Skip to content

Commit

Permalink
TECH-667 Update solana version and remove deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelleher committed Sep 18, 2024
1 parent 011d223 commit e142485
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['12.x', '14.x']
node: ['16.x', '18.x', '20.x']
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
setupFilesAfterEnv: ["<rootDir>/test/setupTests.js"],
};
18 changes: 10 additions & 8 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SystemProgram,
Transaction,
TransactionInstruction,
TransactionResponse,
VersionedTransactionResponse,
} from '@solana/web3.js';
import { encode } from 'bs58';

Expand Down Expand Up @@ -85,20 +85,19 @@ export const makeTransaction = async (
toPubkey,
});

const { blockhash } = await connection.getLatestBlockhash();
const tx = new Transaction({
recentBlockhash: blockhash,
const blockhashWithExpiryBlockHeight = await connection.getLatestBlockhash();
return new Transaction({
feePayer: fromPubkey,
...blockhashWithExpiryBlockHeight,
}).add(instruction);
return tx;
};

const findBlock = async (
connection: Connection,
blockhash: string
): Promise<void> =>
connection
.getFeeCalculatorForBlockhash(blockhash, 'confirmed')
.isBlockhashValid(blockhash, { commitment: 'confirmed' })
.then(result => {
if (!result.value) throw new Error('Block was not found');
// if we were interested in the age of the block,
Expand All @@ -117,12 +116,15 @@ export const checkRecentBlock = async (
const findTransaction = async (
connection: Connection,
transaction: Transaction
): Promise<TransactionResponse | null> => {
): Promise<VersionedTransactionResponse | null> => {
if (!transaction.signature) {
throw new Error('Transaction has no signature');
}
const txSig = encode(transaction.signature);
return connection.getTransaction(txSig);
return connection.getTransaction(txSig, {
commitment: 'confirmed',
maxSupportedTransactionVersion: 0,
});
};

export const checkTransactionNotBroadcast = async (
Expand Down
7 changes: 7 additions & 0 deletions test/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const nodeCrypto = require('crypto');

Object.defineProperty(global, 'crypto', {
value: {
getRandomValues: arr => nodeCrypto.randomBytes(arr.length),
},
});
Loading

0 comments on commit e142485

Please sign in to comment.