Skip to content

Commit 6823157

Browse files
committed
fix(sdk-coin-stx): return required fields for unsigned sweep
Ticket: COIN-3893
1 parent ffa03f7 commit 6823157

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

modules/sdk-coin-stx/src/lib/iface.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { ClarityValue, PayloadType } from '@stacks/transactions';
3+
import { TransactionExplanation as BaseTransactionExplanation } from '@bitgo/sdk-core';
34

45
export interface TxData {
56
id: string;
@@ -107,6 +108,15 @@ export interface RecoveryOptions {
107108
contractId?: string;
108109
}
109110

111+
export interface RecoveryInfo extends BaseTransactionExplanation {
112+
txHex: string;
113+
feeInfo?: {
114+
fee: string;
115+
};
116+
coin?: string;
117+
}
118+
110119
export interface RecoveryTransaction {
111120
txHex: string;
121+
coin?: string;
112122
}

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ import { findContractTokenNameUsingContract, findTokenNameByContract, getAddress
4242
import {
4343
AddressDetails,
4444
NativeStxBalance,
45+
RecoveryInfo,
4546
RecoveryOptions,
4647
RecoveryTransaction,
4748
SingleFungibleTokenBalance,
4849
StxNonceResponse,
4950
StxTxnFeeEstimationResponse,
51+
TxData,
5052
} from './lib/iface';
5153
import { TransferBuilder } from './lib/transferBuilder';
5254
import { FungibleTokenTransferBuilder } from './lib/fungibleTokenTransferBuilder';
@@ -667,9 +669,9 @@ export class Stx extends BaseCoin {
667669
* @param {String} params.bitgoKey - encrypted bitgo public key
668670
* @param {String} params.walletPassphrase - wallet password
669671
* @param {String} params.contractId - contract id of the token (mandatory for token recovery)
670-
* @returns {Promise<RecoveryTransaction>} RecoveryTransaction.txHex - hex of serialized transaction (signed or unsigned)
672+
* @returns {Promise<RecoveryInfo|RecoveryTransaction>} RecoveryTransaction.txHex - hex of serialized transaction (signed or unsigned)
671673
*/
672-
async recover(params: RecoveryOptions): Promise<RecoveryTransaction> {
674+
async recover(params: RecoveryOptions): Promise<RecoveryInfo | RecoveryTransaction> {
673675
if (!this.isValidAddress(params.rootAddress)) {
674676
throw new Error('invalid root address!');
675677
}
@@ -716,9 +718,15 @@ export class Stx extends BaseCoin {
716718
const serializedTx: string = tx.toBroadcastFormat();
717719

718720
if (isUnsignedSweep) {
719-
return {
721+
const txJson: TxData = tx.toJson();
722+
const transactionExplanation: RecoveryInfo = (await this.explainTransaction({
720723
txHex: serializedTx,
721-
};
724+
feeInfo: { fee: txJson.fee },
725+
})) as RecoveryInfo;
726+
transactionExplanation.coin = this.getChain();
727+
transactionExplanation.feeInfo = { fee: txJson.fee };
728+
transactionExplanation.txHex = serializedTx;
729+
return transactionExplanation;
722730
}
723731
// check the private key & sign
724732
if (!keys[0].privateKey) {

modules/sdk-coin-stx/test/unit/sip10Token.ts

+3
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,10 @@ describe('Sip10Token:', function () {
311311
};
312312
const response: RecoveryTransaction = await basecoin.recover(recoveryOptions);
313313
response.should.have.property('txHex');
314+
response.should.have.property('coin');
315+
response.should.have.property('feeInfo');
314316
assert.deepEqual(response.txHex, testData.COLD_WALLET_TOKEN_UNSIGNED_SWEEP_TX_HEX, 'tx hex not matching!');
317+
assert.deepEqual(response.coin, 'tstx:tsip6dp', 'coin not matching!');
315318
});
316319

317320
it('should fail with insufficient balance when native stx balance is lower than fee for sip10', async () => {

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

+3
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,10 @@ describe('STX:', function () {
401401
};
402402
const response: RecoveryTransaction = await basecoin.recover(recoveryOptions);
403403
response.should.have.property('txHex');
404+
response.should.have.property('coin');
405+
response.should.have.property('feeInfo');
404406
assert.deepEqual(response.txHex, testData.COLD_WALLET_UNSIGNED_SWEEP_TX_HEX, 'tx hex not matching!');
407+
assert.deepEqual(response.coin, 'tstx', 'coin not matching!');
405408
});
406409

407410
it('should throw invalid root address when root address is missing or invalid', async function () {

0 commit comments

Comments
 (0)