Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stdlib): Add SendDefaultMode #1010

Merged
merged 13 commits into from
Oct 31, 2024
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ability to specify a compile-time method ID expression for getters: PR [#922](https://github.com/tact-lang/tact/pull/922) and PR [#932](https://github.com/tact-lang/tact/pull/932)
- Destructuring of structs and messages: PR [#856](https://github.com/tact-lang/tact/pull/856)
- Docs: automatic links to Web IDE from all code blocks: PR [#994](https://github.com/tact-lang/tact/pull/994)
- The `SendDefaultMode` send mode constant to the standard library: PR [#1010](https://github.com/tact-lang/tact/pull/1010)
- Docs: initial semi-automated Chinese translation of the documentation: PR [#942](https://github.com/tact-lang/tact/pull/942)
- The `replace` and `replaceGet` methods for the `Map` type: PR [#941](https://github.com/tact-lang/tact/pull/941)

Expand Down
2 changes: 1 addition & 1 deletion docs/grammars/grammar-tact.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
},
{
"comment": "Other constants from the core library",
"match": "(?<!\\.)\\b(SendRemainingValue|SendRemainingBalance|SendPayGasSeparately|SendIgnoreErrors|SendBounceIfActionFail|SendDestroyIfZero|SendOnlyEstimateFee|ReserveExact|ReserveAllExcept|ReserveAtMost|ReserveAddOriginalBalance|ReserveInvertSign|ReserveBounceIfActionFail)\\b",
"match": "(?<!\\.)\\b(SendDefaultMode|SendRemainingValue|SendRemainingBalance|SendPayGasSeparately|SendIgnoreErrors|SendBounceIfActionFail|SendDestroyIfZero|SendOnlyEstimateFee|ReserveExact|ReserveAllExcept|ReserveAtMost|ReserveAddOriginalBalance|ReserveInvertSign|ReserveBounceIfActionFail)\\b",
"name": "constant.other.builtin.tact"
},
{
Expand Down
3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
"typescript": "^5.6.2",
"unist-util-visit": "^5.0.0"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"version": ""
}
4 changes: 3 additions & 1 deletion docs/src/content/docs/book/message-mode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: Message mode
description: "Messages are sent with the mode param of a struct SendParameters. It's an Int value, which is combined from base modes and optional flags, which are also Int values"
---

import { Badge } from '@astrojs/starlight/components';

As it was previously mentioned, messages are sent with the `mode` param of a struct `SendParameters{:tact}`. It's an [`Int{:tact}`][int] value, which is combined from base modes and optional flags, which are also [`Int{:tact}`][int] values.

It's possible to use raw [`Int{:tact}`][int] values and manually provide them for the `mode`, but for your convenience there's a set of constants which you may use to construct the compound `mode` with ease. Take a look at the following tables for more information on base modes and optional flags.
Expand All @@ -11,7 +13,7 @@ It's possible to use raw [`Int{:tact}`][int] values and manually provide them fo

Mode value | Constant name | Description
---------: | :---------------------------- | -----------
$0$ | - | Ordinary message (default).
$0$ | <Badge text="Since Tact 1.6" variant="tip"/> `SendDefaultMode{:tact}` | Ordinary message (default).
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
$64$ | `SendRemainingValue{:tact}` | Carry all the remaining value of the inbound message in addition to the value initially indicated in the new message.
$128$ | `SendRemainingBalance{:tact}` | Carry all the remaining balance of the current smart contract instead of the value originally indicated in the message.

Expand Down
53 changes: 27 additions & 26 deletions src/imports/stdlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,32 +278,33 @@ files['std/reserve.tact'] =
files['std/send.tact'] =
'YXNtIGZ1biBuYXRpdmVTZW5kTWVzc2FnZShjZWxsOiBDZWxsLCBtb2RlOiBJbnQpIHsgU0VORFJBV01TRyB9Cgphc20gZnVuIG5hdGl2ZVNlbmRNZXNzYWdlUmV0dXJu' +
'Rm9yd2FyZEZlZShtc2c6IENlbGwsIG1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6dWludDMyCiAgICAvLyAgICAgICAgICAgICAgICAgICAgIG1heWJlOiBzdGF0ZUluaXQgKGZhbHNlKSBib2R5UmVmOiBib29sICh0cnVlKQogICAgbGV0' +
'IGM6IENlbGwgPSBiZWdpbkNlbGwoKQogICAgICAgIC5zdG9yZVVpbnQoMTUyMTE4MDcyMDI3Mzg3NTI4MTc5NjA0Mzg0NjQ1MTMsIDEwNCkKICAgICAgICAuc3RvcmVS' +
'ZWYoYm9keSkKICAgICAgICAuZW5kQ2VsbCgpOwogICAgbmF0aXZlU2VuZE1lc3NhZ2UoYywgMCk7Cn0KCmFzbSBmdW4gYWNjZXB0TWVzc2FnZSgpIHsgQUNDRVBUIH0K' +
'CmFzbSBmdW4gY29tbWl0KCkgeyBDT01NSVQgfQo=';
files['std/text.tact'] =
'Ly8KLy8gU3RyaW5nIGJ1aWxkZXIKLy8KCkBuYW1lKF9fdGFjdF9zdHJpbmdfYnVpbGRlcl9zdGFydF9zdHJpbmcpCm5hdGl2ZSBiZWdpblN0cmluZygpOiBTdHJpbmdC' +
'dWlsZGVyOwoKQG5hbWUoX190YWN0X3N0cmluZ19idWlsZGVyX3N0YXJ0X2NvbW1lbnQpCm5hdGl2ZSBiZWdpbkNvbW1lbnQoKTogU3RyaW5nQnVpbGRlcjsKCkBuYW1l' +
Expand Down
1 change: 1 addition & 0 deletions stdlib/std/send.tact
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ asm fun nativeSendMessageReturnForwardFee(msg: Cell, mode: Int): Int { SENDMSG }

const SendRemainingBalance: Int = 128;
const SendRemainingValue: Int = 64;
const SendDefaultMode: Int = 0;
const SendIgnoreErrors: Int = 2;
const SendPayGasSeparately: Int = 1;
const SendDestroyIfZero: Int = 32;
Expand Down
Loading