diff --git a/CHANGELOG.md b/CHANGELOG.md index 752cfab43..0fa421de7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Enabled compilation of examples in `data-structures.mdx` and across Cookbook: PR [#917](https://github.com/tact-lang/tact/pull/917) - Removed the Programmatic API page due to frequent changes. To use the API, please refer to the compiler sources: PR [#1184](https://github.com/tact-lang/tact/pull/1184) - Added a link to the article by CertiK to Security best practices page: PR [#1185](https://github.com/tact-lang/tact/pull/1185) +- Added a note on `dump()` being computationally expensive: PR [#1189](https://github.com/tact-lang/tact/pull/1189) ### Release contributors diff --git a/docs/src/content/docs/book/debug.mdx b/docs/src/content/docs/book/debug.mdx index aed09583c..45ad2595c 100644 --- a/docs/src/content/docs/book/debug.mdx +++ b/docs/src/content/docs/book/debug.mdx @@ -165,6 +165,12 @@ it('should deploy', async () => { ### Debug with `dump()` {#tests-dump} +:::note + + Calling [`dump(){:tact}`][dump] is computationally expensive and consumes a lot of gas. Be sure to always supply enough Toncoins in your tests to avoid [exit code -14](/book/exit-codes#-14). + +::: + To see results of [`dump(){:tact}`][dump] function calls and use ["printf debugging"](#approach) approach, one has to: 1. Put calls to [`dump(){:tact}`][dump] and other [common debugging functions](#debug-functions) in relevant places of the code. diff --git a/docs/src/content/docs/book/structs-and-messages.mdx b/docs/src/content/docs/book/structs-and-messages.mdx index 0723104e4..37a9294ec 100644 --- a/docs/src/content/docs/book/structs-and-messages.mdx +++ b/docs/src/content/docs/book/structs-and-messages.mdx @@ -3,6 +3,8 @@ title: Structs and Messages description: "Structs can define complex data types that contain multiple fields of different types, while Messages also have a 32-bit header and are convenient to receive and sent message bodies on TON Blockchain" --- +import { Badge } from '@astrojs/starlight/components'; + Tact supports a number of [primitive data types](/book/types#primitive-types) that are tailored for smart contract use. However, using individual means of storage often becomes cumbersome, so there are [Structs](#structs) and [Messages](#messages) which allow combining types together. :::caution @@ -108,7 +110,7 @@ Messages are almost the same thing as [Structs](#structs) with the only differen Tact automatically generates those unique ids (opcodes) for every received Message, but this can be manually overwritten: ```tact -// This Message overwrites its unique id with 0x7362d09c +// This Message overwrites its unique id (opcode) with 0x7362d09c message(0x7362d09c) TokenNotification { forwardPayload: Slice as remaining; } @@ -116,9 +118,11 @@ message(0x7362d09c) TokenNotification { This is useful for cases where you want to handle certain opcodes of a given smart contract, such as [Jetton standard](https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md). The short-list of opcodes this contract is able to process is [given here in FunC](https://github.com/ton-blockchain/token-contract/blob/main/ft/op-codes.fc). They serve as an interface to the smart contract. -A message opcode can be any compile-time (constant) expression which evaluates to a strictly positive integer that fits into 32-bits, so the following is also a valid message declaration: + A message opcode can be any [compile-time](/ref/core-comptime) expression that evaluates to a positive $32$-bit integer, so the following is also valid: ```tact +// This Message overwrites its unique id (opcode) with 898001897, +// which is the evaluated integer value of the specified compile-time expression message((crc32("Tact") + 42) & 0xFFFF_FFFF) MsgWithExprOpcode { field: Int as uint4; } diff --git a/docs/src/content/docs/ref/core-debug.mdx b/docs/src/content/docs/ref/core-debug.mdx index f380d2104..3ca7afb08 100644 --- a/docs/src/content/docs/ref/core-debug.mdx +++ b/docs/src/content/docs/ref/core-debug.mdx @@ -50,6 +50,8 @@ fun dump(arg); Prints the argument `arg` to the contract's debug console. Evaluated only if the `debug` option in the [configuration file](/book/config) is set to `true{:json}`, otherwise does nothing. +This function is computationally expensive and consumes a lot of gas because it prints the location from which it was called, i.e. the filename, line and column numbers, and the original expression that was the `arg` argument. + Can be applied to the following list of types and values: * [`Int{:tact}`][int] @@ -65,7 +67,10 @@ Usage examples: ```tact // Int -dump(42); +dump(42); // prints: + // File filename.tact:2:1 + // dump(42) + // 42 // Bool dump(true);