Skip to content

Commit 40dae3b

Browse files
authored
Merge pull request #7287 from BitGo/derek/SC-3567-add-recent-blockhash-to-versioned-tx-flow
feat(sdk-coin-sol): add recentBlockhash to custom versioned solana tx flow
2 parents 8609b2c + 191eb86 commit 40dae3b

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

modules/sdk-coin-sol/src/lib/iface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ export interface VersionedTransactionData {
261261
numReadonlySignedAccounts: number;
262262
numReadonlyUnsignedAccounts: number;
263263
};
264+
recentBlockhash?: string;
264265
}
265266

266267
export interface AddressLookupTable {

modules/sdk-coin-sol/src/lib/transactionBuilder.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,10 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
258258
data: Buffer.from(base58.decode(instruction.data)),
259259
}));
260260

261-
if (!this._recentBlockhash) {
262-
throw new BuildTransactionError('Missing nonce (recentBlockhash) for VersionedTransaction');
261+
const recentBlockhash = data.recentBlockhash || this._recentBlockhash;
262+
263+
if (!recentBlockhash) {
264+
throw new BuildTransactionError('Missing recent blockhash for VersionedTransaction');
263265
}
264266

265267
if (!this._sender) {
@@ -269,7 +271,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
269271
const messageV0 = new MessageV0({
270272
header: data.messageHeader,
271273
staticAccountKeys,
272-
recentBlockhash: this._recentBlockhash,
274+
recentBlockhash: recentBlockhash,
273275
compiledInstructions,
274276
addressTableLookups,
275277
});

modules/sdk-coin-sol/test/unit/versionedTransaction.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('Sol Jupiter Swap Transaction', () => {
3737
addressLookupTables,
3838
staticAccountKeys,
3939
messageHeader: originalDeserialized.message.header,
40+
recentBlockhash: originalDeserialized.message.recentBlockhash,
4041
};
4142

4243
const factory = getBuilderFactory('tsol');
@@ -197,7 +198,7 @@ describe('Sol Jupiter Swap Transaction', () => {
197198
);
198199
});
199200

200-
it('should not inject nonce advance when using regular nonce (no durableNonceParams)', async function () {
201+
it('should not inject nonce advance when using recentBlockhash (no durableNonceParams)', async function () {
201202
const versionedTransactionData = {
202203
versionedInstructions: [
203204
{
@@ -213,6 +214,7 @@ describe('Sol Jupiter Swap Transaction', () => {
213214
numReadonlySignedAccounts: 0,
214215
numReadonlyUnsignedAccounts: 0,
215216
},
217+
recentBlockhash: testData.blockHashes.validBlockHashes[0],
216218
};
217219

218220
const factory = getBuilderFactory('tsol');

modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface SolVersionedTransactionData {
6868
numReadonlySignedAccounts: number;
6969
numReadonlyUnsignedAccounts: number;
7070
};
71+
recentBlockhash?: string;
7172
}
7273

7374
export interface aptosCustomTransactionParams {

modules/sdk-core/src/bitgo/wallet/iWallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export interface PrebuildTransactionOptions {
202202
numReadonlySignedAccounts: number;
203203
numReadonlyUnsignedAccounts: number;
204204
};
205+
recentBlockhash?: string;
205206
};
206207
/**
207208
* Custom transaction parameters for Aptos entry function calls.

0 commit comments

Comments
 (0)