Skip to content

Commit 0da7eaa

Browse files
Merge pull request #7276 from BitGo/COIN-6108
fix: return recipients in unsigned transaction
2 parents 30c45cb + 0c6c2cd commit 0da7eaa

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { AbstractEthLikeCoin } from './abstractEthLikeCoin';
6767
import { EthLikeToken } from './ethLikeToken';
6868
import {
6969
calculateForwarderV1Address,
70+
decodeTransferData,
7071
ERC1155TransferBuilder,
7172
ERC721TransferBuilder,
7273
getBufferedByteCode,
@@ -1570,6 +1571,30 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
15701571
};
15711572
}
15721573

1574+
/**
1575+
* Extract recipients from transaction hex
1576+
* @param txHex - The transaction hex string
1577+
* @returns Array of recipients with address and amount
1578+
*/
1579+
private async extractRecipientsFromTxHex(txHex: string): Promise<Array<{ address: string; amount: string }>> {
1580+
const txBuffer = optionalDeps.ethUtil.toBuffer(txHex);
1581+
const decodedTx = optionalDeps.EthTx.TransactionFactory.fromSerializedData(txBuffer);
1582+
const recipients: Array<{ address: string; amount: string }> = [];
1583+
1584+
if (decodedTx.data && decodedTx.data.length > 0) {
1585+
const dataHex = optionalDeps.ethUtil.bufferToHex(decodedTx.data);
1586+
const transferData = decodeTransferData(dataHex);
1587+
if (transferData.to) {
1588+
recipients.push({
1589+
address: transferData.to,
1590+
amount: transferData.amount,
1591+
});
1592+
}
1593+
}
1594+
1595+
return recipients;
1596+
}
1597+
15731598
async sendCrossChainRecoveryTransaction(
15741599
params: SendCrossChainRecoveryOptions
15751600
): Promise<{ coin: string; txHex?: string; txid: string }> {
@@ -1617,15 +1642,22 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
16171642
};
16181643
}
16191644

1620-
async buildCrossChainRecoveryTransaction(
1621-
recoveryId: string
1622-
): Promise<{ coin: string; txHex: string; txid: string; walletVersion?: number }> {
1645+
async buildCrossChainRecoveryTransaction(recoveryId: string): Promise<{
1646+
coin: string;
1647+
txHex: string;
1648+
txid: string;
1649+
walletVersion?: number;
1650+
recipients: Array<{ address: string; amount: string }>;
1651+
}> {
16231652
const res = await this.bitgo.get(this.bitgo.microservicesUrl(`/api/recovery/v1/crosschain/${recoveryId}/buildtx`));
1653+
// Extract recipients from the transaction hex
1654+
const recipients = await this.extractRecipientsFromTxHex(res.body.txHex);
16241655
return {
16251656
coin: res.body.coin,
16261657
txHex: res.body.txHex,
16271658
txid: res.body.txid,
16281659
walletVersion: res.body.walletVersion,
1660+
recipients,
16291661
};
16301662
}
16311663

modules/sdk-coin-ethlike/test/unit/ethlikeCoin.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,37 @@ describe('EthLike coin tests', function () {
9494
result.txHex.should.equal(mockData.ccr[coin.name].txHex);
9595
});
9696

97+
it('should build cross chain recovery transaction and extract recipients', async function () {
98+
const recoveryId = '0x1234567890abcdef';
99+
const mockResponse = {
100+
coin: coin.name,
101+
txHex: mockData.ccr[coin.name].txHex,
102+
txid: mockData.ccr[coin.name].txid,
103+
walletVersion: 1,
104+
};
105+
106+
nock(bitgo.microservicesUrl(`/api/recovery/v1/crosschain`))
107+
.get(`/${recoveryId}/buildtx`)
108+
.reply(200, mockResponse);
109+
110+
const result = await basecoin.buildCrossChainRecoveryTransaction(recoveryId);
111+
112+
result.should.have.property('coin');
113+
result.coin.should.equal(coin.name);
114+
result.should.have.property('txHex');
115+
result.txHex.should.equal(mockData.ccr[coin.name].txHex);
116+
result.should.have.property('txid');
117+
result.txid.should.equal(mockData.ccr[coin.name].txid);
118+
result.should.have.property('walletVersion');
119+
result.should.have.property('recipients');
120+
result.recipients.should.be.an.Array();
121+
const recipient = result.recipients[0];
122+
recipient.should.have.property('address');
123+
recipient.should.have.property('amount');
124+
recipient.address.should.be.a.String();
125+
recipient.amount.should.be.a.String();
126+
});
127+
97128
it('should generate signature data for custodial hot wallet and sign using hsm signature', async function () {
98129
const baseAddress = '0x702cf81e03aa310ec9481d814e3d04a20b04b505';
99130
const destinationAddress = '0xb9f62c71d5f6949cfb211a67fb13ccf079cc760b';

0 commit comments

Comments
 (0)