triggr/instructions/
update_middleware.rs

1pub use crate::state::*;
2pub use anchor_lang::prelude::*;
3
4#[derive(Accounts)]
5#[instruction(services: Vec<Middleware>)]
6pub struct UpdateMiddleware<'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(
17    ctx: Context<UpdateMiddleware>,
18    index: u32,
19    program_id: Pubkey,
20    accounts_count: u8,
21) -> Result<()> {
22    ctx.accounts.program_account.update_middleware_by_index(
23        index as usize,
24        program_id,
25        accounts_count,
26    );
27    Ok(())
28}