From 6372e4c8d5ebbd839b1478160a6eb174ac8a3da0 Mon Sep 17 00:00:00 2001 From: semaraugusto Date: Tue, 14 Mar 2023 15:36:44 -0300 Subject: [PATCH] removing all Is in anonimity-claims pallet. leads to errors on the VAnchorConfiguration pallet that requires two generic arguments --- pallets/anonymity-mining-claims/src/lib.rs | 145 +++++++++++---------- 1 file changed, 76 insertions(+), 69 deletions(-) diff --git a/pallets/anonymity-mining-claims/src/lib.rs b/pallets/anonymity-mining-claims/src/lib.rs index 4f20cbd116..fb957d8c8f 100644 --- a/pallets/anonymity-mining-claims/src/lib.rs +++ b/pallets/anonymity-mining-claims/src/lib.rs @@ -60,7 +60,7 @@ use pallet_vanchor::VAnchorConfigration; use sp_runtime::traits::Zero; use sp_std::{convert::TryInto, vec}; use webb_primitives::{ - linkable_tree::{LinkableTreeInspector, LinkableTreeInterface}, + linkable_tree::LinkableTreeInterface, traits::vanchor::{VAnchorInspector, VAnchorInterface}, // types::vanchor::{ExtData, ProofData, VAnchorMetadata}, // utils::compute_chain_id_type, @@ -70,13 +70,20 @@ use webb_primitives::{ }; /// Type alias for the orml_traits::MultiCurrency::Balance type -pub type BalanceOf = - <>::Currency as MultiCurrency<::AccountId>>::Balance; +// pub type BalanceOf = +// <>::Currency as MultiCurrency<::AccountId>>::Balance; +/// Type alias for the orml_traits::MultiCurrency::Balance type +pub type BalanceOf = + <::Currency as MultiCurrency<::AccountId>>::Balance; /// Type alias for the orml_traits::MultiCurrency::CurrencyId type // pub type CurrencyIdOf = <>::Currency as MultiCurrency< // ::AccountId, // >>::CurrencyId; -pub type CurrencyIdOf = <>::Currency as MultiCurrency< +// pub type CurrencyIdOf = <>::Currency as MultiCurrency< +// ::AccountId, +// >>::CurrencyId; + +pub type CurrencyIdOf = <::Currency as MultiCurrency< ::AccountId, >>::CurrencyId; @@ -89,7 +96,7 @@ pub mod pallet { #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] - pub struct Pallet(_); + pub struct Pallet(_); #[derive(Clone, Encode, Decode, Debug, Default, Eq, PartialEq, TypeInfo)] pub struct RewardProofData { @@ -109,11 +116,11 @@ pub mod pallet { #[pallet::config] /// The module configuration trait. - pub trait Config: - frame_system::Config + pallet_balances::Config + pallet_vanchor::Config + pub trait Config: + frame_system::Config + pallet_balances::Config + pallet_vanchor::Config { /// The overarching event type. - type RuntimeEvent: From> + type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Account Identifier from which the internal Pot is generated. @@ -131,24 +138,24 @@ pub mod pallet { /// Currency type for taking unspents type Currency: MultiCurrency; - /// VAnchor Interface - type VAnchor: VAnchorInterface> - + VAnchorInspector>; + /// VAnchor Interface + type VAnchor: VAnchorInterface> + + VAnchorInspector>; /// The verifier type ClaimsVerifier: ClaimsVerifierModule; /// AP asset id #[pallet::constant] - type AnonymityPointsAssetId: Get>; + type AnonymityPointsAssetId: Get>; /// Reward asset id #[pallet::constant] - type RewardAssetId: Get>; + type RewardAssetId: Get>; /// Native currency id #[pallet::constant] - type NativeCurrencyId: Get>; + type NativeCurrencyId: Get>; /// The origin which may forcibly reset parameters or otherwise alter /// privileged attributes. @@ -158,35 +165,35 @@ pub mod pallet { /// FIX: The map of trees to the maximum number of anchor edges they can have #[pallet::storage] #[pallet::getter(fn max_edges)] - pub type MaxEdges, I: 'static = ()> = StorageValue<_, u8, ValueQuery>; + pub type MaxEdges = StorageValue<_, u8, ValueQuery>; /// FIX: A map for each resourceID that has been registered in the pallet #[pallet::storage] #[pallet::getter(fn registered_resource_ids)] - pub type RegisteredResourceIds, I: 'static = ()> = + pub type RegisteredResourceIds = StorageMap<_, Blake2_128Concat, u32, ResourceId, ValueQuery>; /// Where to register the next resource id on the `RegisteredResourceIds` map #[pallet::storage] #[pallet::getter(fn next_resource_id_index)] - pub type NextResourceIdIndex, I: 'static = ()> = StorageValue<_, u32, ValueQuery>; + pub type NextResourceIdIndex = StorageValue<_, u32, ValueQuery>; /// The next unspent tree root index for a specific ResourceId #[pallet::storage] #[pallet::getter(fn next_unspent_root_index)] - pub(super) type NextUnspentRootIndex, I: 'static = ()> = + pub(super) type NextUnspentRootIndex = StorageMap<_, Blake2_128Concat, ResourceId, T::RootIndex, ValueQuery>; /// The next spent tree root index for a specific ResourceId #[pallet::storage] #[pallet::getter(fn next_spent_root_index)] - pub(super) type NextSpentRootIndex, I: 'static = ()> = + pub(super) type NextSpentRootIndex = StorageMap<_, Blake2_128Concat, ResourceId, T::RootIndex, ValueQuery>; // Map of ResourceId -> root index -> root value for unspent roots #[pallet::storage] #[pallet::getter(fn cached_unspent_roots)] - pub type CachedUnspentRoots, I: 'static = ()> = StorageDoubleMap< + pub type CachedUnspentRoots = StorageDoubleMap< _, Blake2_128Concat, ResourceId, @@ -199,7 +206,7 @@ pub mod pallet { // Map of ResourceId -> root index -> root value for spent roots #[pallet::storage] #[pallet::getter(fn cached_spent_roots)] - pub type CachedSpentRoots, I: 'static = ()> = StorageDoubleMap< + pub type CachedSpentRoots = StorageDoubleMap< _, Blake2_128Concat, ResourceId, @@ -212,37 +219,37 @@ pub mod pallet { /// The map of spent reward_nullfiier_hashes to prevent double claiming #[pallet::storage] #[pallet::getter(fn reward_nullifier_hashes)] - pub type RewardNullifierHashes, I: 'static = ()> = + pub type RewardNullifierHashes = StorageMap<_, Blake2_128Concat, T::Element, bool, ValueQuery>; #[pallet::genesis_config] - pub struct GenesisConfig, I: 'static = ()> { - pub phantom: (PhantomData, PhantomData), + pub struct GenesisConfig { + pub phantom: PhantomData, } #[cfg(feature = "std")] - impl, I: 'static> Default for GenesisConfig { + impl Default for GenesisConfig { fn default() -> Self { Self { phantom: Default::default() } } } #[pallet::genesis_build] - impl, I: 'static> GenesisBuild for GenesisConfig { + impl GenesisBuild for GenesisConfig { fn build(&self) {} } #[pallet::storage] #[pallet::getter(fn get_pool_weight)] - pub type PoolWeight, I: 'static = ()> = StorageValue<_, u64, ValueQuery>; + pub type PoolWeight = StorageValue<_, u64, ValueQuery>; #[pallet::storage] #[pallet::getter(fn get_tokens_sold)] - pub type TokensSold, I: 'static = ()> = StorageValue<_, u64, ValueQuery>; + pub type TokensSold = StorageValue<_, u64, ValueQuery>; #[pallet::event] #[pallet::generate_deposit(pub fn deposit_event)] - pub enum Event, I: 'static = ()> { + pub enum Event { UpdatedPoolWeight { pool_weight: u64 }, UpdatedTokensSold { tokens_sold: u64 }, AnchorEdgeAdded, @@ -250,7 +257,7 @@ pub mod pallet { } #[pallet::error] - pub enum Error { + pub enum Error { /// Error during hashing HashError, /// Invalid proof @@ -276,13 +283,13 @@ pub mod pallet { } #[pallet::call] - impl, I: 'static> Pallet { + impl Pallet { #[pallet::weight(0)] #[pallet::call_index(1)] pub fn claim( origin: OriginFor, recipient: T::AccountId, - amount: BalanceOf, + amount: BalanceOf, ) -> DispatchResultWithPostInfo { Ok(().into()) } @@ -291,25 +298,25 @@ pub mod pallet { pub type ProposalNonce = u32; pub type RootIndex = u32; -impl, I: 'static> Pallet { +impl Pallet { fn create( creator: Option, depth: u8, max_edges: u8, - asset: CurrencyIdOf, + asset: CurrencyIdOf, nonce: u32, ) -> Result { // Nonce should be greater than the proposal nonce in storage let id = T::VAnchor::create(creator.clone(), depth, max_edges as u32, asset, nonce.into())?; // set max_edges value - MaxEdges::::mutate(|i| *i = max_edges); + MaxEdges::::mutate(|i| *i = max_edges); Ok(id) } // Add rewardNullifier hash fn add_reward_nullifier_hash(nullifier_hash: T::Element) -> Result<(), DispatchError> { - RewardNullifierHashes::::insert(nullifier_hash, true); + RewardNullifierHashes::::insert(nullifier_hash, true); Ok(()) } /// Handle proof verification @@ -319,11 +326,11 @@ impl, I: 'static> Pallet { let max_edges = Self::max_edges(); ensure!( proof_data.spent_roots.len() == max_edges as usize, - Error::::InvalidSpentRootsLength + Error::::InvalidSpentRootsLength ); ensure!( proof_data.unspent_roots.len() == max_edges as usize, - Error::::InvalidUnspentRootsLength + Error::::InvalidUnspentRootsLength ); let mut bytes = Vec::new(); bytes.extend_from_slice(proof_data.rate.to_bytes()); @@ -343,7 +350,7 @@ impl, I: 'static> Pallet { } // Verify the zero-knowledge proof let res = T::ClaimsVerifier::verify(&bytes, &proof_data.proof, max_edges)?; - ensure!(res, Error::::InvalidProof); + ensure!(res, Error::::InvalidProof); Ok(()) } // / Update unspent root @@ -354,27 +361,27 @@ impl, I: 'static> Pallet { ) -> Result<(), DispatchError> { let max_edges = Self::max_edges(); let next_resource_id_index = Self::next_resource_id_index(); - ensure!(next_resource_id_index < (max_edges as u32), Error::::ResourceIdListIsFull); + ensure!(next_resource_id_index < (max_edges as u32), Error::::ResourceIdListIsFull); let registered_resource_ids = Self::get_registered_resource_ids(); ensure!( registered_resource_ids.contains(&resource_id) == false, - Error::::ResourceIdAlreadyInitialized + Error::::ResourceIdAlreadyInitialized ); let resource_id_index = Self::next_resource_id_index(); - ensure!((resource_id_index as u8) < max_edges, Error::::ResourceIdListIsFull); + ensure!((resource_id_index as u8) < max_edges, Error::::ResourceIdListIsFull); - RegisteredResourceIds::::insert(resource_id_index, resource_id); + RegisteredResourceIds::::insert(resource_id_index, resource_id); - NextResourceIdIndex::::mutate(|i| *i = i.saturating_add(One::one())); + NextResourceIdIndex::::mutate(|i| *i = i.saturating_add(One::one())); let root_index: T::RootIndex = Zero::zero(); // Add unspent root - CachedUnspentRoots::::insert(resource_id, root_index, unspent_root); + CachedUnspentRoots::::insert(resource_id, root_index, unspent_root); // Add spent root - CachedSpentRoots::::insert(resource_id, root_index, spent_root); + CachedSpentRoots::::insert(resource_id, root_index, spent_root); - NextUnspentRootIndex::::mutate(resource_id, |i| *i = One::one()); - NextSpentRootIndex::::mutate(resource_id, |i| *i = One::one()); + NextUnspentRootIndex::::mutate(resource_id, |i| *i = One::one()); + NextSpentRootIndex::::mutate(resource_id, |i| *i = One::one()); Ok(()) } @@ -384,13 +391,13 @@ impl, I: 'static> Pallet { resource_id: ResourceId, unspent_root: T::Element, ) -> Result<(), DispatchError> { - ensure!(Self::get_unspent_roots(resource_id).len() >= 1, Error::::InvalidResourceId); + ensure!(Self::get_unspent_roots(resource_id).len() >= 1, Error::::InvalidResourceId); // Update unspent root let root_index = Self::next_unspent_root_index(resource_id); - CachedUnspentRoots::::insert(resource_id, root_index, unspent_root); + CachedUnspentRoots::::insert(resource_id, root_index, unspent_root); - NextUnspentRootIndex::::mutate(resource_id, |i| { + NextUnspentRootIndex::::mutate(resource_id, |i| { *i = i.saturating_add(One::one()) % T::UnspentRootHistorySize::get() }); Ok(()) @@ -401,12 +408,12 @@ impl, I: 'static> Pallet { resource_id: ResourceId, spent_root: T::Element, ) -> Result<(), DispatchError> { - ensure!(Self::get_spent_roots(resource_id).len() >= 1, Error::::InvalidResourceId); + ensure!(Self::get_spent_roots(resource_id).len() >= 1, Error::::InvalidResourceId); // Update spent root let root_index = Self::next_spent_root_index(resource_id); - CachedSpentRoots::::insert(resource_id, root_index, spent_root); + CachedSpentRoots::::insert(resource_id, root_index, spent_root); - NextSpentRootIndex::::mutate(resource_id, |i| { + NextSpentRootIndex::::mutate(resource_id, |i| { *i = i.saturating_add(One::one()) % T::UnspentRootHistorySize::get() }); @@ -418,18 +425,18 @@ impl, I: 'static> Pallet { resource_ids: &Vec, unspent_roots: &Vec, ) -> Result<(), DispatchError> { - let max_edges = MaxEdges::::get(); + let max_edges = MaxEdges::::get(); // validate size of arrays provided - ensure!(unspent_roots.len() as u8 == max_edges, Error::::InvalidUnspentRootsLength); - ensure!(resource_ids.len() as u8 == max_edges, Error::::InvalidResourceIdLength); + ensure!(unspent_roots.len() as u8 == max_edges, Error::::InvalidUnspentRootsLength); + ensure!(resource_ids.len() as u8 == max_edges, Error::::InvalidResourceIdLength); // validate if unspent_roots are in resource_id root history for (resource_id, root) in resource_ids.iter().zip(unspent_roots) { let historical_roots = Self::get_unspent_roots(*resource_id); - ensure!(historical_roots.len() >= 1, Error::::InvalidResourceId); + ensure!(historical_roots.len() >= 1, Error::::InvalidResourceId); let is_known = historical_roots.contains(root); - ensure!(is_known, Error::::InvalidUnspentRoots); + ensure!(is_known, Error::::InvalidUnspentRoots); } Ok(()) } @@ -439,39 +446,39 @@ impl, I: 'static> Pallet { resource_ids: &Vec, spent_roots: &Vec, ) -> Result<(), DispatchError> { - let max_edges = MaxEdges::::get(); + let max_edges = MaxEdges::::get(); // validate size of arrays provided - ensure!(spent_roots.len() as u8 == max_edges, Error::::InvalidSpentRootsLength); - ensure!(resource_ids.len() as u8 == max_edges, Error::::InvalidResourceIdLength); + ensure!(spent_roots.len() as u8 == max_edges, Error::::InvalidSpentRootsLength); + ensure!(resource_ids.len() as u8 == max_edges, Error::::InvalidResourceIdLength); // validate if spent_roots are in resource_id root history for (resource_id, root) in resource_ids.iter().zip(spent_roots) { let historical_roots = Self::get_spent_roots(*resource_id); - ensure!(historical_roots.len() >= 1, Error::::InvalidResourceId); + ensure!(historical_roots.len() >= 1, Error::::InvalidResourceId); let is_known = historical_roots.contains(root); - ensure!(is_known, Error::::InvalidSpentRoots); + ensure!(is_known, Error::::InvalidSpentRoots); } Ok(()) } /// get unspent roots pub fn get_unspent_roots(resource_id: ResourceId) -> Vec { - CachedUnspentRoots::::iter_prefix_values(resource_id) + CachedUnspentRoots::::iter_prefix_values(resource_id) .into_iter() .collect::>() } /// get spent roots pub fn get_spent_roots(resource_id: ResourceId) -> Vec { - CachedSpentRoots::::iter_prefix_values(resource_id) + CachedSpentRoots::::iter_prefix_values(resource_id) .into_iter() .collect::>() } /// get registered resource ids pub fn get_registered_resource_ids() -> Vec { - RegisteredResourceIds::::iter_values().collect::>() + RegisteredResourceIds::::iter_values().collect::>() } /// Handle claiming of AP tokens @@ -481,9 +488,9 @@ impl, I: 'static> Pallet { resource_ids: Vec, ) -> DispatchResultWithPostInfo { // Check if nullifier has been spent - let is_spent = RewardNullifierHashes::::get(&reward_proof_data.reward_nullifier); + let is_spent = RewardNullifierHashes::::get(&reward_proof_data.reward_nullifier); - ensure!(!is_spent, Error::::RewardNullifierAlreadySpent); + ensure!(!is_spent, Error::::RewardNullifierAlreadySpent); // Handle proof verification Self::handle_proof_verification(&reward_proof_data)?;