Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental: Add a function to get the addresses for lookup tables #2977

Open
mcintyre94 opened this issue Jul 24, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@mcintyre94
Copy link
Collaborator

Motivation

We have a type AddressesByLookupTableAddress which stores the addresses for lookup tables. I used this in the deserialize-transaction example. To get this you need to write code like:

// The only data from the lookup table we need is its addresses
type LookupTableData = {
    addresses: Address[];
};

// We fetch the JSON parsed representation of the lookup table from the RPC
const lookupTableAccount = await fetchJsonParsedAccount<LookupTableData>(rpc, LOOKUP_TABLE_ADDRESS);
assertAccountDecoded(lookupTableAccount);
assertAccountExists(lookupTableAccount);

const lookupAddresses = {
    [LOOKUP_TABLE_ADDRESS]: lookupTableAccount.data.addresses,
}

We could write a helper function that does this for you, with better error handling, perhaps for multiple lookup tables.

Example use case

const lookupAddresses = await fetchAddressesForLookupTableAddresses(rpc, [LOOKUP_TABLE_ADDRESS])

// compress a transaction message using the lookup tables
const transactionMessageWithLookupTables = compressTransactionMessageUsingAddressLookupTables(transactionMessage, lookupAddresses);

We also use the same data structure for decompileTransactionMessage

Details

  • Use await fetchJsonParsedAccounts
  • Add assertions that the accounts are owned by the Lookup Table Program
  • Add specific errors for the assertions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant