Skip to content

Commit

Permalink
Merge pull request #4952 from BitGo/BTC-1501-fanout-specific-unspents
Browse files Browse the repository at this point in the history
feat(wp) fanout specific unspents
  • Loading branch information
kcheng-bitgo committed Sep 27, 2024
2 parents 09b4423 + dc22770 commit ef802f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
23 changes: 22 additions & 1 deletion modules/bitgo/test/v2/unit/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1461,9 +1461,13 @@ describe('V2 Wallet:', function () {
});
});

describe('maxNumInputsToUse verification', function () {
describe('fanout input maxNumInputsToUse and unspents verification', function () {
const address = '5b34252f1bf349930e34020a';
const maxNumInputsToUse = 2;
const unspents = [
'cc30565750e2aeb818625aaedaf89db5c614e5977b9645cee1d7289f616fb1d8:0',
'8c45164787a954ab07864af9b05b34fbde3a8e430a8c65b0e60e4e543d8e1b6c:2',
];
let basecoin;
let wallet;

Expand Down Expand Up @@ -1492,6 +1496,23 @@ describe('V2 Wallet:', function () {

response.isDone().should.be.true();
});

it('should pass unspents parameter when calling fanout unspents', async function () {
const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/fanoutUnspents`;
const response = nock(bgUrl)
.persist()
.post(path, _.matches({ unspents })) // use _.matches to do a partial match on request body object instead of strict matching
.reply(200);

try {
await wallet.fanoutUnspents({ address, unspents });
} catch (e) {
// the fanoutUnspents method will probably throw an exception for not having all of the correct nocks
// we only care about /fanoutUnspents and whether unspents is an allowed parameter
}

response.isDone().should.be.true();
});
});

describe('manage unspents', function () {
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/wallet/iWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export interface FanoutUnspentsOptions extends WalletSignTransactionOptions {
maxValue?: number | string;
minHeight?: number;
maxNumInputsToUse?: number;
unspents?: string[];
numUnspentsToMake?: number;
minConfirms?: number;
enforceMinConfirmsForChange?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ export class Wallet implements IWallet {
common.validateParams(params, [], ['walletPassphrase', 'xprv']);

const reqId = new RequestTracer();
const fanoutInputFormat = params.maxNumInputsToUse ? 'maxNumInputsToUse' : 'unspents';
const filteredParams = _.pick(params, [
'feeRate',
'maxFeeRate',
Expand All @@ -695,7 +696,7 @@ export class Wallet implements IWallet {
'txFormat',
'bulk',

routeName === 'consolidate' ? 'limit' : 'maxNumInputsToUse',
routeName === 'consolidate' ? 'limit' : fanoutInputFormat,
'numUnspentsToMake',
]);
this.bitgo.setRequestTracer(reqId);
Expand Down

0 comments on commit ef802f2

Please sign in to comment.