triggr-program 0.1.1

Created with Anchor
Documentation
pub use crate::state::*;
pub use anchor_lang::prelude::*;

#[derive(Accounts)]
#[instruction(services: Vec<Middleware>)]
pub struct UpdateMiddleware<'info> {
    #[account(mut, constraint = program_account.authority == authority.key())]
    authority: Signer<'info>,

    #[account(mut,  seeds = ["program".as_bytes()], bump, realloc = 8 + ProgramState::SIZE + (services.len() * Middleware::SIZE) , realloc::payer = authority, realloc::zero = true,)]
    program_account: Account<'info, ProgramState>,

    system_program: Program<'info, System>,
}

pub fn handler(
    ctx: Context<UpdateMiddleware>,
    index: u32,
    program_id: Pubkey,
    accounts_count: u8,
) -> Result<()> {
    ctx.accounts.program_account.update_middleware_by_index(
        index as usize,
        program_id,
        accounts_count,
    );
    Ok(())
}