triggr/instructions/
add_middleware.rs1pub use crate::state::*;
2pub use anchor_lang::prelude::*;
3
4#[derive(Accounts)]
5#[instruction(services: Vec<Middleware>)]
6pub struct AddMiddleware<'info> {
7 #[account(mut, constraint = program_account.authority == authority.key())]
8 authority: Signer<'info>,
9
10 #[account(mut, seeds = ["program".as_bytes()], bump, realloc = 8 + ProgramState::SIZE + (services.len() * Middleware::SIZE) , realloc::payer = authority, realloc::zero = true,)]
11 program_account: Account<'info, ProgramState>,
12
13 system_program: Program<'info, System>,
14}
15
16pub fn handler(ctx: Context<AddMiddleware>, middleware: Middleware) -> Result<()> {
17 ctx.accounts.program_account.add_middleware(
18 middleware.name,
19 middleware.program_id,
20 middleware.accounts_count,
21 );
22
23 Ok(())
24}