anchor-decoder
A procedural macro to help with decoding Solana accounts and instructions for programs written with the Anchor framework.
Note: this tool relies on IDLs generated by Anchor 0.30.0. Fortunately, there's a CLI command to help convert legacy IDLs to the new format.
Usage
Add the crate to your Cargo.toml, and point the macro at your IDL:
use anchor_idl;
pub const ID: Pubkey = crateID;
You can also call the macro multiple times in the same files by using separate modules.
Using Decoders
I recommend creating separate crates for each parser. You can then install and import crates as needed. Assume you have a separate crate called program_decoder. You can then use the decoders as follows:
Decode instructions
use ;
let ix: CompiledInstruction = ...;
let account_keys: = ...;
match decode_instruction ;
Decode accounts
use ;
let account_data: = ...;
let account_key: Pubkey = ...;
// account decoder shown here, but it works the same for `decode_instruction`
match decode_account
There are more examples in the examples/ directory.
License
The project is licensed under Apache 2.0.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.
Contribution
Any contributions are welcome. If you notice there's an IDL that doesn't breaks the macro, please open an issue or submit a pull request.