/**
 * This code was GENERATED using the solita package.
 * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality.
 *
 * See: https://github.com/metaplex-foundation/solita
 */

import * as beet from '@metaplex-foundation/beet';
import * as web3 from '@solana/web3.js';

/**
 * @category Instructions
 * @category VerifyLeaf
 * @category generated
 */
export type VerifyLeafInstructionArgs = {
  root: number[] /* size: 32 */;
  leaf: number[] /* size: 32 */;
  index: number;
};
/**
 * @category Instructions
 * @category VerifyLeaf
 * @category generated
 */
export const verifyLeafStruct = new beet.BeetArgsStruct<
  VerifyLeafInstructionArgs & {
    instructionDiscriminator: number[] /* size: 8 */;
  }
>(
  [
    ['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)],
    ['root', beet.uniformFixedSizeArray(beet.u8, 32)],
    ['leaf', beet.uniformFixedSizeArray(beet.u8, 32)],
    ['index', beet.u32],
  ],
  'VerifyLeafInstructionArgs'
);
/**
 * Accounts required by the _verifyLeaf_ instruction
 *
 * @property [] merkleTree
 * @category Instructions
 * @category VerifyLeaf
 * @category generated
 */
export type VerifyLeafInstructionAccounts = {
  merkleTree: web3.PublicKey;
  anchorRemainingAccounts?: web3.AccountMeta[];
};

export const verifyLeafInstructionDiscriminator = [
  124, 220, 22, 223, 104, 10, 250, 224,
];

/**
 * Creates a _VerifyLeaf_ instruction.
 *
 * @param accounts that will be accessed while the instruction is processed
 * @param args to provide as instruction data to the program
 *
 * @category Instructions
 * @category VerifyLeaf
 * @category generated
 */
export function createVerifyLeafInstruction(
  accounts: VerifyLeafInstructionAccounts,
  args: VerifyLeafInstructionArgs,
  programId = new web3.PublicKey('cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK')
) {
  const [data] = verifyLeafStruct.serialize({
    instructionDiscriminator: verifyLeafInstructionDiscriminator,
    ...args,
  });
  const keys: web3.AccountMeta[] = [
    {
      pubkey: accounts.merkleTree,
      isWritable: false,
      isSigner: false,
    },
  ];

  if (accounts.anchorRemainingAccounts != null) {
    for (const acc of accounts.anchorRemainingAccounts) {
      keys.push(acc);
    }
  }

  const ix = new web3.TransactionInstruction({
    programId,
    keys,
    data,
  });
  return ix;
}
