Skip to content

Commit

Permalink
chore: add unspent reservation example
Browse files Browse the repository at this point in the history
TICKET: BTC-1501
  • Loading branch information
davidkaplanbitgo committed Sep 25, 2024
1 parent e1b44f8 commit b2d00c1
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/ts/reserve-unspents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Manage unspent reservations on your wallet
*
* Copyright 2024 BitGo, Inc. All Rights Reserved.
*/

const BitGoJS = require('modules/bitgo');

// change this to env: 'prod' when you are ready for production
const env = 'test';
// change coin to 'btc' when working with production
const coin = env === 'test' ? 'tbtc' : 'btc';

const bitgo = new BitGoJS.BitGo({ env });

// set your access token here
const accessToken = '';

// set the unspent IDs to manage the reservations of
const unspentIds = ['', ''];

// set the expire time for the reservation (use 'never' to freeze)
const expireTime = '';

async function createUnspentReservation() {

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused function createUnspentReservation.
bitgo.authenticateWithAccessToken({ accessToken });
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });

const reserveResult = await wallet.manageUnspentReservations({
create: { unspentIds, expireTime: 'never' },
});
console.log('reserved ' + JSON.stringify(reserveResult, null, 2));
}

async function modifyUnspentReservation() {

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused function modifyUnspentReservation.
bitgo.authenticateWithAccessToken({ accessToken });
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });

const reserveResult = await wallet.manageUnspentReservations({
modify: { unspentIds, changes: { expireTime } },
});
console.log('modified ' + JSON.stringify(reserveResult, null, 2));
}

async function releaseUnspentReservation() {

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused function releaseUnspentReservation.
bitgo.authenticateWithAccessToken({ accessToken });
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });

const reserveResult = await wallet.manageUnspentReservations({
delete: { id: unspentIds[0] },
});
console.log('released ' + JSON.stringify(reserveResult, null, 2));
}

// createUnspentReservation().catch(console.error);
// modifyUnspentReservation().catch(console.error);
// releaseUnspentReservation().catch(console.error);

0 comments on commit b2d00c1

Please sign in to comment.