Skip to content

Commit

Permalink
feat(docs): new functions from TVM upgrades 2023-07 and 2024-04 (tact…
Browse files Browse the repository at this point in the history
…-lang#1062)

* feat(docs): new TVM functions from 2023-07 and 2024-04 upgrades

* chore(stdlib): unify doc comments to the latest style

The general idea:
1. What the thing is and which version of Tact it became available in
2. Further description of what it does, if necessary
3. Usage examples, wrapped in a function body for highlighting and
immediate copy-paste when editing
4. "See" links to the related pages in Tact and TON docs or elsewhere

And the most important part — all descriptions come directly from docs
and then get stripped of doc-specific things, like inlined links `[]()`
(or `[][]`)  or `{:tact}` directives for highlighting.

* chore(CI): bump action versions to prevent Node.js 16 deprecation issues

See:
https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default
  • Loading branch information
novusnota authored and sansx committed Dec 9, 2024
1 parent 7dfc97f commit dd3cdcd
Show file tree
Hide file tree
Showing 10 changed files with 718 additions and 212 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js 18 for backwards compat tests
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
# without caching
Expand All @@ -46,7 +46,7 @@ jobs:
yarn config delete ignore-engines
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Wider range of serialization options for integers — `uint1` through `uint256` and `int1` through `int257`: PR [#558](https://github.com/tact-lang/tact/pull/558), PR [#937](https://github.com/tact-lang/tact/pull/937)
- The `deepEquals` method for the `Map` type: PR [#637](https://github.com/tact-lang/tact/pull/637), PR [#939](https://github.com/tact-lang/tact/pull/939)
- `asm` bodies for module-level functions: PR [#769](https://github.com/tact-lang/tact/pull/769), PR [#825](https://github.com/tact-lang/tact/pull/825)
- Corresponding stdlib functions for new TVM instructions from 2023.07 and 2024.04 upgrades: PR [#331](https://github.com/tact-lang/tact/pull/331). Added the `storeBuilder` extension function and `gasConsumed`, `getComputeFee`, `getStorageFee`, `getForwardFee`, `getSimpleComputeFee`, `getSimpleForwardFee`, `getOriginalFwdFee`, `myStorageDue` functions.
- Corresponding stdlib functions for new TVM instructions from 2023.07 and 2024.04 upgrades: PR [#331](https://github.com/tact-lang/tact/pull/331), PR [#1062](https://github.com/tact-lang/tact/pull/1062). Added the `storeBuilder` extension function and `gasConsumed`, `getComputeFee`, `getStorageFee`, `getForwardFee`, `getSimpleComputeFee`, `getSimpleForwardFee`, `getOriginalFwdFee`, `myStorageDue` functions.
- `slice`, `rawSlice`, `ascii` and `crc32` built-in functions: PR [#787](https://github.com/tact-lang/tact/pull/787), PR [#799](https://github.com/tact-lang/tact/pull/799), PR [#951](https://github.com/tact-lang/tact/pull/951)
- `Builder.storeMaybeRef`, `parseStdAddress` and `parseVarAddress` stdlib functions: PR [#793](https://github.com/tact-lang/tact/pull/793), PR [#950](https://github.com/tact-lang/tact/pull/950)
- The compiler development guide: PR [#833](https://github.com/tact-lang/tact/pull/833)
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"funs",
"frontmatter",
"Georgiy",
"getsimpleforwardfee",
"gettest",
"Héctor",
"infixl",
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/book/debug.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ If you're overwhelmed by the testing setup of [Blueprint][bp] or just want to te
```json filename="package.json" {3}
{
"scripts": {
"lab": "blueprint build 1>/dev/null && yarn test -t plays"
"lab": "blueprint build --all 1>/dev/null && yarn test -t plays"
}
}
```
Expand All @@ -703,7 +703,7 @@ If you're overwhelmed by the testing setup of [Blueprint][bp] or just want to te
```json filename="package.json" {3-4}
{
"scripts": {
"build": "blueprint build | out-null",
"build": "blueprint build --all | out-null",
"lab": "yarn build && yarn test -t plays"
}
}
Expand Down
41 changes: 17 additions & 24 deletions docs/src/content/docs/book/security-best-practices.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ message Sample {
parsedField: Slice;
}
receive(msg: Sample) {
// Process msg.parsedField directly
contract Example {
receive(msg: Sample) {
// Process msg.parsedField directly
}
}
```

Expand All @@ -138,13 +140,13 @@ receive(msg: Sample) {
Avoid parsing strings from human-readable formats into binary structures **on-chain**, as this increases computational overhead and gas costs.

```tact
message Sample {
field: String;
}
message Sample { field: String }
receive(msg: Sample) {
// Parsing occurs on-chain, which is inefficient
let parsed = field.fromBase64();
contract Example {
receive(msg: Sample) {
// Parsing occurs on-chain, which is inefficient
let parsed = field.fromBase64();
}
}
```

Expand All @@ -155,11 +157,9 @@ Be careful with the `Out of gas error`. It cannot be handled, so try to pre-calc
##### Do's ✅

```tact
message Vote {
votes: Int as int32;
}
message Vote { votes: Int as int32 }
contract Sample2 {
contract Example {
const voteGasUsage = 10000; // precompute with tests
receive(msg: Vote) {
Expand Down Expand Up @@ -360,7 +360,7 @@ Return excesses using a [Message][message] with `0xd53276db` opcode.

```tact
message(0xd53276db) Excesses {}
message Vote { votes: Int as int32; }
message Vote { votes: Int as int32 }
contract Sample {
votes: Int as uint32 = 0;
Expand All @@ -378,14 +378,11 @@ contract Sample {
}
```

Also, you can leverage [`notify():{tact}`](/ref/core-base/#self-notify) or [`forward():{tact}`](/ref/core-base/#self-forward) standard functions.
Also, you can leverage [`notify(){:tact}`](/ref/core-base/#self-notify) or [`forward(){:tact}`](/ref/core-base/#self-forward) standard functions.

```tact
message Vote {
votes: Int as int32;
}
message(0xd53276db) Excesses {}
message Vote { votes: Int as int32 }
contract Sample {
votes: Int as uint32 = 0;
Expand All @@ -409,12 +406,8 @@ Thus, any on-chain communication is asynchronous and done by sending and receivi
Exchange messages to pull data from other contract.

```tact
message ProvideMoney {
}
message TakeMoney {
money: Int as coins;
}
message ProvideMoney {}
message TakeMoney { money: Int as coins }
contract OneContract {
money: Int as coins;
Expand Down
Loading

0 comments on commit dd3cdcd

Please sign in to comment.