nifty-oss / asset

A lightweight standard for non-fungible assets.
Apache License 2.0
38 stars 8 forks source link

Add allocate impl for cpi instruction #20

Closed febo closed 8 months ago

febo commented 8 months ago

This PR adds an extra impl block to the AllocateCpiAccounts struct to provide a memory-efficient way to invoke the instruction. The rationale is to avoid cloning the instruction data multiple times, which happens on the "standard" builder. The impl has a companion macro to prepare the instruction data.

let data = ...; // slice of extension data ([u8] or &[u8])

AllocateCpiAccounts {
    asset: ctx.accounts.asset,
    payer: Some(ctx.accounts.payer),
    system_program: Some(ctx.accounts.system_program),
}
.invoke(
    ctx.accounts.nifty_asset_program,
    allocate_instruction_data!(ExtensionType::Blob, data.len(), data),
)?;