Skip to content

Commit 32010d5

Browse files
authored
Merge pull request #182 from BitGo/BTC-0.dot-parse-refactor
refactor: move explain logic out of wasm-dot, accept metadata as hex string
2 parents fb3f392 + 3ebe07d commit 32010d5

15 files changed

Lines changed: 190 additions & 904 deletions

File tree

package-lock.json

Lines changed: 0 additions & 294 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wasm-dot/js/explain.ts

Lines changed: 0 additions & 234 deletions
This file was deleted.

packages/wasm-dot/js/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
* wasm-dot: WASM bindings for Polkadot/DOT transaction operations
33
*
44
* This module provides:
5-
* - Transaction parsing: parseTransaction(bytes, context) → ParsedTransaction
6-
* - Transaction explanation: explainTransaction(bytes, options) → ExplainedTransaction
5+
* - Transaction parsing: parseTransaction(tx, context) → ParsedTransaction
76
* - Transaction building: buildTransaction(intent, context) → DotTransaction
87
* - Transaction signing: DotTransaction.fromBytes(bytes) → inspect + sign
98
*/
@@ -32,4 +31,3 @@ export * from "./types";
3231
export * from "./transaction";
3332
export * from "./parser";
3433
export * from "./builder";
35-
export * from "./explain";

packages/wasm-dot/js/parser.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Transaction parsing — standalone function that decodes extrinsic bytes
2+
* Transaction parsing — standalone function that decodes a DotTransaction
33
* into structured data (pallet, method, args, nonce, etc.).
44
*
55
* This is separate from the DotTransaction class, which handles signing.
@@ -8,51 +8,35 @@
88
*/
99

1010
import { ParserNamespace, MaterialJs, ParseContextJs } from "./wasm/wasm_dot";
11-
import { DotTransaction } from "./transaction";
11+
import type { DotTransaction } from "./transaction";
1212
import type { ParseContext, ParsedTransaction } from "./types";
1313

14-
/**
15-
* Input type for parsing — accepts raw bytes, hex string, or DotTransaction.
16-
*/
17-
export type TransactionInput = Uint8Array | string | DotTransaction;
18-
1914
/**
2015
* Parse a DOT transaction into structured data.
2116
*
17+
* Accepts a `DotTransaction` object (from `DotTransaction.fromBytes()`),
18+
* avoiding double deserialization.
19+
*
2220
* Returns a plain `ParsedTransaction` object with decoded pallet, method,
2321
* args, nonce, tip, era, etc.
2422
*
25-
* For a signable `DotTransaction` object, use `DotTransaction.fromBytes()` instead.
26-
*
27-
* @param input - Raw bytes, hex string (with or without 0x), or DotTransaction
23+
* @param tx - A DotTransaction instance (from DotTransaction.fromBytes())
2824
* @param context - Parsing context with chain material (required for decoding)
2925
* @returns Parsed transaction data
3026
*
3127
* @example
3228
* ```typescript
33-
* import { parseTransaction } from '@bitgo/wasm-dot';
29+
* import { DotTransaction, parseTransaction } from '@bitgo/wasm-dot';
3430
*
35-
* const parsed = parseTransaction(txBytes, { material });
31+
* const tx = DotTransaction.fromBytes(txBytes, context);
32+
* const parsed = parseTransaction(tx, { material });
3633
* console.log(parsed.method.pallet); // "balances"
3734
* console.log(parsed.method.name); // "transferKeepAlive"
3835
* ```
3936
*/
40-
export function parseTransaction(
41-
input: TransactionInput,
42-
context?: ParseContext,
43-
): ParsedTransaction {
37+
export function parseTransaction(tx: DotTransaction, context?: ParseContext): ParsedTransaction {
4438
const ctx = context ? createParseContext(context) : undefined;
45-
46-
if (input instanceof DotTransaction) {
47-
return ParserNamespace.parseTransaction(input.toBytes(), ctx) as ParsedTransaction;
48-
}
49-
50-
if (input instanceof Uint8Array) {
51-
return ParserNamespace.parseTransaction(input, ctx) as ParsedTransaction;
52-
}
53-
54-
// String input — let WASM handle hex parsing
55-
return ParserNamespace.parseTransactionHex(input, ctx) as ParsedTransaction;
39+
return ParserNamespace.parseFromTransaction(tx.wasm, ctx) as ParsedTransaction;
5640
}
5741

5842
/**

0 commit comments

Comments
 (0)