Skip to content

Commit 7584c8b

Browse files
committed
fix(abstract-eth): fix issue with ethlike signTx
COIN-2506 TICKET: COIN-2506
1 parent ec62e4e commit 7584c8b

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,12 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
10131013
}
10141014
const transaction = await txBuilder.build();
10151015

1016-
const recipients = transaction.outputs.map((output) => ({ address: output.address, amount: output.value }));
1016+
// In case of tx with contract data from a custodial wallet, we are running into an issue
1017+
// as halfSigned is not having the data field. So, we are adding the data field to the halfSigned tx
1018+
let recipients = params.txPrebuild.recipients || params.recipients;
1019+
if (recipients === undefined) {
1020+
recipients = transaction.outputs.map((output) => ({ address: output.address, amount: output.value }));
1021+
}
10171022

10181023
const txParams = {
10191024
eip1559: params.txPrebuild.eip1559,

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,56 @@ describe('Optimism', function () {
232232
halfSignedRawTx.halfSigned.eip1559.maxFeePerGas.should.equal('7593123');
233233
halfSignedRawTx.halfSigned.eip1559.maxPriorityFeePerGas.should.equal('150');
234234
});
235+
236+
it('should sign an unsigned test tx with data', async function () {
237+
const builder = getBuilder('topeth') as TransactionBuilder;
238+
builder.fee({
239+
fee: '280000000000',
240+
gasLimit: '7000000',
241+
eip1559: {
242+
maxFeePerGas: '7593123',
243+
maxPriorityFeePerGas: '150',
244+
},
245+
});
246+
builder.counter(1);
247+
builder.type(TransactionType.Send);
248+
builder.contract(account_1.address);
249+
const transferBuilder = builder.transfer() as TransferBuilder;
250+
transferBuilder.coin('topeth').amount('1').to(account_2.address).expirationTime(10000).contractSequenceId(1);
251+
252+
const unsignedTx = await builder.build();
253+
const unsignedTxForBroadcasting = unsignedTx.toBroadcastFormat();
254+
255+
const halfSignedRawTx = await basecoin.signTransaction({
256+
txPrebuild: {
257+
txHex: unsignedTxForBroadcasting,
258+
eip1559: {
259+
maxFeePerGas: '7593123',
260+
maxPriorityFeePerGas: '150',
261+
},
262+
recipients: [
263+
{
264+
address: account_2.address,
265+
amount: '1',
266+
data: '0xaaaa',
267+
},
268+
],
269+
},
270+
prv: account_1.owner_2,
271+
});
272+
273+
builder.transfer().key(account_1.owner_2);
274+
const halfSignedTx = await builder.build();
275+
const halfSignedTxForBroadcasting = halfSignedTx.toBroadcastFormat();
276+
277+
halfSignedRawTx.halfSigned.txHex.should.equals(halfSignedTxForBroadcasting);
278+
halfSignedRawTx.halfSigned.recipients.length.should.equals(1);
279+
halfSignedRawTx.halfSigned.recipients[0].address.toLowerCase().should.equals(account_2.address.toLowerCase());
280+
halfSignedRawTx.halfSigned.recipients[0].amount.toLowerCase().should.equals('1');
281+
halfSignedRawTx.halfSigned.recipients[0].data.toLowerCase().should.equals('0xaaaa');
282+
halfSignedRawTx.halfSigned.eip1559.maxFeePerGas.should.equal('7593123');
283+
halfSignedRawTx.halfSigned.eip1559.maxPriorityFeePerGas.should.equal('150');
284+
});
235285
});
236286

237287
describe('Transaction Verification', function () {

0 commit comments

Comments
 (0)