Derive Macro shank::ShankBuilder
source · #[derive(ShankBuilder)]
{
// Attributes available to this derive:
#[account]
#[args]
}
Expand description
Generates instruction builders for each annotated instruction.
An instruction builder is an struct that contains all the accounts for an instruction. You can
also include #[args] attributes to specify additional arguments that are passed to the builder.
Example
When you annotate your instruction with #[derive(ShankBuilder)]:
use borsh::{BorshDeserialize, BorshSerialize};
use shank::ShankBuilder;
#[derive(Debug, Clone, ShankBuilder, BorshSerialize, BorshDeserialize)]
#[rustfmt::skip]
pub enum Instruction {
/// This instruction stores an amout in the vault.
#[account(0, writable, name="vault", desc="Vault account")]
#[account(1, signer, name="authority", desc = "Authority of the vault")]
#[account(2, signer, writable, name = "payer", desc = "Payer")]
#[account(3, name = "system_program", desc = "System program")]
#[args(additional_accounts: Vec<AccountMeta>)]
Create(CreateArgs)
}Shank will generate a CreateBuilder struct in a submodule called builders. The builder can be used
to define the accounts and arguments for the instruction:
let create_ix = CreateBuilder::new()
.vault(vault_pubkey)
.authority(authority_pubkey)
.payer(payer_pubkey)
.build(additional_accounts)
.instruction();