Skip to content

Commit a2c323b

Browse files
committed
fet(hbar): add AccountUpdate support to explainTransaction in BitGoJS
ticket: SI-511
1 parent 27f3db2 commit a2c323b

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,15 @@ export class Hbar extends BaseCoin {
751751
});
752752
break;
753753

754+
case 'cryptoUpdateAccount':
755+
const updateParams = txJson.instructionsData.params;
756+
outputs.push({
757+
address: updateParams.accountId,
758+
amount: '0',
759+
memo,
760+
});
761+
break;
762+
754763
default:
755764
throw new Error('Transaction format outside of cryptoTransfer not supported for explanation.');
756765
}

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,67 @@ describe('Hedera Hashgraph:', function () {
179179
explain.changeAmount.should.equal('0');
180180
});
181181

182+
it('should explain an account update (staking) transaction', async function () {
183+
const sourceAccountId = '0.0.81320';
184+
const factory = getBuilderFactory('thbar');
185+
const txBuilder = factory.getAccountUpdateBuilder();
186+
txBuilder.fee({ fee: '1000000000' });
187+
txBuilder.source({ address: sourceAccountId });
188+
txBuilder.stakedNodeId(3);
189+
txBuilder.declineStakingReward(false);
190+
txBuilder.node({ nodeId: '0.0.2345' });
191+
txBuilder.startTime('1596110493.372646570');
192+
const tx = await txBuilder.build();
193+
const txHex = tx.toBroadcastFormat();
194+
195+
const explain = await basecoin.explainTransaction({
196+
txHex,
197+
feeInfo: {
198+
size: 1000,
199+
fee: 1160407,
200+
feeRate: 1160407,
201+
},
202+
});
203+
204+
explain.id.should.equal(sourceAccountId + '@1596110493.372646570');
205+
explain.outputAmount.should.equal('0');
206+
explain.timestamp.should.equal('1596110493.372646570');
207+
explain.outputs.length.should.equal(1);
208+
explain.outputs[0].amount.should.equal('0');
209+
explain.outputs[0].address.should.equal(sourceAccountId);
210+
explain.outputs[0].memo.should.equal('');
211+
explain.fee.should.equal(1160407);
212+
explain.changeAmount.should.equal('0');
213+
});
214+
215+
it('should explain an unstake (account update with nodeId -1) transaction', async function () {
216+
const sourceAccountId = '0.0.81320';
217+
const factory = getBuilderFactory('thbar');
218+
const txBuilder = factory.getAccountUpdateBuilder();
219+
txBuilder.fee({ fee: '1000000000' });
220+
txBuilder.source({ address: sourceAccountId });
221+
txBuilder.stakedNodeId(-1);
222+
txBuilder.node({ nodeId: '0.0.2345' });
223+
txBuilder.startTime('1596110493.372646570');
224+
const tx = await txBuilder.build();
225+
const txHex = tx.toBroadcastFormat();
226+
227+
const explain = await basecoin.explainTransaction({
228+
txHex,
229+
feeInfo: {
230+
size: 1000,
231+
fee: 1160407,
232+
feeRate: 1160407,
233+
},
234+
});
235+
236+
explain.outputAmount.should.equal('0');
237+
explain.outputs.length.should.equal(1);
238+
explain.outputs[0].amount.should.equal('0');
239+
explain.outputs[0].address.should.equal(sourceAccountId);
240+
explain.fee.should.equal(1160407);
241+
});
242+
182243
it('should verify isWalletAddress', async function () {
183244
const baseAddress = '0.0.41098';
184245
const validAddress1 = '0.0.41098?memoId=1';

0 commit comments

Comments
 (0)