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 AddMiddleware<'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<AddMiddleware>, middleware: Middleware) -> Result<()> {
    ctx.accounts.program_account.add_middleware(
        middleware.name,
        middleware.program_id,
        middleware.accounts_count,
    );

    Ok(())
}