diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b6ed3c8..6cb090b5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,17 +2,13 @@ name: Set-Up & Build & Test # Controls when the action will run. on: - push: - branches: - - "**" # matches every branch - - "!master" # excludes master - pull_request: - branches: - - "**" # matches every branch - - "!master" # excludes master - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: + push: + branches: + - "**" # matches every branch + - "!master" # excludes master + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: diff --git a/pallets/merkle/src/lib.rs b/pallets/merkle/src/lib.rs index bac9ca2b..fbe57973 100644 --- a/pallets/merkle/src/lib.rs +++ b/pallets/merkle/src/lib.rs @@ -192,9 +192,12 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] + #[pallet::metadata(T::AccountId = "AccountId", T::GroupId = "GroupId")] pub enum Event { + /// New tree created + NewTree(T::GroupId, T::AccountId, bool), /// New members/leaves added to the tree - NewMember(T::GroupId, T::AccountId, Vec), + NewMembers(T::GroupId, T::AccountId, u32, Vec), } /// Old name generated by `decl_event`. @@ -498,8 +501,10 @@ impl Group for Pallet { Groups::::insert(group_id, Some(mtree)); // Setting up the manager - let manager = Manager::::new(sender, is_manager_required); + let manager = Manager::::new(sender.clone(), is_manager_required); Managers::::insert(group_id, Some(manager)); + + Self::deposit_event(Event::NewTree(group_id, sender, is_manager_required)); Ok(group_id) } @@ -549,9 +554,10 @@ impl Group for Pallet { Self::is_manager_required(sender.clone(), &manager_data), Error::::ManagerIsRequired ); - let num_points = members.len() as u32; + let leaf_count_before = tree.leaf_count; + let num_members = members.len() as u32; ensure!( - tree.leaf_count + num_points <= tree.max_leaves, + leaf_count_before + num_members <= tree.max_leaves, Error::::ExceedsMaxLeaves ); @@ -564,7 +570,7 @@ impl Group for Pallet { Groups::::insert(id, Some(tree)); // Raising the New Member event for the client to build a tree locally - Self::deposit_event(Event::NewMember(id, sender, members)); + Self::deposit_event(Event::NewMembers(id, sender, leaf_count_before, members)); Ok(()) } diff --git a/pallets/mixer/src/lib.rs b/pallets/mixer/src/lib.rs index cc1663a0..8ba17051 100644 --- a/pallets/mixer/src/lib.rs +++ b/pallets/mixer/src/lib.rs @@ -140,18 +140,32 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] - #[pallet::metadata(::AccountId = "AccountId", ::GroupId = "GroupId")] + #[pallet::metadata(T::AccountId = "AccountId", T::GroupId = "GroupId", BalanceOf = "Balance")] pub enum Event { /// New deposit added to the specific mixer Deposit( - ::GroupId, - ::AccountId, - ScalarData, + /// Id of the tree + T::GroupId, + /// Account id of the sender + T::AccountId, + /// Deposit size + BalanceOf, + /// Number of leaves before insertion + u32, + /// Leaf data + Vec, ), /// Withdrawal from the specific mixer Withdraw( - ::GroupId, - ::AccountId, + /// Id of the tree + T::GroupId, + /// Account id of the sender + T::AccountId, + /// Account id of the recipient + T::AccountId, + /// Account id of the relayer + T::AccountId, + /// Merkle root ScalarData, ), } @@ -257,9 +271,21 @@ pub mod pallet { >::insert(mixer_id, tvl + deposit); // add elements to the mixer group's merkle tree and save the leaves T::Group::add_members(Self::account_id(), mixer_id.into(), data_points.clone())?; - mixer_info.leaves.extend(data_points); + + // number of leaves before the insertion of new leaves + let num_leaves_before = mixer_info.leaves.len() as u32; + let deposit_size = mixer_info.fixed_deposit_size; + mixer_info.leaves.extend(data_points.clone()); MixerGroups::::insert(mixer_id, mixer_info); + Self::deposit_event(Event::Deposit( + mixer_id, + sender, + deposit_size, + num_leaves_before, + data_points, + )); + Ok(().into()) } @@ -315,6 +341,14 @@ pub mod pallet { withdraw_proof.mixer_id.into(), withdraw_proof.nullifier_hash, )?; + + Self::deposit_event(Event::Withdraw( + withdraw_proof.mixer_id, + sender, + recipient, + relayer, + withdraw_proof.cached_root, + )); Ok(().into()) }