Skip to content

Commit 99ca1a1

Browse files
Merge pull request #4988 from BitGo/BTC-1527-add-build-only-flag
feat(wp): add manage unspents build flag to fanoutUnspents
2 parents d1d8475 + fae6f66 commit 99ca1a1

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,6 @@ describe('V2 Wallet:', function () {
15001500
it('should pass unspents parameter when calling fanout unspents', async function () {
15011501
const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/fanoutUnspents`;
15021502
const response = nock(bgUrl)
1503-
.persist()
15041503
.post(path, _.matches({ unspents })) // use _.matches to do a partial match on request body object instead of strict matching
15051504
.reply(200);
15061505

@@ -1513,6 +1512,26 @@ describe('V2 Wallet:', function () {
15131512

15141513
response.isDone().should.be.true();
15151514
});
1515+
1516+
it('should only build tx (not sign/send) while fanning out unspents', async function () {
1517+
const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/fanoutUnspents`;
1518+
const response = nock(bgUrl).post(path, _.matches({ unspents })).reply(200);
1519+
1520+
const unusedNocks = nock(bgUrl);
1521+
unusedNocks.get(`/api/v2/${wallet.coin()}/key/${wallet.keyIds()[0]}`).reply(200);
1522+
unusedNocks.post(`/api/v2/${wallet.coin()}/wallet/${wallet.id()}/tx/send`).reply(200);
1523+
1524+
try {
1525+
await wallet.fanoutUnspents({ address, unspents }, ManageUnspentsOptions.BUILD_ONLY);
1526+
} catch (e) {
1527+
// the fanoutUnspents method will probably throw an exception for not having all of the correct nocks
1528+
// we only care about /fanoutUnspents and whether unspents is an allowed parameter
1529+
}
1530+
1531+
response.isDone().should.be.true();
1532+
unusedNocks.pendingMocks().length.should.eql(2);
1533+
nock.cleanAll();
1534+
});
15161535
});
15171536

15181537
describe('manage unspents', function () {
@@ -1570,6 +1589,7 @@ describe('V2 Wallet:', function () {
15701589
await wallet.consolidateUnspents({ bulk: true, walletPassphrase });
15711590

15721591
nocks.forEach((n) => {
1592+
console.log(n);
15731593
n.isDone().should.be.true();
15741594
});
15751595
});

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)