Skip to content

Commit 25b65b8

Browse files
committed
fix: add toJsonFromWasm adapter and metadata-aware parsing fixes
- update wasm-dot tarball with parse-refactor changes: - Material.metadata is string (hex) matching Substrate RPC wire format - parseTransaction accepts DotTransaction only (not raw bytes/hex) - DotTransaction.fromHex/fromBytes accept material for metadata-aware signed extension parsing - explainTransaction removed from wasm-dot (now in BitGoJS) - simplify wasmParser.ts: pass material directly (no type conversion needed) - remove unused ParsedTransaction import BTC-0 TICKET: BTC-0
1 parent 127c729 commit 25b65b8

8 files changed

Lines changed: 369 additions & 103 deletions

File tree

modules/sdk-coin-dot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@bitgo/sdk-core": "^36.33.2",
4444
"@bitgo/sdk-lib-mpc": "^10.9.0",
4545
"@bitgo/statics": "^58.29.0",
46-
"@bitgo/wasm-dot": "^1.1.0",
46+
"@bitgo/wasm-dot": "^1.1.2",
4747
"@polkadot/api": "14.1.1",
4848
"@polkadot/api-augment": "14.1.1",
4949
"@polkadot/keyring": "13.5.6",

modules/sdk-coin-dot/src/dot.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Environments,
88
ExplanationResult,
99
KeyPair,
10-
TransactionType,
1110
MPCAlgorithm,
1211
ParsedTransaction,
1312
ParseTransactionOptions,
@@ -40,8 +39,6 @@ import {
4039
Transaction,
4140
TransactionBuilderFactory,
4241
Utils,
43-
explainDotTransaction,
44-
type DotWasmExplanation,
4542
} from './lib';
4643
import '@polkadot/api-augment';
4744
import { ApiPromise, WsProvider } from '@polkadot/api';
@@ -204,25 +201,6 @@ export class Dot extends BaseCoin {
204201
* @param unsignedTransaction
205202
*/
206203
async explainTransaction(unsignedTransaction: UnsignedTransaction): Promise<ExplanationResult> {
207-
// Testnet uses WASM-based parsing (no @polkadot/api dependency).
208-
if (this.getChain() === 'tdot') {
209-
const material = dotUtils.getMaterial(coins.get(this.getChain()));
210-
const wasmExplain = explainDotTransaction({
211-
txHex: unsignedTransaction.serializedTxHex,
212-
material,
213-
});
214-
return {
215-
...wasmExplain,
216-
type: TransactionType[wasmExplain.type],
217-
outputs: wasmExplain.outputs.map((o) => ({
218-
...o,
219-
valueString: String(o.amount),
220-
})),
221-
sequenceId: wasmExplain.nonce,
222-
blockNumber: unsignedTransaction.coinSpecific?.blockNumber,
223-
};
224-
}
225-
226204
let outputAmount = 0;
227205
unsignedTransaction.parsedTx.outputs.forEach((o) => {
228206
outputAmount += parseInt(o.valueString, 10);
@@ -253,15 +231,6 @@ export class Dot extends BaseCoin {
253231
return explanationResult;
254232
}
255233

256-
/**
257-
* Explain a DOT transaction from hex using WASM parsing.
258-
* Bypasses txwrapper-polkadot rebuild — delegates to explainDotTransaction().
259-
*/
260-
explainTransactionWithWasm(txHex: string, senderAddress?: string): DotWasmExplanation {
261-
const material = dotUtils.getMaterial(coins.get(this.getChain()));
262-
return explainDotTransaction({ txHex, material, senderAddress });
263-
}
264-
265234
verifySignTransactionParams(params: SignTransactionOptions): VerifiedTransactionParameters {
266235
const prv = params.prv;
267236

modules/sdk-coin-dot/src/lib/transaction.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
} from './iface';
3939
import { getAddress, getDelegateAddress } from './iface_utils';
4040
import utils from './utils';
41-
import { explainDotTransaction } from './wasmParser';
41+
import { toJsonFromWasm } from './wasmParser';
4242
import BigNumber from 'bignumber.js';
4343
import { Vec } from '@polkadot/types';
4444
import { PalletConstantMetadataV14 } from '@polkadot/types/interfaces';
@@ -162,6 +162,20 @@ export class Transaction extends BaseTransaction {
162162
if (!this._dotTransaction) {
163163
throw new InvalidTransactionError('Empty transaction');
164164
}
165+
166+
// WASM path for signed tdot transactions — validates WASM parsing against production.
167+
// Only for signed txs because toBroadcastFormat() returns the signed extrinsic (parseable).
168+
// Unsigned txs return a signing payload (different format), so they use the legacy path.
169+
if (this._coinConfig.name === 'tdot' && this._signedTransaction) {
170+
return toJsonFromWasm({
171+
txHex: this._signedTransaction,
172+
material: utils.getMaterial(this._coinConfig),
173+
senderAddress: this._sender,
174+
coinConfigName: this._coinConfig.name,
175+
referenceBlock: this._dotTransaction.blockHash,
176+
blockNumber: Number(this._dotTransaction.blockNumber),
177+
});
178+
}
165179
const decodedTx = decode(this._dotTransaction, {
166180
metadataRpc: this._dotTransaction.metadataRpc,
167181
registry: this._registry,
@@ -339,17 +353,6 @@ export class Transaction extends BaseTransaction {
339353

340354
/** @inheritdoc */
341355
explainTransaction(): TransactionExplanation {
342-
// Testnet uses WASM-based parsing (no @polkadot/api dependency).
343-
// This validates the WASM path against production traffic before
344-
// replacing the legacy implementation for all networks.
345-
if (this._coinConfig.name === 'tdot' && this._dotTransaction) {
346-
return explainDotTransaction({
347-
txHex: this.toBroadcastFormat(),
348-
material: utils.getMaterial(this._coinConfig),
349-
senderAddress: this._sender,
350-
});
351-
}
352-
353356
const result = this.toJson();
354357
const displayOrder = ['outputAmount', 'changeAmount', 'outputs', 'changeOutputs', 'fee', 'type'];
355358
const outputs: TransactionRecipient[] = [];

0 commit comments

Comments
 (0)