use {
anchor_lang::{
prelude::*,
solana_program::system_program
},
crate::state,
std::mem::size_of
};
#[derive(Accounts)]
#[instruction(
namespace: String,
is_serial: bool,
bump: u8,
)]
pub struct CreateIndex<'info> {
#[account(
init,
seeds = [
state::SEED_INDEX,
signer.key().as_ref(),
namespace.as_ref()
],
bump = bump,
payer = signer,
space = 8 + size_of::<state::Index>()
)]
pub index: Account<'info, state::Index>,
#[account(mut)]
pub signer: Signer<'info>,
#[account(address = system_program::ID)]
pub system_program: Program<'info, System>,
}
pub fn handler(
ctx: Context<CreateIndex>,
namespace: String,
is_serial: bool,
bump: u8,
) -> ProgramResult {
let index = &mut ctx.accounts.index;
let signer = &ctx.accounts.signer;
index.owner = signer.key();
index.namespace = namespace;
index.count = 0;
index.is_serial = is_serial;
index.bump = bump;
return Ok(());
}