fix: wasm-ton parser gaps and tx id computation#242
Conversation
6372b7e to
4197cfe
Compare
packages/wasm-ton/src/parser.rs
Outdated
| /// Body parse result: (opcode, memo, jetton_transfer, withdraw_amount) | ||
| type BodyParseResult = ( |
There was a problem hiding this comment.
it's probably time to make this a struct
4197cfe to
9d290b2
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes TON transaction parsing gaps around staking withdrawals and aligns Transaction.id() with TON ecosystem conventions by computing the root cell hash (rather than hashing BOC bytes), then exposes the new parsed withdrawAmount field through the WASM-to-JS boundary with strengthened tests.
Changes:
- Parse
withdraw_amountfrom Whales + SingleNominator withdrawal message bodies and expose it onParsedSendAction(Rust + JS types). - Update
Transaction.id()to use the root cell hash from the originally parsed root cell. - Expand Rust and JS test coverage to assert exact IDs and withdrawal amounts.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/wasm-ton/test/transaction.ts | Adds JS tests for exact transaction IDs and withdrawAmount parsing expectations. |
| packages/wasm-ton/src/wasm/try_into_js_value.rs | Exposes withdrawAmount in the JS object conversion for ParsedSendAction. |
| packages/wasm-ton/src/transaction.rs | Implements cell-hash-based transaction IDs and adds Rust tests asserting expected IDs. |
| packages/wasm-ton/src/parser.rs | Extends message-body parsing to extract withdrawal amounts for specific opcodes. |
| packages/wasm-ton/js/parser.ts | Updates TS types to include optional withdrawAmount?: bigint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/wasm-ton/src/transaction.rs
Outdated
| // The re-serialized cell hash (what the old buggy code computed) | ||
| let reserialized_hash = tx | ||
| .message | ||
| .to_cell(()) | ||
| .map(|cell| base64::engine::general_purpose::URL_SAFE.encode(cell.hash())) | ||
| .unwrap(); | ||
|
|
||
| // The original cell hash (what we now use) |
There was a problem hiding this comment.
The comment says the “re-serialized cell hash” is what the old buggy code computed, but prior to this change Transaction::id() was SHA-256 of the BOC bytes (not a cell hash). Please update the wording to avoid misleading future readers (e.g., describe it as a naive/alternative implementation based on message.to_cell() rather than “old code”).
| // The re-serialized cell hash (what the old buggy code computed) | |
| let reserialized_hash = tx | |
| .message | |
| .to_cell(()) | |
| .map(|cell| base64::engine::general_purpose::URL_SAFE.encode(cell.hash())) | |
| .unwrap(); | |
| // The original cell hash (what we now use) | |
| // The hash of a naively re-serialized message cell produced via `message.to_cell()`. | |
| let reserialized_hash = tx | |
| .message | |
| .to_cell(()) | |
| .map(|cell| base64::engine::general_purpose::URL_SAFE.encode(cell.hash())) | |
| .unwrap(); | |
| // The hash derived from the original parsed cell, which `Transaction::id()` returns. |
9d290b2 to
e9a68ef
Compare
- Parse withdraw amount from SingleNominator and Whales withdrawal message bodies, exposed as withdrawAmount on ParsedSendAction - Fix Transaction.id() to use cell hash instead of SHA-256 of BOC bytes, matching TON blockchain convention and TonWeb behavior - Expose withdrawAmount in JS via try_into_js_value and parser.ts types - Strengthen transaction tests to assert exact id and withdrawAmount values BTC-3246
e9a68ef to
079eda9
Compare
BTC-3246