1

Is it possible to allocate space to an account based on account provided in remaining_accounts? I want to allocate enough space to store public key of the accounts provided in remaining_accounts in a struct (State).

This demonstrates what I am trying to do:

#[account(
  init,
  seeds = [STATE_SEED.as_ref(), signer.key().as_ref()],
  bump,
  payer = proposer,
  space = 8 + 4 + remaining_accounts.len() * 32
)]
pub state: Account<'info, State>

Should I just send the length of remaining_accounts as instruction data?

1 Answer 1

1

Should I just send the length of remaining_accounts as instruction data?

This is the only way to do it, and then use that instruction data in the context macros with

#[instruction(...)]

The Context<...> struct is not available to the accounts struct and/or the account macros as it would be referencing itself prior to instantiation.

1
  • Thank you for your answer.
    – onurhb
    Commented Apr 5, 2023 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.