Skip to content

Commit

Permalink
Merge pull request #3823 from BitGo/BTC-368.submit-codec.extend
Browse files Browse the repository at this point in the history
feat(sdk-core): use BuildParams codec in Wallet.accelerateTransaction
  • Loading branch information
OttoAllmendinger authored Aug 21, 2023
2 parents 4e8f0db + a3edcc3 commit eb9bea9
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 58 deletions.
1 change: 0 additions & 1 deletion modules/bitgo/.nvmrc

This file was deleted.

127 changes: 77 additions & 50 deletions modules/sdk-core/src/bitgo/wallet/BuildParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,93 @@ export const BuildParamsUTXO = t.partial({
cpfpTxIds: t.unknown,
unspents: t.unknown,
minValue: t.unknown,
minConfirms: t.unknown,
maxValue: t.unknown,
targetWalletUnspents: t.unknown,
/* unspent selection strategy */
strategy: t.unknown,
strategyAllowFallback: t.unknown,
noSplitChange: t.unknown,
smallestChangeSplitSize: t.unknown,
enforceMinConfirmsForChange: t.unknown,
/* legacy or psbt */
txFormat: t.unknown,
maxChangeOutputs: t.unknown,
});

export const BuildParams = t.intersection([
BuildParamsUTXO,
t.partial({
apiVersion: t.unknown,
consolidateAddresses: t.unknown,
feeRate: t.unknown,
gasLimit: t.unknown,
gasPrice: t.unknown,
hopParams: t.unknown,
idfSignedTimestamp: t.unknown,
idfUserId: t.unknown,
idfVersion: t.unknown,
instant: t.unknown,
lastLedgerSequence: t.unknown,
ledgerSequenceDelta: t.unknown,
maxFee: t.unknown,
maxFeeRate: t.unknown,
memo: t.unknown,
transferId: t.unknown,
message: t.unknown,
minConfirms: t.unknown,
numBlocks: t.unknown,
nonce: t.unknown,
pendingApprovalId: t.unknown,
preview: t.unknown,
previewPendingTxs: t.unknown,
receiveAddress: t.unknown,
recipients: t.unknown,
reservation: t.unknown,
sequenceId: t.unknown,
sourceChain: t.unknown,
destinationChain: t.unknown,
trustlines: t.unknown,
type: t.unknown,
nonParticipation: t.unknown,
validFromBlock: t.unknown,
validToBlock: t.unknown,
messageKey: t.unknown,
stakingOptions: t.unknown,
eip1559: t.unknown,
keyregTxBase64: t.unknown,
closeRemainderTo: t.unknown,
tokenName: t.unknown,
enableTokens: t.unknown,
// param to set emergency flag on a custodial transaction.
// This transaction should be performed in less than 1 hour or it will fail.
emergency: t.unknown,
}),
]);
export const BuildParamsStacks = t.partial({
contractName: t.unknown,
functionName: t.unknown,
functionArgs: t.unknown,
});

export type BuildParams = t.TypeOf<typeof BuildParams>;
export const BuildParamsOffchain = t.partial({
idfSignedTimestamp: t.unknown,
idfVersion: t.unknown,
idfUserId: t.unknown,
});

export const BuildParams = t.exact(
t.intersection([
BuildParamsUTXO,
BuildParamsStacks,
BuildParamsOffchain,
t.partial({
apiVersion: t.unknown,
consolidateAddresses: t.unknown,
consolidateId: t.unknown,
comment: t.string,
delayMs: t.unknown,
fee: t.unknown,
feeRate: t.unknown,
feeMultiplier: t.unknown,
enableTokens: t.unknown,
gasLimit: t.unknown,
gasPrice: t.unknown,
hopParams: t.unknown,
instant: t.unknown,
lastLedgerSequence: t.unknown,
ledgerSequenceDelta: t.unknown,
maxFee: t.unknown,
maxFeeRate: t.unknown,
memo: t.unknown,
transferId: t.unknown,
message: t.unknown,
numBlocks: t.unknown,
nonce: t.unknown,
pendingApprovalId: t.unknown,
preview: t.unknown,
previewPendingTxs: t.unknown,
senderAddress: t.unknown,
receiveAddress: t.unknown,
recipients: t.unknown,
reservation: t.unknown,
refundOptions: t.unknown,
sequenceId: t.unknown,
sourceChain: t.unknown,
destinationChain: t.unknown,
trustlines: t.unknown,
type: t.unknown,
timeBounds: t.unknown,
startTime: t.unknown,
stateProofKey: t.unknown,
nonParticipation: t.unknown,
validFromBlock: t.unknown,
validToBlock: t.unknown,
messageKey: t.unknown,
stakingParams: t.unknown,
stakingOptions: t.unknown,
unstakingOptions: t.unknown,
eip1559: t.unknown,
keyregTxBase64: t.unknown,
closeRemainderTo: t.unknown,
tokenName: t.unknown,
// param to set emergency flag on a custodial transaction.
// This transaction should be performed in less than 1 hour or it will fail.
emergency: t.unknown,
}),
])
);

export type BuildParams = t.TypeOf<typeof BuildParams>;
export const buildParamKeys = getCodecProperties(BuildParams);
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const SendTransactionRequest = t.exact(
invoice: t.unknown,
videoApprovers: t.array(t.unknown),
}),
BuildParams,
BuildParams.type,
])
);

Expand Down
10 changes: 5 additions & 5 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import { getTxRequest } from '../tss';
import { Hash } from 'crypto';
import { ofcTokens } from '@bitgo/statics';
import { SendTransactionRequest } from './SendTransactionRequest';
import { buildParamKeys } from './BuildParams';
import { buildParamKeys, BuildParams } from './BuildParams';
import { postWithCodec } from '../utils/postWithCodec';

const debug = require('debug')('bitgo:v2:wallet');
Expand Down Expand Up @@ -1931,10 +1931,10 @@ export class Wallet implements IWallet {

params.recipients = [];

// We must pass the build params through to submit in case the CPFP tx ever has to be rebuilt.
const submitParams = Object.assign(params, await this.prebuildAndSignTransaction(params));
delete (submitParams as any).wallet;
return await this.submitTransaction(submitParams);
return await this.submitTransaction({
...(await this.prebuildAndSignTransaction(params)),
...BuildParams.encode(params),
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@ import { getCodecProperties } from '../../../../src/bitgo/utils/codecProps';

describe('SendTransactionRequest', function () {
it('has expected property count', function () {
assert.strictEqual(getCodecProperties(BuildParams).length, 54);
assert.strictEqual(getCodecProperties(BuildParams).length, 72);
});

it('enforces codec', function () {
assert.deepStrictEqual(
BuildParams.encode({
addressType: 'p2sh',
txFormat: 'psbt',
comment: 'foo',
unknown: 'bar',
} as any),
{
addressType: 'p2sh',
txFormat: 'psbt',
comment: 'foo',
// drops unknown properties
}
);

assert.deepStrictEqual(SendTransactionRequest.encode({ txHex: '00' }), { txHex: '00' });
assert.deepStrictEqual(SendTransactionRequest.encode({ txHex: '00', addressType: 'p2sh', bar: 'omit' } as any), {
txHex: '00',
Expand Down

0 comments on commit eb9bea9

Please sign in to comment.