-
Notifications
You must be signed in to change notification settings - Fork 162
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): Slice.loadBasechainAddress()
and Slice.skipBasechainAddress()
#2395
Draft
novusnota
wants to merge
12
commits into
main
Choose a base branch
from
closes-2044
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0921f3c
fix: some past PRs that added doc comments
novusnota c9789d3
feat(docs/stdlib): `Slice.loadBasechainAddress()` and `Slice.skipBase…
novusnota ff3fe41
Merge branch 'main' into closes-2044
anton-trunov 85eb255
fix
novusnota 8dee60e
Merge branch 'closes-2044' of github.com:tact-lang/tact into closes-2044
novusnota 350955b
changelog
novusnota 12cdac0
stdlib.ts
novusnota 9f0c411
Merge branch 'main' into closes-2044
anton-trunov 5946f1e
tests
novusnota 3afc9ba
tests for addr_var and addr_extern, just in case
novusnota ec560dc
more visibility for address methods in core-cells
novusnota e290af8
Merge branch 'main' into closes-2044
novusnota File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,7 +220,7 @@ asm( -> 1 0) extends mutates fun loadAddress(self: Slice): Address { LDMSGADDR } | |
/// } | ||
/// ``` | ||
/// | ||
/// See: https://docs.tact-lang.org/ref/core-cells#sliceloadaddress | ||
/// See: https://docs.tact-lang.org/ref/core-cells#sliceskipaddress | ||
/// | ||
asm extends mutates fun skipAddress(self: Slice) { LDMSGADDR NIP } | ||
|
||
|
@@ -307,12 +307,15 @@ inline fun contractBasechainAddress(s: StateInit): BasechainAddress { | |
/// | ||
/// ```tact | ||
/// fun example() { | ||
/// let addr: BasechainAddress = newBasechainAddress(0x83dfd552e63729b472fcbcc8c45ebcc6691702558b68ec7527e1ba403a0f31a8); | ||
/// let addr: BasechainAddress = | ||
/// newBasechainAddress(0x83dfd552e63729b472fcbcc8c45ebcc6691702558b68ec7527e1ba403a0f31a8); | ||
/// let b: Builder = beginCell(); | ||
/// let b2: Builder = b.storeBasechainAddress(addr); | ||
/// } | ||
/// ``` | ||
/// | ||
/// See: https://docs.tact-lang.org/ref/core-cells#builderstorebasechainaddress | ||
/// | ||
extends fun storeBasechainAddress(self: Builder, address: BasechainAddress): Builder { | ||
if (address.hash == null) { | ||
return self.storeUint(0, 2); // 0b00 | ||
|
@@ -323,6 +326,81 @@ extends fun storeBasechainAddress(self: Builder, address: BasechainAddress): Bui | |
.storeUint(address.hash!!, 256); | ||
} | ||
|
||
/// Extension mutation function for the `Slice` type. Available since Tact 1.6.4. | ||
/// | ||
/// Loads and returns a `BasechainAddress` struct from the `Slice`. | ||
/// | ||
/// Attempts to load such `BasechainAddress` struct when `Slice` doesn't contain it throw an exception with [exit code 8]: `Cell overflow`. | ||
/// | ||
/// Attempts to load more data than `Slice` contains throw an exception with [exit code 9]: `Cell underflow`. | ||
/// | ||
/// ```tact | ||
/// fun example() { | ||
/// let s: Slice = beginCell() | ||
/// .storeBasechainAddress(BasechainAddress{ hash: null }) | ||
/// .asSlice(); | ||
/// let fizz: BasechainAddress = s.loadBasechainAddress(); | ||
/// } | ||
/// ``` | ||
/// | ||
/// See: | ||
/// * https://docs.tact-lang.org/ref/core-cells#sliceloadbasechainaddress | ||
/// * https://docs.tact-lang.org/book/exit-codes | ||
/// | ||
/// [exit code 8]: https://docs.tact-lang.org/book/exit-codes#8 | ||
/// [exit code 9]: https://docs.tact-lang.org/book/exit-codes#9 | ||
/// | ||
extends mutates fun loadBasechainAddress(self: Slice): BasechainAddress { | ||
// addr_none | ||
if (self.loadUint(2) == 0) { | ||
return BasechainAddress{ hash: null }; | ||
} | ||
|
||
// addr_std, skip the remaining prefix bits | ||
self.skipBits(9); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens when we have workchains other than basechain? |
||
// Load the hash (account ID) | ||
return BasechainAddress{ hash: self.loadUint(256) }; | ||
} | ||
|
||
/// Extension mutation function for the `Slice` type. Available since Tact 1.6.4. | ||
/// | ||
/// Skips a `BasechainAddress` struct from the `Slice`. | ||
/// | ||
/// Attempts to skip such `BasechainAddress` struct when `Slice` doesn't contain it throw an exception with [exit code 8]: `Cell overflow`. | ||
/// | ||
/// Attempts to skip more data than `Slice` contains throw an exception with [exit code 9]: `Cell underflow`. | ||
/// | ||
/// ```tact | ||
/// fun example() { | ||
/// let s1: Slice = beginCell() | ||
/// .storeBasechainAddress(BasechainAddress{ hash: null }) | ||
/// .storeUint(42, 32) | ||
/// .asSlice(); | ||
/// | ||
/// s1.skipBasechainAddress(); | ||
/// let fizz: Int = s1.loadUint(32); // 42 | ||
/// } | ||
/// ``` | ||
/// | ||
/// See: | ||
/// * https://docs.tact-lang.org/ref/core-cells#sliceskipbasechainaddress | ||
/// * https://docs.tact-lang.org/book/exit-codes | ||
/// | ||
/// [exit code 8]: https://docs.tact-lang.org/book/exit-codes#8 | ||
/// [exit code 9]: https://docs.tact-lang.org/book/exit-codes#9 | ||
/// | ||
extends mutates fun skipBasechainAddress(self: Slice) { | ||
// addr_std | ||
if (self.loadUint(2) != 0) { | ||
// 9 bits of the remaining prefix since first 2 are loaded already | ||
// plus 256 bits of the hash (account ID) | ||
self.skipBits(265); | ||
} | ||
|
||
// addr_none, nothing to load since its 2 bits | ||
// are loaded in the if statement above | ||
} | ||
|
||
/// Global function. Available since Tact 1.6.3. | ||
/// | ||
/// Checks whether the `address` is in the basechain, i.e., its chain ID is 0. If it is not, throws an exception with exit code 138: `Not a basechain address`. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when a slice that is not a valid basechain addess is passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exit code 9.
Actually, I may have found a bunch of long-standing typos — the exit code 8 doesn't seem right for the .load functions.
Double-checking those now.
UPD: They're incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be documented