Skip to content

Commit decf227

Browse files
Merge pull request #9112 from BitGo/CECHO-1445/fix-flr-export-recipient-address
fix(sdk-coin-flr): auto-detect atomic export txs in explainTransaction
2 parents dc5729c + d3a368a commit decf227

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)