Skip to content

Commit

Permalink
doc(stdlib): doc comments for BaseTrait (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
i582 authored Jan 20, 2025
1 parent 4c6ff6b commit 9c12481
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Document that identifiers cannot start with `__gen` or `__tact`, and cannot contain Unicode characters apart from the small subset `a-zA-Z0-9_`: PR [#1312](https://github.com/tact-lang/tact/pull/1312)
- Added signatures for map methods, such as `.get()`, `.exists()`, `.set()`, `.replace()`, `.replaceGet()`, `.del()`, `.isEmpty()`, `.deepEquals()`, `.asCell()`: PR [#1352](https://github.com/tact-lang/tact/pull/1352)
- Added a compilation-related page with the description of the compilation report: PR [#1309](https://github.com/tact-lang/tact/pull/1309)
- Documented `BaseTrait` and methods in stdlib code: PR [#1296](https://github.com/tact-lang/tact/pull/1296)

### Release contributors

Expand Down
67 changes: 50 additions & 17 deletions src/stdlib/stdlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,54 @@ files["libs/stoppable.tact"] =
"ICAgIHNlbGYucmVxdWlyZU93bmVyKCk7CiAgICAgICAgc2VsZi5yZXF1aXJlU3RvcHBlZCgpOwogICAgICAgIHNlbGYuc3RvcHBlZCA9IGZhbHNlOwogICAgICAgIHNl" +
"bGYucmVwbHkoIlJlc3VtZWQiLmFzQ29tbWVudCgpKTsKICAgIH0KfQ==";
files["std/base.tact"] =
"dHJhaXQgQmFzZVRyYWl0IHsKICAgIHZpcnR1YWwgY29uc3Qgc3RvcmFnZVJlc2VydmU6IEludCA9IDA7CiAgICAKICAgIHZpcnR1YWwgaW5saW5lIGZ1biByZXBseShi" +
"b2R5OiBDZWxsPykgewogICAgICAgIHNlbGYuZm9yd2FyZChzZW5kZXIoKSwgYm9keSwgdHJ1ZSwgbnVsbCk7CiAgICB9CgogICAgdmlydHVhbCBpbmxpbmUgZnVuIG5v" +
"dGlmeShib2R5OiBDZWxsPykgewogICAgICAgIHNlbGYuZm9yd2FyZChzZW5kZXIoKSwgYm9keSwgZmFsc2UsIG51bGwpOwogICAgfQoKICAgIHZpcnR1YWwgZnVuIGZv" +
"cndhcmQodG86IEFkZHJlc3MsIGJvZHk6IENlbGw/LCBib3VuY2U6IEJvb2wsIGluaXQ6IFN0YXRlSW5pdD8pIHsKCiAgICAgICAgbGV0IGNvZGU6IENlbGw/ID0gbnVs" +
"bDsKICAgICAgICBsZXQgZGF0YTogQ2VsbD8gPSBudWxsOwogICAgICAgIGlmIChpbml0ICE9IG51bGwpIHsKICAgICAgICAgICAgbGV0IGluaXQyOiBTdGF0ZUluaXQg" +
"PSBpbml0ISE7CiAgICAgICAgICAgIGNvZGUgPSBpbml0Mi5jb2RlOwogICAgICAgICAgICBkYXRhID0gaW5pdDIuZGF0YTsKICAgICAgICB9CgogICAgICAgIC8vIExv" +
"Y2sgc3RvcmFnZSBpZiBuZWVkZWQKICAgICAgICBpZiAoc2VsZi5zdG9yYWdlUmVzZXJ2ZSA+IDApIHsgLy8gT3B0aW1pemVkIGluIGNvbXBpbGUtdGltZQogICAgICAg" +
"ICAgICBsZXQgY3R4OiBDb250ZXh0ID0gY29udGV4dCgpOwogICAgICAgICAgICBsZXQgYmFsYW5jZTogSW50ID0gbXlCYWxhbmNlKCk7CiAgICAgICAgICAgIGxldCBi" +
"YWxhbmNlQmVmb3JlTWVzc2FnZTogSW50ID0gYmFsYW5jZSAtIGN0eC52YWx1ZTsKICAgICAgICAgICAgaWYgKGJhbGFuY2VCZWZvcmVNZXNzYWdlIDwgc2VsZi5zdG9y" +
"YWdlUmVzZXJ2ZSkgewogICAgICAgICAgICAgICAgbmF0aXZlUmVzZXJ2ZShzZWxmLnN0b3JhZ2VSZXNlcnZlLCBSZXNlcnZlRXhhY3QpOwogICAgICAgICAgICAgICAg" +
"c2VuZChTZW5kUGF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Z1bmN0aW9uIHdpdGgKICAgIC8vLyB0aGUgZm9sbG93aW5nIGFyZ3VtZW50czoKICAgIC8vLwogICAgLy8vIGBgYHRh" +
"Y3QKICAgIC8vLyBzZWxmLmZvcndhcmQoc2VuZGVyKCksIGJvZHksIHRydWUsIG51bGwpOwogICAgLy8vICAgICAgICAgICAgICDihpEgICAgICAgICDihpEgICAgIOKG" +
"kSAgICAg4oaRCiAgICAvLy8gICAgICAgICAgICAgIHwgICAgICAgICB8ICAgICB8ICAgICBpbml0OiBTdGF0ZUluaXQ/CiAgICAvLy8gICAgICAgICAgICAgIHwgICAg" +
"ICAgICB8ICAgICBib3VuY2U6IEJvb2wKICAgIC8vLyAgICAgICAgICAgICAgfCAgICAgICAgIGJvZHk6IENlbGw/CiAgICAvLy8gICAgICAgICAgICAgIHRvOiBBZGRy" +
"ZXNzCiAgICAvLy8gYGBgCiAgICB2aXJ0dWFsIGlubGluZSBmdW4gcmVwbHkoYm9keTogQ2VsbD8pIHsKICAgICAgICBzZWxmLmZvcndhcmQoc2VuZGVyKCksIGJvZHks" +
"IHRydWUsIG51bGwpOwogICAgfQoKICAgIC8vLyBTZW5kcyBhIG5vbi1ib3VuY2VhYmxlIG1lc3NhZ2UgYmFjayB0byB0aGUgc2VuZGVyIG9mIHRoZSBjdXJyZW50IG1l" +
"c3NhZ2UuCiAgICAvLy8gQW4gYWxpYXMgZnVuY3Rpb24gdG8gY2FsbGluZyB0aGUgYHNlbGYuZm9yd2FyZCgpYCBmdW5jdGlvbiB3aXRoCiAgICAvLy8gdGhlIGZvbGxv" +
"d2luZyBhcmd1bWVudHM6CiAgICAvLy8KICAgIC8vLyBgYGB0YWN0CiAgICAvLy8gc2VsZi5mb3J3YXJkKHNlbmRlcigpLCBib2R5LCBmYWxzZSwgbnVsbCk7CiAgICAv" +
"Ly8gICAgICAgICAgICAgIOKGkSAgICAgICAgIOKGkSAgICAg4oaRICAgICDihpEKICAgIC8vLyAgICAgICAgICAgICAgfCAgICAgICAg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GlmIG5lZWRlZAogICAgICAgIGlmIChzZWxmLnN0b3JhZ2VSZXNlcnZlID4gMCkgeyAvLyBPcHRpbWl6ZWQgaW4gY29tcGlsZS10aW1l" +
"CiAgICAgICAgICAgIGxldCBjdHg6IENvbnRleHQgPSBjb250ZXh0KCk7CiAgICAgICAgICAgIGxldCBiYWxhbmNlOiBJbnQgPSBteUJhbGFuY2UoKTsKICAgICAgICAg" +
"ICAgbGV0IGJhbGFuY2VCZWZvcmVNZXNzYWdlOiBJbnQgPSBiYWxhbmNlIC0gY3R4LnZhbHVlOwogICAgICAgICAgICBpZiAoYmFsYW5jZUJlZm9yZU1lc3NhZ2UgPCBz" +
"ZWxmLnN0b3JhZ2VSZXNlcnZlKSB7CiAgICAgICAgICAgICAgICBuYXRpdmVSZXNlcnZlKHNlbGYuc3RvcmFnZVJlc2VydmUsIFJlc2VydmVFeGFjdCk7CiAgICAgICAg" +
"ICAgICAgICBzZW5kKFNlbmRQYXJhbWV0ZXJzewogICAgICAgICAgICAgICAgICAgIGJvdW5jZSwKICAgICAgICAgICAgICAgICAgICB0bywKICAgICAgICAgICAgICAg" +
"ICAgICB2YWx1ZTogMCwKICAgICAgICAgICAgICAgICAgICBtb2RlOiBTZW5kUmVtYWluaW5nQmFsYW5jZSB8IFNlbmRJZ25vcmVFcnJvcnMsCiAgICAgICAgICAgICAg" +
"ICAgICAgYm9keSwKICAgICAgICAgICAgICAgICAgICBjb2RlLAogICAgICAgICAgICAgICAgICAgIGRhdGEsCiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAg" +
"ICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgLy8gSnVzdCBzZW5kIHdpdGggcmVtYWluaW5nIGJhbGFuY2UKICAgICAgICBzZW5kKFNl" +
"bmRQYXJhbWV0ZXJzewogICAgICAgICAgICBib3VuY2UsCiAgICAgICAgICAgIHRvLAogICAgICAgICAgICB2YWx1ZTogMCwKICAgICAgICAgICAgbW9kZTogU2VuZFJl" +
"bWFpbmluZ1ZhbHVlIHwgU2VuZElnbm9yZUVycm9ycywKICAgICAgICAgICAgYm9keSwKICAgICAgICAgICAgY29kZSwKICAgICAgICAgICAgZGF0YSwKICAgICAgICB9" +
"KTsKICAgIH0KfQo=";
files["std/cells.tact"] =
"Ly8KLy8gQnVpbGRlcgovLwoKYXNtIGZ1biBiZWdpbkNlbGwoKTogQnVpbGRlciB7IE5FV0MgfQoKLy8gc3BlY2lhbCB0cmVhdG1lbnQgaW4gRnVuYyBjb21waWxlciwg" +
"c28gbm90IHJlcGxhY2VkIHdpdGggYXNtICJTVElYIgpAbmFtZShzdG9yZV9pbnQpCmV4dGVuZHMgbmF0aXZlIHN0b3JlSW50KHNlbGY6IEJ1aWxkZXIsIHZhbHVlOiBJ" +
Expand Down Expand Up @@ -356,7 +389,7 @@ files["std/math.tact"] =
"bmFtZShfX3RhY3RfcG93KQpuYXRpdmUgcG93KGJhc2U6IEludCwgZXhwOiBJbnQpOiBJbnQ7Cgphc20gZnVuIHBvdzIoZXhwOiBJbnQpOiBJbnQgeyBQT1cyIH0=";
files["std/primitives.tact"] =
"cHJpbWl0aXZlIEludDsKcHJpbWl0aXZlIEJvb2w7CnByaW1pdGl2ZSBCdWlsZGVyOwpwcmltaXRpdmUgU2xpY2U7CnByaW1pdGl2ZSBDZWxsOwpwcmltaXRpdmUgQWRk" +
"cmVzczsKcHJpbWl0aXZlIFN0cmluZzsKcHJpbWl0aXZlIFN0cmluZ0J1aWxkZXI7";
"cmVzczsKcHJpbWl0aXZlIFN0cmluZzsKcHJpbWl0aXZlIFN0cmluZ0J1aWxkZXI7Cg==";
files["std/reserve.tact"] =
"YXNtIGZ1biBuYXRpdmVSZXNlcnZlKGFtb3VudDogSW50LCBtb2RlOiBJbnQpIHsgUkFXUkVTRVJWRSB9Cgpjb25zdCBSZXNlcnZlRXhhY3Q6IEludCA9IDA7CmNvbnN0" +
"IFJlc2VydmVBbGxFeGNlcHQ6IEludCA9IDE7CmNvbnN0IFJlc2VydmVBdE1vc3Q6IEludCA9IDI7CmNvbnN0IFJlc2VydmVBZGRPcmlnaW5hbEJhbGFuY2U6IEludCA9" +
Expand Down Expand Up @@ -849,5 +882,5 @@ files["stdlib.fc"] =
files["stdlib.tact"] =
"aW1wb3J0ICIuL3N0ZC9wcmltaXRpdmVzIjsKaW1wb3J0ICIuL3N0ZC9jZWxscyI7CmltcG9ydCAiLi9zdGQvY3J5cHRvIjsKaW1wb3J0ICIuL3N0ZC90ZXh0IjsKaW1w" +
"b3J0ICIuL3N0ZC9tYXRoIjsKaW1wb3J0ICIuL3N0ZC9jb250cmFjdCI7CmltcG9ydCAiLi9zdGQvZGVidWciOwppbXBvcnQgIi4vc3RkL2NvbnRleHQiOwppbXBvcnQg" +
"Ii4vc3RkL3Jlc2VydmUiOwppbXBvcnQgIi4vc3RkL3NlbmQiOwppbXBvcnQgIi4vc3RkL2NvbmZpZyI7CmltcG9ydCAiLi9zdGQvYmFzZSI7";
"Ii4vc3RkL3Jlc2VydmUiOwppbXBvcnQgIi4vc3RkL3NlbmQiOwppbXBvcnQgIi4vc3RkL2NvbmZpZyI7CmltcG9ydCAiLi9zdGQvYmFzZSI7Cg==";
export default files;
81 changes: 77 additions & 4 deletions src/stdlib/stdlib/std/base.tact
Original file line number Diff line number Diff line change
@@ -1,16 +1,73 @@
/// Describes the base logic that is available in all contracts and traits by default.
///
/// This trait is implicitly inherited by every other contract and trait.
/// It contains a number of the most useful internal functions for any kind of contract,
/// and a constant `self.storageReserve` aimed at advanced users of Tact.
///
/// See: https://docs.tact-lang.org/ref/core-base/
trait BaseTrait {
/// The amount of nanoToncoins to reserve before forwarding a message with
/// `SendRemainingBalance` mode. Default is 0 (no reserve).
///
/// ```tact
/// contract AllYourStorageBelongsToUs {
/// // This would change the behavior of `self.forward()` function,
/// // causing it to try reserving this amount of nanoToncoins before
/// // forwarding a message with `SendRemainingBalance` mode
/// override const storageReserve: Int = ton("0.1");
/// }
/// ```
///
/// See: https://docs.tact-lang.org/ref/core-base/#self-forward
virtual const storageReserve: Int = 0;

/// Sends a bounceable message back to the sender of the current message.
/// An alias function to calling the `self.forward()` function with
/// the following arguments:
///
/// ```tact
/// self.forward(sender(), body, true, null);
/// ↑ ↑ ↑ ↑
/// | | | init: StateInit?
/// | | bounce: Bool
/// | body: Cell?
/// to: Address
/// ```
virtual inline fun reply(body: Cell?) {
self.forward(sender(), body, true, null);
}

/// Sends a non-bounceable message back to the sender of the current message.
/// An alias function to calling the `self.forward()` function with
/// the following arguments:
///
/// ```tact
/// self.forward(sender(), body, false, null);
/// ↑ ↑ ↑ ↑
/// | | | init: StateInit?
/// | | bounce: Bool
/// | body: Cell?
/// to: Address
/// ```
virtual inline fun notify(body: Cell?) {
self.forward(sender(), body, false, null);
}

/// Queues the message (bounceable or non-bounceable) to be sent to the specified address `to`.
/// Optionally, you may provide a `body` of the message and the `init` package with `initOf`.
///
/// When `self.storageReserve` constant is overwritten to be greater than zero, before sending a
/// message it also tries to reserve the `self.storageReserve` amount of nanoToncoins from the
/// remaining balance before making the send in the `SendRemainingBalance` (128) mode.
///
/// In case reservation attempt fails and in the default case without the attempt, the message
/// is sent with the `SendRemainingValue` (64) mode instead.
///
/// > Note that `self.forward()` never sends additional nanoToncoins on top of what’s available on the balance.
/// > To be able to send more nanoToncoins with a single message, use the the `send` function.
///
/// See: https://docs.tact-lang.org/ref/core-base/#self-forward for examples.
virtual fun forward(to: Address, body: Cell?, bounce: Bool, init: StateInit?) {

let code: Cell? = null;
let data: Cell? = null;
if (init != null) {
Expand All @@ -26,12 +83,28 @@ trait BaseTrait {
let balanceBeforeMessage: Int = balance - ctx.value;
if (balanceBeforeMessage < self.storageReserve) {
nativeReserve(self.storageReserve, ReserveExact);
send(SendParameters{bounce: bounce, to: to, value: 0, mode: SendRemainingBalance | SendIgnoreErrors, body: body, code: code, data: data });
send(SendParameters{
bounce,
to,
value: 0,
mode: SendRemainingBalance | SendIgnoreErrors,
body,
code,
data,
});
return;
}
}

// Just send with remaining balance
send(SendParameters{bounce: bounce, to: to, value: 0, mode: SendRemainingValue | SendIgnoreErrors, body: body, code: code, data: data });
send(SendParameters{
bounce,
to,
value: 0,
mode: SendRemainingValue | SendIgnoreErrors,
body,
code,
data,
});
}
}
}
2 changes: 1 addition & 1 deletion src/stdlib/stdlib/std/primitives.tact
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ primitive Slice;
primitive Cell;
primitive Address;
primitive String;
primitive StringBuilder;
primitive StringBuilder;
2 changes: 1 addition & 1 deletion src/stdlib/stdlib/stdlib.tact
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import "./std/context";
import "./std/reserve";
import "./std/send";
import "./std/config";
import "./std/base";
import "./std/base";

0 comments on commit 9c12481

Please sign in to comment.