chainsaw 
Deserializing Solana accounts using their progam IDL.
Table of Contents generated with DocToc
Installation
cargo add sol-chainsaw
Example
let opts = SerializationOpts ;
let mut chainsaw = new;
// 1. Add IDLS
// Candy Machine IDL
let cndy_program_id = "cndy3Z4yapfJBmL3ShUp5exZKqR3z33thTzeNMm2gRZ";
// Staking Program IDL
let stake_program_id = "StakeSSzfxn391k3LvdKbZP5WVwWd6AsY1DNiXHjQfK";
// 2. Read Accounts Data
// Stake Account
let stake_acc_data = read_account;
// Candy Machine Account
let cndy_acc_data = read_account;
// 3. Deserialize Accounts
// Stake Account
// Candy Machine Account
See ./examples/multiple_idls_and_accounts.rs for the full example.
Run it via: cargo run --example multiple_idls_and_accounts
Network Feature
To make retrieving IDLs from chain easier an idl client implementation is included which is
only enabled when the network feature is enabled.
let idl_client = for_anchor_on_mainnet;
let program_idl = idl_client.fetch?;
_more detailed example inside tests/task_update_idls.rs.
Development
Test Tasks
Various tasks related to tests were included via the ./Makefile. They are part of the tests folder but gated
behind features. Thus to activate them specific features need to be enabled.
In order to use a custom RPC cluster when running those tasks please provide it via the
RPC_URL env var, i.e.:
Updating IDLs
Inside ./tests/data/programs_with_idl.json are program
ids which have IDLs uploaded on chain.
Those IDLs are stored inside ./fixtures/idls to be used by integration tests.
- idl_update: update IDLs to what's currently on chain
Fetching Test Data from Chain
- fetch_account: fetches a specific account from chain (requires
ADDRESSenv var) and stores it in a tmp file - fetch_accounts_for_program: Updates accounts for specific program from chain (requires
PROGRAM_IDenv var) - fetch_accounts_for_all_programs: Updates accounts for all known program from chain (requires COUNT env var to indicate how many accounts per account type to fetch)
Triaging Account Deserialization
In order to isolate deserialization issues for specific accounts use on of the following tasks and provide the required env vars.
- deserialize_account_type_address_for_program: deserializes an account of program
PROGRAM_IDof account typeACCOUNT_TYPEat addressADDRESS - deserialize_account_type_for_program: deserializes all accounts of program
PROGRAM_IDand account typeACCOUNT_TYPE - deserialize_accounts_for_program: deserializes all accounts of program
PROGRAM_ID
Examples:
LICENSE
MIT