Skip to content

Commit

Permalink
feat(sdk-core): add prebuild staking transaction function (Ticket: SC-96
Browse files Browse the repository at this point in the history
)
  • Loading branch information
quarterdill committed Jun 25, 2024
1 parent 77f3db7 commit 6ba48e0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = {
'QA-',
'RA-',
'SO-',
'SC-',
'ST-',
'STLX-',
'TRUST-',
Expand Down
31 changes: 31 additions & 0 deletions modules/bitgo/test/v2/unit/staking/stakingWalletCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,35 @@ describe('Staking Wallet Common', function () {
msScope.isDone().should.be.True();
});
});

describe('prebuildSelfManagedStakingTransaction', function () {
it('should prebuild self-managed staking transaction', async function () {
const transaction = fixtures.transaction('READY', fixtures.buildParams);
nock(microservicesUri)
.get(
`/api/staking/v1/${stakingWallet.coin}/wallets/${stakingWallet.walletId}/requests/${transaction.stakingRequestId}/transactions/${transaction.id}`
)
.query({ expandBuildParams: true })
.reply(200, transaction);
const buildResult = {
txBase64:
'AAAAANsKrHV2BVjACFt2xlyhxYzP2MNBmb4IQ5E9/WiJiV3TAAABLAAM4aEAAAAHAAAAAAAAAAAAAAABAAAAAAAAAAYAAAABQlNUAAAAAABhNDpbuY4frrgwVQqkws7jxK+k4IMrJ6BaE0OFUva9vwAAAOjUpRAAAAAAAAAAAAA=',
};

nock(microservicesUri).post(`/api/v2/${stakingWallet.coin}/wallet/walletId/tx/build`).reply(200, buildResult);
console.log(`/api/v2/${stakingWallet.coin}/wallet/${stakingWallet.walletId}/tx/build`);
const formattedParams = {
...fixtures.buildParams,
coin: stakingWallet.coin,
walletId: stakingWallet.walletId,
walletType: stakingWallet.wallet.type(),
preview: true,
};
const expected = await stakingWallet.wallet.prebuildTransaction(formattedParams);
const stakingTransaction = await stakingWallet.prebuildSelfManagedStakingTransaction(transaction);

stakingTransaction.should.deepEqual(expected);
should.exist(stakingTransaction);
});
});
});
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/staking/iStakingWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,5 @@ export interface IStakingWallet {
send(signedTransaction: StakingSignedTransaction): Promise<StakingTransaction>;
buildSignAndSend(signOptions: StakingSignOptions, transaction: StakingTransaction);
cancelStakingRequest(stakingRequestId: string): Promise<StakingRequest>;
prebuildSelfManagedStakingTransaction(transaction: StakingTransaction): Promise<PrebuildTransactionResult>;
}
19 changes: 18 additions & 1 deletion modules/sdk-core/src/bitgo/staking/stakingWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
ClaimRewardsOptions,
} from './iStakingWallet';
import { BitGoBase } from '../bitgoBase';
import { IWallet } from '../wallet';
import { IWallet, PrebuildTransactionResult } from '../wallet';
import { ITssUtils, RequestTracer, TssUtils } from '../utils';

export class StakingWallet implements IStakingWallet {
Expand Down Expand Up @@ -215,6 +215,23 @@ export class StakingWallet implements IStakingWallet {
});
}

/**
* Create prebuilt staking transaction.
* @param transaction
*/
async prebuildSelfManagedStakingTransaction(transaction: StakingTransaction): Promise<PrebuildTransactionResult> {
const builtStakingTransaction = await this.build(transaction);
const buildParams = builtStakingTransaction.transaction.buildParams;
const formattedParams = {
...buildParams,
coin: this.coin,
walletId: this.walletId,
walletType: this.wallet.type(),
preview: true,
};
return await this.wallet.prebuildTransaction(formattedParams);
}

/**
* Build and sign the transaction.
* @param signOptions
Expand Down

0 comments on commit 6ba48e0

Please sign in to comment.