metaplex-foundation/kinobi

Add support for nested account structs on instructions

Closed this issue · 0 comments

febo commented

When using Anchor, it is possible to have nested account structs to organize the list of accounts of an instruction:

// The instruction account list.
#[derive(Accounts)]
pub struct MyInstruction<'info> {
  pub shared: InnerAccountStruct<'info>,

  #[account(mut)]
  pub payer: Signer<'info>,
}

// An "inner" account struct to encapsulate shared accounts,
// most likely used across different instructions.
#[derive(Accounts)]
pub struct InnerAccountStruct<'info> {
  #[account(mut)]
  pub state: UncheckedAccount<'info>,

  pub owner: UncheckedAccount<'info>,
}

This will result on an IDL looking like:

{
  {
      "name": "myInstruction",
      "accounts": [
        {
          "name": "shared",
          "accounts": [
            {
              "name": "state",
              "isMut": true,
              "isSigner": false
            },
            {
              "name": "owner",
              "isMut": false,
              "isSigner": false
            },
          ]
        },
        {
          "name": "payer",
          "isMut": true,
          "isSigner": true
        }
      ]
   }
}

The end result is that the client generated code will represent the "account" shared as a single PublicKey instead of flattening the struct to include both state and owner accounts.