Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion modules/sdk-coin-flr/src/flr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ export class Flr extends AbstractEthLikeNewCoins {
if (!txHex) {
throw new Error('missing txHex in explain tx parameters');
}
if (params.crossChainType) {
// Avalanche atomic transactions are identified by their codec prefix (0x00000000).
// Auto-detect them so callers don't need to pass crossChainType explicitly.
const hexWithout0x = txHex.startsWith('0x') ? txHex.slice(2) : txHex;
if (params.crossChainType || hexWithout0x.startsWith('0000')) {
return this.explainAtomicTransaction(txHex);
}
if (!params.feeInfo) {
Expand Down
13 changes: 13 additions & 0 deletions modules/sdk-coin-flr/test/unit/flr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ describe('flr', function () {
txExplain.changeOutputs.should.be.empty();
});

it('should explain an export in C transaction without crossChainType when hex is atomic', async function () {
const testData = EXPORT_C_TEST_DATA;
// Wallet platform may omit crossChainType; auto-detection via codec prefix must still return
// the recipient P-chain address so the UI can display it.
const txExplain = await tflrCoin.explainTransaction({
txHex: testData.fullsigntxHex,
});
txExplain.type.should.equal(TransactionType.Export);
const sortedPAddresses = testData.pAddresses.slice().sort().join('~');
txExplain.outputs[0].address.should.equal(sortedPAddresses);
txExplain.outputAmount.should.equal(testData.amount);
});

it('should throw error when missing txHex', async function () {
await tflrCoin
.explainTransaction({ crossChainType: 'export' } as ExplainTransactionOptions)
Expand Down
13 changes: 13 additions & 0 deletions modules/sdk-coin-flrp/test/unit/flrp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ describe('Flrp test cases', function () {
txExplain.changeOutputs.should.be.empty();
});

it('should explain a signed export from C-chain transaction and include recipient P-chain address', async () => {
const txExplain = await basecoin.explainTransaction({ txHex: EXPORT_IN_C.signedHex });

txExplain.type.should.equal(TransactionType.Export);
txExplain.outputs.should.be.an.Array();
txExplain.outputs.length.should.equal(1);
// The recipient address must be the P-chain destination — not empty.
txExplain.outputs[0].address.should.be.a.String();
txExplain.outputs[0].address.should.not.be.empty();
txExplain.outputs[0].address.should.startWith('P-');
txExplain.changeOutputs.should.be.empty();
});

it('should fail when transaction hex is not provided', async () => {
await basecoin.explainTransaction({}).should.be.rejectedWith('missing transaction hex');
});
Expand Down
Loading