pub use crate::state::*;
use anchor_lang::{prelude::*, system_program::System};
#[derive(Accounts)]
#[instruction(tirgger_index: u64, conditions: AdjacencyTree)]
pub struct UpdateTrigger<'info> {
#[account(mut)]
signer: Signer<'info>,
#[account(mut, seeds = ["user".as_bytes(), &signer.key().to_bytes()], bump)]
user: Account<'info, User>,
#[account(
mut,
seeds = ["trigger".as_bytes(), &signer.key().to_bytes()[..], &tirgger_index.to_le_bytes()],
bump,
realloc = 8 + Trigger::get_size(&conditions),
realloc::payer = signer,
realloc::zero = true
)]
trigger: Account<'info, Trigger>,
system_program: Program<'info, System>,
}
pub fn handler(ctx: Context<UpdateTrigger>, _trigger_index: u64, conditions: AdjacencyTree) -> Result<()> {
ctx.accounts.trigger.conditions = conditions;
Ok(())
}