Skip to content

Commit 2de4b27

Browse files
fix(sdk-coin-flr): auto-detect atomic export txs in explainTransaction
When the FLR wallet platform calls explainTransaction for a cross-chain export without setting crossChainType, the method falls through to the EVM explain path which cannot parse atomic transaction hex, causing the recipient P-chain address to be missing from the result. Avalanche/Flare atomic transactions are identified by their codec prefix (0x00000000). Add auto-detection: if the tx hex starts with '0000' (after stripping any 0x prefix), route to explainAtomicTransaction even when crossChainType is not supplied. This ensures the P-chain recipient address always appears in outputs[0].address for export transactions, regardless of whether the caller sets crossChainType explicitly. Add regression tests in both sdk-coin-flr and sdk-coin-flrp that verify outputs[0].address is non-empty for C-chain export transactions. Ticket: CECHO-1445 Session-Id: 9552a57f-ade5-43df-b67b-d19aa62e6e32 Task-Id: 1785a314-e5c6-4b30-b86e-46e56c9206ed
1 parent dc5729c commit 2de4b27

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ export class Flr extends AbstractEthLikeNewCoins {
176176
if (!txHex) {
177177
throw new Error('missing txHex in explain tx parameters');
178178
}
179-
if (params.crossChainType) {
179+
// Avalanche atomic transactions are identified by their codec prefix (0x00000000).
180+
// Auto-detect them so callers don't need to pass crossChainType explicitly.
181+
const hexWithout0x = txHex.startsWith('0x') ? txHex.slice(2) : txHex;
182+
if (params.crossChainType || hexWithout0x.startsWith('0000')) {
180183
return this.explainAtomicTransaction(txHex);
181184
}
182185
if (!params.feeInfo) {

modules/sdk-coin-flr/test/unit/flr.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,19 @@ describe('flr', function () {
249249
txExplain.changeOutputs.should.be.empty();
250250
});
251251

252+
it('should explain an export in C transaction without crossChainType when hex is atomic', async function () {
253+
const testData = EXPORT_C_TEST_DATA;
254+
// Wallet platform may omit crossChainType; auto-detection via codec prefix must still return
255+
// the recipient P-chain address so the UI can display it.
256+
const txExplain = await tflrCoin.explainTransaction({
257+
txHex: testData.fullsigntxHex,
258+
});
259+
txExplain.type.should.equal(TransactionType.Export);
260+
const sortedPAddresses = testData.pAddresses.slice().sort().join('~');
261+
txExplain.outputs[0].address.should.equal(sortedPAddresses);
262+
txExplain.outputAmount.should.equal(testData.amount);
263+
});
264+
252265
it('should throw error when missing txHex', async function () {
253266
await tflrCoin
254267
.explainTransaction({ crossChainType: 'export' } as ExplainTransactionOptions)

modules/sdk-coin-flrp/test/unit/flrp.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ describe('Flrp test cases', function () {
282282
txExplain.changeOutputs.should.be.empty();
283283
});
284284

285+
it('should explain a signed export from C-chain transaction and include recipient P-chain address', async () => {
286+
const txExplain = await basecoin.explainTransaction({ txHex: EXPORT_IN_C.signedHex });
287+
288+
txExplain.type.should.equal(TransactionType.Export);
289+
txExplain.outputs.should.be.an.Array();
290+
txExplain.outputs.length.should.equal(1);
291+
// The recipient address must be the P-chain destination — not empty.
292+
txExplain.outputs[0].address.should.be.a.String();
293+
txExplain.outputs[0].address.should.not.be.empty();
294+
txExplain.outputs[0].address.should.startWith('P-');
295+
txExplain.changeOutputs.should.be.empty();
296+
});
297+
285298
it('should fail when transaction hex is not provided', async () => {
286299
await basecoin.explainTransaction({}).should.be.rejectedWith('missing transaction hex');
287300
});

0 commit comments

Comments
 (0)