How can one set a variable number of input accounts for a an instruction wrapper?
ie given this:
#[derive(Accounts)]
pub struct Initialize<'info> {
...I'd like to specify here a random number of accounts
}
This is useful when you would want to refer to all creators of a digital asset (say NFT), but you don't know in advance how many there are.
Oh, I have just found out you can use something like this:
pub fn do_something(ctx: Context<Initialize>) -> ProgramResult {
let vec: Vec<AccountInfo> = ctx.remaining_accounts.into_vec();
// do something with the accounts
Ok(())
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.