Skip to content

fix: wasm-ton parser gaps and tx id computation#242

Merged
lcovar merged 1 commit intomasterfrom
BTC-3246-wasm-ton-fix-parser-gaps
Apr 3, 2026
Merged

fix: wasm-ton parser gaps and tx id computation#242
lcovar merged 1 commit intomasterfrom
BTC-3246-wasm-ton-fix-parser-gaps

Conversation

@lcovar
Copy link
Copy Markdown
Contributor

@lcovar lcovar commented Apr 1, 2026

  • 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

@lcovar lcovar requested a review from a team as a code owner April 1, 2026 18:30
@lcovar lcovar force-pushed the BTC-3246-wasm-ton-fix-parser-gaps branch from 6372b7e to 4197cfe Compare April 1, 2026 19:27
Comment on lines +8 to +9
/// Body parse result: (opcode, memo, jetton_transfer, withdraw_amount)
type BodyParseResult = (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's probably time to make this a struct

@lcovar lcovar force-pushed the BTC-3246-wasm-ton-fix-parser-gaps branch from 4197cfe to 9d290b2 Compare April 2, 2026 16:54
@lcovar lcovar requested a review from OttoAllmendinger April 2, 2026 17:28
@ppongbitgo ppongbitgo requested a review from Copilot April 2, 2026 18:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_amount from Whales + SingleNominator withdrawal message bodies and expose it on ParsedSendAction (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.

Comment on lines +175 to +182
// 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)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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”).

Suggested change
// 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.

Copilot uses AI. Check for mistakes.
@lcovar lcovar force-pushed the BTC-3246-wasm-ton-fix-parser-gaps branch from 9d290b2 to e9a68ef Compare April 2, 2026 19:02
- 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
@lcovar lcovar force-pushed the BTC-3246-wasm-ton-fix-parser-gaps branch from e9a68ef to 079eda9 Compare April 2, 2026 22:55
@lcovar lcovar merged commit 871430e into master Apr 3, 2026
14 checks passed
@lcovar lcovar deleted the BTC-3246-wasm-ton-fix-parser-gaps branch April 3, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants