Skip to content

Commit 5334d0b

Browse files
feat(bitgo): ada staking and unstaking tests
Ticket: BG-59726
1 parent 91875ec commit 5334d0b

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Send a staking transaction from a multi-sig wallet at BitGo.
3+
*
4+
* Copyright 2022, BitGo, Inc. All Rights Reserved.
5+
*/
6+
const BitGoJS = require('bitgo');
7+
const bitgo = new BitGoJS.BitGo({ env: 'test' });
8+
const Promise = require('bluebird');
9+
const coin = 'tada';
10+
const basecoin = bitgo.coin(coin);
11+
12+
// TODO: set your access token here
13+
const accessToken = '';
14+
const walletId = '631b73c2bf01c90007f9154194486da3';
15+
16+
// TODO: set your passphrase here
17+
const walletPassphrase = null;
18+
19+
Promise.coroutine(function *() {
20+
// generating address w/ same staking key and same payment key
21+
bitgo.authenticateWithAccessToken({ accessToken: accessToken });
22+
yield bitgo.unlock({ otp: '000000', duration: 3600 });
23+
const walletInstance = yield basecoin.wallets().get({ id: walletId });
24+
25+
const stakePoolKeyHash = 'fa1a5e1e70bc2fa7f60080b214f7bf5ab14c51da4b307a1a792c1714';
26+
27+
const whitelistedParams = {
28+
intent: {
29+
intentType: 'stake',
30+
stakingRequestId: '7265fe1ec9c304ad79f0-0000',
31+
poolKeyHash: stakePoolKeyHash,
32+
},
33+
apiVersion: 'lite',
34+
preview: undefined,
35+
};
36+
37+
const unsignedTx = (yield bitgo
38+
.post(bitgo.url('/wallet/' + walletId + '/txrequests', 2))
39+
.send(whitelistedParams)
40+
.result());
41+
42+
// sign tx
43+
const keychains = yield basecoin.keychains().getKeysForSigning({ wallet: walletInstance });
44+
const signedStakingTransaction = yield walletInstance.signTransaction({
45+
txPrebuild: unsignedTx,
46+
keychain: keychains[0],
47+
walletPassphrase: walletPassphrase,
48+
pubs: keychains.map((k) => k.pub),
49+
reqId: unsignedTx.txRequestId,
50+
});
51+
52+
// submit tx
53+
const submittedTx = yield bitgo
54+
.post(basecoin.url('/wallet/' + walletId + '/tx/send'))
55+
.send({ txRequestId: signedStakingTransaction.txRequestId })
56+
.result();
57+
58+
console.log('New Transaction:', JSON.stringify(submittedTx, null, 4));
59+
60+
})();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Send an unstaking transaction from a multi-sig wallet at BitGo.
3+
*
4+
* Copyright 2022, BitGo, Inc. All Rights Reserved.
5+
*/
6+
const BitGoJS = require('bitgo');
7+
const bitgo = new BitGoJS.BitGo({ env: 'test' });
8+
const Promise = require('bluebird');
9+
const coin = 'tada';
10+
const basecoin = bitgo.coin(coin);
11+
12+
// TODO: set your access token here
13+
const accessToken = '';
14+
const walletId = '631b73c2bf01c90007f9154194486da3';
15+
16+
// TODO: set your passphrase here
17+
const walletPassphrase = null;
18+
19+
Promise.coroutine(function *() {
20+
// generating address w/ same staking key and same payment key
21+
bitgo.authenticateWithAccessToken({ accessToken: accessToken });
22+
yield bitgo.unlock({ otp: '000000', duration: 3600 });
23+
const walletInstance = yield basecoin.wallets().get({ id: walletId });
24+
25+
const whitelistedParams = {
26+
intent: {
27+
intentType: 'unstake',
28+
stakingRequestId: '7265fe1ec9c304ad79f0-0000',
29+
},
30+
apiVersion: 'lite',
31+
preview: undefined,
32+
};
33+
// build tx
34+
const unsignedTx = (yield bitgo
35+
.post(bitgo.url('/wallet/' + walletId + '/txrequests', 2))
36+
.send(whitelistedParams)
37+
.result());
38+
39+
// sign tx
40+
const keychains = yield basecoin.keychains().getKeysForSigning({ wallet: walletInstance });
41+
const signedStakingTransaction = yield walletInstance.signTransaction({
42+
txPrebuild: unsignedTx,
43+
keychain: keychains[0],
44+
walletPassphrase: walletPassphrase,
45+
pubs: keychains.map((k) => k.pub),
46+
reqId: unsignedTx.txRequestId,
47+
});
48+
49+
// submit tx
50+
const submittedTx = yield bitgo
51+
.post(basecoin.url('/wallet/' + walletId + '/tx/send'))
52+
.send({ txRequestId: signedStakingTransaction.txRequestId })
53+
.result();
54+
55+
console.log('New Transaction:', JSON.stringify(submittedTx, null, 4));
56+
57+
})();

0 commit comments

Comments
 (0)