Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wp) fanout specific unspents #4952

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading