diff --git a/modules/sdk-core/src/bitgo/wallet/iWallet.ts b/modules/sdk-core/src/bitgo/wallet/iWallet.ts index b80ae7310f..608a8fa652 100644 --- a/modules/sdk-core/src/bitgo/wallet/iWallet.ts +++ b/modules/sdk-core/src/bitgo/wallet/iWallet.ts @@ -297,6 +297,22 @@ export interface UnspentsOptions extends PaginationOptions { chains?: number[]; } +export interface ManageUnspentReservationOptions { + create?: { + unspentIds: string[]; + expireTime: string; + }; + modify?: { + unspentIds: string[]; + changes: { + expireTime: string; + }; + }; + delete?: { + id: string; + }; +} + export interface ConsolidateUnspentsOptions extends WalletSignTransactionOptions { walletPassphrase?: string; xprv?: string; diff --git a/modules/sdk-core/src/bitgo/wallet/wallet.ts b/modules/sdk-core/src/bitgo/wallet/wallet.ts index f57976c3da..a70269d868 100644 --- a/modules/sdk-core/src/bitgo/wallet/wallet.ts +++ b/modules/sdk-core/src/bitgo/wallet/wallet.ts @@ -96,6 +96,7 @@ import { CreateBulkWalletShareListResponse, SharedKeyChain, BulkWalletShareKeychain, + ManageUnspentReservationOptions, } from './iWallet'; import { StakingWallet } from '../staking'; import { Lightning } from '../lightning/custodial'; @@ -740,6 +741,32 @@ export class Wallet implements IWallet { return Array.isArray(buildResponse) ? response : response[0]; } + /** + * Manage the unspent reservations on the wallet + * + * @param params.create - create a new reservation + * @param params.modify - modify an existing reservation + * @param params.delete - delete an existing reservation + */ + async manageUnspentReservations(params: ManageUnspentReservationOptions): Promise { + const filteredParams = _.pick(params, ['create', 'modify', 'delete']); + this.bitgo.setRequestTracer(new RequestTracer()); + // The URL cannot contain the coinName, so we remove it from the URL + const url = this.url(`/reservedunspents`).replace(`/${this.baseCoin.getChain()}`, ''); + if (filteredParams.create) { + const filteredCreateParams = _.pick(params.create, ['unspentIds', 'expireTime']); + return this.bitgo.post(url).send(filteredCreateParams).result(); + } else if (filteredParams.modify) { + const filteredModifyParams = _.pick(params.modify, ['unspentIds', 'changes']); + return this.bitgo.put(url).send(filteredModifyParams).result(); + } else if (filteredParams.delete) { + const filteredDeleteParams = _.pick(params.delete, ['id']); + return this.bitgo.del(url).query(filteredDeleteParams).result(); + } else { + throw new Error('Did not detect a creation, modification, or deletion request.'); + } + } + /** * Consolidate unspents on a wallet *