diff --git a/contracts/programs/gummyroll/src/lib.rs b/contracts/programs/gummyroll/src/lib.rs index 3517a40ed13..7c6f69b2800 100644 --- a/contracts/programs/gummyroll/src/lib.rs +++ b/contracts/programs/gummyroll/src/lib.rs @@ -13,14 +13,12 @@ pub mod state; pub mod utils; use crate::error::GummyrollError; -use crate::state::{ChangeLogEvent, MerkleRollHeader}; -use crate::utils::ZeroCopy; +use crate::state::{CandyWrapper, ChangeLogEvent, MerkleRollHeader}; +use crate::utils::{wrap_event, ZeroCopy}; pub use concurrent_merkle_tree::{error::CMTError, merkle_roll::MerkleRoll, state::Node}; declare_id!("GRoLLMza82AiYN7W9S9KCCtCyyPRAQP2ifBy4v4D5RMD"); -const MAX_TREE_DEPTH: usize = 30; - #[derive(Accounts)] pub struct Initialize<'info> { #[account(zero)] @@ -29,6 +27,7 @@ pub struct Initialize<'info> { pub authority: Signer<'info>, /// CHECK: unsafe pub append_authority: UncheckedAccount<'info>, + pub candy_wrapper: Program<'info, CandyWrapper>, } #[derive(Accounts)] @@ -37,6 +36,7 @@ pub struct Modify<'info> { /// CHECK: This account is validated in the instruction pub merkle_roll: UncheckedAccount<'info>, pub authority: Signer<'info>, + pub candy_wrapper: Program<'info, CandyWrapper>, } #[derive(Accounts)] @@ -46,6 +46,7 @@ pub struct Append<'info> { pub merkle_roll: UncheckedAccount<'info>, pub authority: Signer<'info>, pub append_authority: Signer<'info>, + pub candy_wrapper: Program<'info, CandyWrapper>, } #[derive(Accounts)] @@ -130,7 +131,7 @@ fn fill_in_proof_from_canopy( proof: &mut Vec, ) -> Result<()> { // 26 is hard coded as it is the current max depth that Gummyroll supports - let mut empty_node_cache = Box::new([EMPTY; MAX_TREE_DEPTH]); + let mut empty_node_cache = Box::new([EMPTY; 30]); check_canopy_bytes(canopy_bytes)?; let canopy = cast_slice_mut::(canopy_bytes); let path_len = get_cached_path_length(canopy, max_depth)?; @@ -148,7 +149,7 @@ fn fill_in_proof_from_canopy( }; if canopy[cached_idx] == EMPTY { let level = max_depth - (31 - node_idx.leading_zeros()); - let empty_node = empty_node_cached::(level, &mut empty_node_cache); + let empty_node = empty_node_cached::<30>(level, &mut empty_node_cache); canopy[cached_idx] = empty_node; inferred_nodes.push(empty_node); } else { @@ -297,6 +298,7 @@ pub mod gummyroll { let (roll_bytes, canopy_bytes) = rest.split_at_mut(merkle_roll_size); let id = ctx.accounts.merkle_roll.key(); let change_log = merkle_roll_apply_fn!(header, id, roll_bytes, initialize,)?; + wrap_event(change_log.try_to_vec()?, &ctx.accounts.candy_wrapper)?; emit!(*change_log); update_canopy(canopy_bytes, header.max_depth, None) } @@ -354,6 +356,7 @@ pub mod gummyroll { &proof, index )?; + wrap_event(change_log.try_to_vec()?, &ctx.accounts.candy_wrapper)?; emit!(*change_log); update_canopy(canopy_bytes, header.max_depth, Some(change_log)) } @@ -394,6 +397,7 @@ pub mod gummyroll { &proof, index, )?; + wrap_event(change_log.try_to_vec()?, &ctx.accounts.candy_wrapper)?; emit!(*change_log); update_canopy(canopy_bytes, header.max_depth, Some(change_log)) } @@ -474,6 +478,7 @@ pub mod gummyroll { let merkle_roll_size = merkle_roll_get_size!(header)?; let (roll_bytes, canopy_bytes) = rest.split_at_mut(merkle_roll_size); let change_log = merkle_roll_apply_fn!(header, id, roll_bytes, append, leaf)?; + wrap_event(change_log.try_to_vec()?, &ctx.accounts.candy_wrapper)?; emit!(*change_log); update_canopy(canopy_bytes, header.max_depth, Some(change_log)) } @@ -512,6 +517,7 @@ pub mod gummyroll { &proof, index, )?; + wrap_event(change_log.try_to_vec()?, &ctx.accounts.candy_wrapper)?; emit!(*change_log); update_canopy(canopy_bytes, header.max_depth, Some(change_log)) }