Skip to content

Commit 667c366

Browse files
committed
feat(sdk-core): add BUILD_ONLY flag to fanoutUnspents
TICKET: BTC-1527
1 parent f1fabfe commit 667c366

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

modules/bitgo/test/v2/unit/wallet.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,21 @@ describe('V2 Wallet:', function () {
15131513

15141514
response.isDone().should.be.true();
15151515
});
1516+
1517+
it('should only build tx (not sign/send) while fanning out unspents', async function () {
1518+
const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/fanoutUnspents`;
1519+
const response = nock(bgUrl).persist().post(path, _.matches({ unspents })).reply(200);
1520+
1521+
const unusedNocks = nock(bgUrl);
1522+
unusedNocks.get(`/api/v2/${wallet.coin()}/key/${wallet.keyIds()[0]}`).reply(200);
1523+
unusedNocks.post(`/api/v2/${wallet.coin()}/wallet/${wallet.id()}/tx/send`).reply(200);
1524+
1525+
await wallet.fanoutUnspents({ address, unspents }, ManageUnspentsOptions.BUILD_ONLY);
1526+
1527+
response.isDone().should.be.true();
1528+
unusedNocks.pendingMocks().length.should.eql(2);
1529+
nock.cleanAll();
1530+
});
15161531
});
15171532

15181533
describe('manage unspents', function () {

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,14 @@ export class Wallet implements IWallet {
815815
* @param {Number} params.maxFeeRate - The max limit for a fee rate in satoshis/kB
816816
* @param {Number} params.maxNumInputsToUse - the number of unspents you want to use in the transaction
817817
* @param {Number} params.numUnspentsToMake - the number of new unspents to make
818+
*
819+
* @param {ManageUnspentsOptions} option - flag to toggle build and send or build only
818820
*/
819-
async fanoutUnspents(params: FanoutUnspentsOptions = {}): Promise<unknown> {
820-
return this.manageUnspents('fanout', params);
821+
async fanoutUnspents(
822+
params: FanoutUnspentsOptions = {},
823+
option = ManageUnspentsOptions.BUILD_SIGN_SEND
824+
): Promise<unknown> {
825+
return this.manageUnspents('fanout', params, option);
821826
}
822827

823828
/**

0 commit comments

Comments
 (0)