-
Notifications
You must be signed in to change notification settings - Fork 65
refactor(foundations): change Merkle proofs code sample to Tolk #2100
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
b98f2e3
3730f26
c67740f
6a46d09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -202,11 +202,18 @@ const patchedShardState = rebuild(newShardState, path, accountState) // And repl | |
|
|
||
| Another interesting point is how we access the hash of the last known `ShardBlock`. | ||
|
|
||
| ```tact title="Tact" | ||
| inline fun findShardInBinTree(root: Cell, address: Address, shardBitLen: Int): ShardDescr { | ||
| let curCs = root.beginParse(); | ||
| // It's std address, but we parse it as VarAddress to get hash part as Slice, not as Int | ||
| let accountId = myParseVarAddress(address.asSlice()).address; | ||
| ```tolk title="Tolk" | ||
| @pure | ||
| fun slice.preloadIthRef(self, idx: int): cell | ||
| asm "PLDREFVAR" | ||
|
|
||
| @inline | ||
| fun findShardInBinTree(root: cell, addr: address, shardBitLen: int): ShardDescr { | ||
| var curCs = root.beginParse(); | ||
| // Cast the address to a slice and skip the 11-bit prefix | ||
| // (3 tag bits + 8 workchain bits) to reach the account ID bits. | ||
| var accountId = addr as slice; | ||
| accountId.skipBits(11); | ||
|
Collaborator
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. Consider using this function |
||
| repeat (shardBitLen) { | ||
| if (accountId.loadBool()) { | ||
| // If the bit is 1, we go to the right child | ||
|
|
@@ -222,12 +229,12 @@ inline fun findShardInBinTree(root: Cell, address: Address, shardBitLen: Int): S | |
|
|
||
| // ... | ||
|
|
||
| let mcBlockExtra = McBlockExtra.fromCell(blockHeader.extra.loadRef().beginParse().preloadIthRef(3)); | ||
| // shardHashes is a hashmap (workchain -> ShardDescr) | ||
| // Therefore, we only need to retrieve the ShardDescr for workchain 0, as we are working in basechain. | ||
| // We can use a non-null assertion, as we already proved that it is a valid block, and a valid masterchain block must have a ShardDescr for workchain 0. | ||
| let binTreeWithShardDescr: Cell = mcBlockExtra.shardHashes.get(0)!!; | ||
| let shardDescr = findShardInBinTree(binTreeWithShardDescr, jettonMaster, shardBitLen); | ||
| val mcBlockExtra = McBlockExtra.fromCell(blockHeader.extra.loadRef().beginParse().preloadIthRef(3)); | ||
| // shardHashes is a hashmap (workchain -> ShardDescr). | ||
| // We only need to retrieve the ShardDescr for workchain 0, since we are working in basechain. | ||
| // `mustGet` is safe here, as we already proved that it is a valid block, and a valid masterchain block must have a ShardDescr for workchain 0. | ||
|
Contributor
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. [HIGH] Comment uses “we” in technical documentationThe inline code comment uses first‑person plural phrasing (“we are working in basechain” and “we already proved that it is a valid block”). The project style guide explicitly prohibits first‑person references (“we”/“I”) in documentation and code comments, requiring an impersonal, fact‑focused tone. This violates that HIGH‑severity style rule and could lead to inconsistent tone across the technical documentation. The surrounding code and comments in Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone! |
||
| val binTreeWithShardDescr: cell = mcBlockExtra.shardHashes.mustGet(0); | ||
| val shardDescr = findShardInBinTree(binTreeWithShardDescr, jettonMaster, shardBitLen); | ||
| ``` | ||
|
|
||
| ```tlb | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.