-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add unspent reservation example
TICKET: BTC-1501
- Loading branch information
1 parent
851a558
commit e4c8e4f
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |