Skip to content

Commit

Permalink
cache addressLookupTableAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop committed Dec 4, 2024
1 parent ad3e9e6 commit 297ce77
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "dotenv/config";
import { getKeypairFromEnvironment } from "@solana-developers/helpers";
import axios from "axios";
import {
AddressLookupTableAccount,
Connection,
PublicKey,
VersionedTransaction,
Expand Down Expand Up @@ -39,6 +40,8 @@ function instructionFormat(instruction) {
};
}

const addressLookupTables: { [key: string]: AddressLookupTableAccount[] } = {};

async function run() {

const start = Date.now();
Expand Down Expand Up @@ -127,7 +130,12 @@ async function run() {
// ALT
const addressLookupTableAccounts = await Promise.all(
instructions.addressLookupTableAddresses.map(async (address) => {
if (addressLookupTables[address]) {
return addressLookupTables[address];
}

const result = await connection.getAddressLookupTable(new PublicKey(address));
addressLookupTables[address] = result.value;
return result.value;
})
);
Expand Down

0 comments on commit 297ce77

Please sign in to comment.