diff --git a/pallets/contracts/src/benchmarking.rs b/pallets/contracts/src/benchmarking.rs index 0a9044739f..0553d160ed 100644 --- a/pallets/contracts/src/benchmarking.rs +++ b/pallets/contracts/src/benchmarking.rs @@ -15,7 +15,6 @@ use codec::Encode; use frame_benchmarking::{account, benchmarks}; -use frame_support::StorageMap; use frame_support::{storage::unhashed, traits::tokens::currency::Currency}; use frame_system::{Pallet as System, RawOrigin}; use pallet_contracts::benchmarking::code::body::DynInstr::{Counter, Regular}; @@ -71,7 +70,7 @@ where // Check if contact is already linked. match IdentityPallet::::get_identity(&contract) { Some(contract_did) => { - if contract_did != did && ParentDid::get(contract_did) != Some(did) { + if contract_did != did && ParentDid::::get(contract_did) != Some(did) { // Contract address already linked to a different identity. Err(IdentityError::::AlreadyLinked.into()) } else { diff --git a/pallets/contracts/src/lib.rs b/pallets/contracts/src/lib.rs index da892f334d..534e7aa96f 100644 --- a/pallets/contracts/src/lib.rs +++ b/pallets/contracts/src/lib.rs @@ -63,7 +63,6 @@ use frame_support::ensure; use frame_support::pallet_prelude::MaxEncodedLen; use frame_support::traits::Get; use frame_support::weights::Weight; -use frame_support::StorageMap as _; use frame_system::ensure_root; use frame_system::ensure_signed; #[cfg(feature = "std")] @@ -194,7 +193,7 @@ where // Check if contact is already linked. match IdentityPallet::::get_identity(&contract) { Some(contract_did) => { - if contract_did != did && ParentDid::get(contract_did) != Some(did) { + if contract_did != did && ParentDid::::get(contract_did) != Some(did) { // Contract address already linked to a different identity. Err(IdentityError::::AlreadyLinked.into()) } else { diff --git a/pallets/identity/src/auth.rs b/pallets/identity/src/auth.rs index a7d938c09f..f4dd6b902b 100644 --- a/pallets/identity/src/auth.rs +++ b/pallets/identity/src/auth.rs @@ -14,11 +14,11 @@ // along with this program. If not, see . use crate::{ - AuthorizationType, Authorizations, AuthorizationsGiven, Config, CurrentAuthId, Error, - KeyRecords, NumberOfGivenAuths, Pallet, RawEvent, + AuthorizationType, Authorizations, AuthorizationsGiven, Config, CurrentAuthId, Error, Event, + KeyRecords, NumberOfGivenAuths, Pallet, }; use frame_support::dispatch::DispatchResult; -use frame_support::{ensure, StorageDoubleMap, StorageMap, StorageValue}; +use frame_support::ensure; use frame_system::ensure_signed; use polymesh_primitives::{ Authorization, AuthorizationData, AuthorizationError, IdentityId, Signatory, @@ -56,15 +56,15 @@ impl Pallet { authorization_data: AuthorizationData, expiry: Option, ) -> Result { - let number_of_given_auths = NumberOfGivenAuths::get(from); + let number_of_given_auths = NumberOfGivenAuths::::get(from); ensure!( number_of_given_auths < T::MaxGivenAuths::get(), Error::::ExceededNumberOfGivenAuths ); - NumberOfGivenAuths::insert(from, number_of_given_auths.saturating_add(1)); + NumberOfGivenAuths::::insert(from, number_of_given_auths.saturating_add(1)); let new_auth_id = Self::current_auth_id().saturating_add(1); - CurrentAuthId::put(new_auth_id); + CurrentAuthId::::put(new_auth_id); let auth = Authorization { authorization_data: authorization_data.clone(), @@ -74,11 +74,11 @@ impl Pallet { count: 50, }; - >::insert(target.clone(), new_auth_id, auth); - >::insert(from, new_auth_id, target.clone()); + Authorizations::::insert(target.clone(), new_auth_id, auth); + AuthorizationsGiven::::insert(from, new_auth_id, target.clone()); // This event is split in order to help the event harvesters. - Self::deposit_event(RawEvent::AuthorizationAdded( + Self::deposit_event(Event::AuthorizationAdded( from, target.as_identity().cloned(), target.as_account().cloned(), @@ -97,7 +97,7 @@ impl Pallet { auth_id: u64, ) -> DispatchResult { let sender = ensure_signed(origin)?; - let from_did = if >::contains_key(&sender) { + let from_did = if KeyRecords::::contains_key(&sender) { // If the sender is linked to an identity, ensure that it has relevant permissions Some(pallet_permissions::Pallet::::ensure_call_permissions(&sender)?.primary_did) } else { @@ -122,17 +122,17 @@ impl Pallet { authorizer: &IdentityId, revoked: bool, ) { - >::remove(target, auth_id); - >::remove(authorizer, auth_id); - NumberOfGivenAuths::mutate(authorizer, |number_of_given_auths| { + Authorizations::::remove(target, auth_id); + AuthorizationsGiven::::remove(authorizer, auth_id); + NumberOfGivenAuths::::mutate(authorizer, |number_of_given_auths| { *number_of_given_auths = number_of_given_auths.saturating_sub(1); }); let id = target.as_identity().cloned(); let acc = target.as_account().cloned(); let event = if revoked { - RawEvent::AuthorizationRevoked + Event::AuthorizationRevoked } else { - RawEvent::AuthorizationRejected + Event::AuthorizationRejected }; Self::deposit_event(event(id, acc, auth_id)) } @@ -147,7 +147,7 @@ impl Pallet { auth_type: Option, ) -> Vec> { let now = >::get(); - let auths = >::iter_prefix_values(signatory) + let auths = Authorizations::::iter_prefix_values(signatory) .filter(|auth| allow_expired || auth.expiry.filter(|&e| e < now).is_none()); if let Some(auth_type) = auth_type { auths @@ -197,12 +197,12 @@ impl Pallet { accepter(auth.authorization_data.clone(), auth.authorized_by)?; // Remove authorization from storage and emit event. - >::remove(&target, auth_id); - >::remove(auth.authorized_by, auth_id); - NumberOfGivenAuths::mutate(auth.authorized_by, |number_of_given_auths| { + Authorizations::::remove(&target, auth_id); + AuthorizationsGiven::::remove(auth.authorized_by, auth_id); + NumberOfGivenAuths::::mutate(auth.authorized_by, |number_of_given_auths| { *number_of_given_auths = number_of_given_auths.saturating_sub(1); }); - Self::deposit_event(RawEvent::AuthorizationConsumed( + Self::deposit_event(Event::AuthorizationConsumed( target.as_identity().cloned(), target.as_account().cloned(), auth_id, diff --git a/pallets/identity/src/claims.rs b/pallets/identity/src/claims.rs index 302a38f494..a245990ebd 100644 --- a/pallets/identity/src/claims.rs +++ b/pallets/identity/src/claims.rs @@ -15,11 +15,11 @@ use crate::{ Claim1stKey, Claim2ndKey, Claims, Config, CustomClaimIdSequence, CustomClaims, - CustomClaimsInverse, DidRecords, Error, Event, Pallet, ParentDid, RawEvent, + CustomClaimsInverse, DidRecords, Error, Event, Pallet, ParentDid, }; use frame_support::{ dispatch::{DispatchError, DispatchResult}, - ensure, StorageDoubleMap, StorageMap, StorageValue, + ensure, }; use frame_system::ensure_root; use pallet_base::{ensure_string_limited, try_next_pre}; @@ -203,7 +203,7 @@ impl Pallet { // we will initialize the `parent_claims` iterator. if first_call { first_call = false; - parent_claims = ParentDid::get(did).map(|parent_did| { + parent_claims = ParentDid::::get(did).map(|parent_did| { Self::fetch_base_claims(parent_did, ClaimType::CustomerDueDiligence) }); } @@ -239,7 +239,7 @@ impl Pallet { target: IdentityId, claim_type: ClaimType, ) -> impl Iterator + 'a { - Claims::iter_prefix_values(Claim1stKey { target, claim_type }) + Claims::::iter_prefix_values(Claim1stKey { target, claim_type }) } /// It fetches an specific `claim_type` claim type for target identity `id`, which was issued @@ -252,7 +252,7 @@ impl Pallet { ) -> Option { let pk = Claim1stKey { target, claim_type }; let sk = Claim2ndKey { issuer, scope }; - Claims::get(&pk, &sk) + Claims::::get(&pk, &sk) } /// It adds a new claim without any previous security check. @@ -265,7 +265,7 @@ impl Pallet { let inner_scope = claim.as_scope().cloned(); if let ClaimType::Custom(id) = claim.claim_type() { ensure!( - CustomClaims::contains_key(id), + CustomClaims::::contains_key(id), Error::::CustomClaimTypeDoesNotExist ); } @@ -296,8 +296,8 @@ impl Pallet { claim, }; - Claims::insert(&pk, &sk, id_claim.clone()); - Self::deposit_event(RawEvent::ClaimAdded(target, id_claim)); + Claims::::insert(&pk, &sk, id_claim.clone()); + Self::deposit_event(Event::ClaimAdded(target, id_claim)); } /// Returns claim keys. @@ -336,9 +336,9 @@ impl Pallet { ) -> DispatchResult { let (pk, sk) = Self::get_claim_keys(target, claim_type, issuer, scope); // Remove the claim. - let claim = Claims::take(&pk, &sk).ok_or(Error::::ClaimDoesNotExist)?; + let claim = Claims::::take(&pk, &sk).ok_or(Error::::ClaimDoesNotExist)?; // Emit claim revoked event. - Self::deposit_event(RawEvent::ClaimRevoked(target, claim)); + Self::deposit_event(Event::ClaimRevoked(target, claim)); Ok(()) } @@ -422,7 +422,7 @@ impl Pallet { ); T::CddServiceProviders::disable_member(cdd, expiry, Some(disable_from))?; - Self::deposit_event(RawEvent::CddClaimsInvalidated(cdd, disable_from)); + Self::deposit_event(Event::CddClaimsInvalidated(cdd, disable_from)); Ok(()) } @@ -459,13 +459,13 @@ impl Pallet { fn unsafe_register_custom_claim_type(ty: Vec) -> Result { ensure_string_limited::(&ty)?; ensure!( - !CustomClaimsInverse::contains_key(&ty), + !CustomClaimsInverse::::contains_key(&ty), Error::::CustomClaimTypeAlreadyExists ); - let id = CustomClaimIdSequence::try_mutate(try_next_pre::)?; - CustomClaimsInverse::insert(&ty, id); - CustomClaims::insert(id, ty); + let id = CustomClaimIdSequence::::try_mutate(try_next_pre::)?; + CustomClaimsInverse::::insert(&ty, id); + CustomClaims::::insert(id, ty); Ok(id) } diff --git a/pallets/identity/src/keys.rs b/pallets/identity/src/keys.rs index d8b9fbb357..e58cea684a 100644 --- a/pallets/identity/src/keys.rs +++ b/pallets/identity/src/keys.rs @@ -15,16 +15,14 @@ use crate::{ types, AccountKeyRefCount, ChildDid, Claim, Config, CurrentAuthId, DidKeys, DidRecords, Error, - IsDidFrozen, KeyAssetPermissions, KeyExtrinsicPermissions, KeyPortfolioPermissions, KeyRecords, - MultiPurposeNonce, OffChainAuthorizationNonce, OutdatedAuthorizations, Pallet, ParentDid, - PermissionedCallOriginData, RawEvent, RpcDidRecords, + Event, IsDidFrozen, KeyAssetPermissions, KeyExtrinsicPermissions, KeyPortfolioPermissions, + KeyRecords, MultiPurposeNonce, OffChainAuthorizationNonce, OutdatedAuthorizations, Pallet, + ParentDid, PermissionedCallOriginData, RpcDidRecords, }; use codec::{Decode, Encode as _}; use frame_support::dispatch::DispatchResult; +use frame_support::ensure; use frame_support::traits::{Currency as _, Get as _}; -use frame_support::{ - ensure, IterableStorageDoubleMap, StorageDoubleMap, StorageMap as _, StorageValue as _, -}; use frame_system::ensure_signed; use pallet_base::{ensure_custom_length_ok, ensure_custom_string_limited}; use pallet_permissions::{AccountCallPermissionsData, CheckAccountCallPermissions}; @@ -69,7 +67,10 @@ impl Pallet { } pub fn ensure_no_parent(id: IdentityId) -> DispatchResult { - ensure!(!ParentDid::contains_key(id), Error::::IsChildIdentity); + ensure!( + !ParentDid::::contains_key(id), + Error::::IsChildIdentity + ); Ok(()) } @@ -240,7 +241,7 @@ impl Pallet { /// This function applies the change if `can_add_key_record` returns `true`. /// Otherwise, it does nothing. pub fn add_key_record(key: &T::AccountId, record: KeyRecord) { - if Self::can_add_key_record(key) { + if !KeyRecords::::contains_key(key) { // `key` is not yet linked to any identity, so no constraints. KeyRecords::::insert(key, &record); // For primary/secondary keys add to `DidKeys`. @@ -375,11 +376,11 @@ impl Pallet { DidRecords::::insert(target_did, DidRecord::new(new_primary_key.clone())); let removed_keys = vec![new_primary_key.clone()]; - Self::deposit_event(RawEvent::SecondaryKeysRemoved(target_did, removed_keys)); + Self::deposit_event(Event::SecondaryKeysRemoved(target_did, removed_keys)); } else { Self::add_key_record(&new_primary_key, key_record); } - Self::deposit_event(RawEvent::PrimaryKeyUpdated( + Self::deposit_event(Event::PrimaryKeyUpdated( target_did, old_primary_key.clone(), new_primary_key, @@ -391,7 +392,7 @@ impl Pallet { Self::set_key_permissions(&old_primary_key, &perms); let sk = SecondaryKey::new(old_primary_key, perms); - Self::deposit_event(RawEvent::SecondaryKeysAdded(target_did, vec![sk])); + Self::deposit_event(Event::SecondaryKeysAdded(target_did, vec![sk])); } else { Self::remove_key_record(&old_primary_key, Some(target_did)); } @@ -444,7 +445,7 @@ impl Pallet { // Update secondary key's permissions. Self::set_key_permissions(&key, &permissions); - Self::deposit_event(RawEvent::SecondaryKeyPermissionsUpdated( + Self::deposit_event(Event::SecondaryKeyPermissionsUpdated( did, key.clone(), old_perms, @@ -471,7 +472,7 @@ impl Pallet { // Unlink the secondary account key. Self::remove_key_record(&secondary_key, Some(parent_did)); - Self::deposit_event(RawEvent::SecondaryKeysRemoved( + Self::deposit_event(Event::SecondaryKeysRemoved( parent_did, vec![secondary_key.clone()], )); @@ -492,12 +493,12 @@ impl Pallet { let child_did = Self::make_did()?; // Create a new identity record Self::add_key_record(&key, KeyRecord::PrimaryKey(child_did)); - Self::deposit_event(RawEvent::DidCreated(child_did, key.clone(), vec![])); + Self::deposit_event(Event::DidCreated(child_did, key.clone(), vec![])); // Link new identity to parent identity. - ParentDid::insert(child_did, parent_did); - ChildDid::insert(parent_did, child_did, true); + ParentDid::::insert(child_did, parent_did); + ChildDid::::insert(parent_did, child_did, true); - Self::deposit_event(RawEvent::ChildDidCreated(parent_did, child_did, key)); + Self::deposit_event(Event::ChildDidCreated(parent_did, child_did, key)); Ok(()) } @@ -557,18 +558,20 @@ impl Pallet { } // Update that identity's offchain authorization nonce. - OffChainAuthorizationNonce::mutate(parent_did, |nonce| *nonce = authorization.nonce + 1); + OffChainAuthorizationNonce::::mutate(parent_did, |nonce| { + *nonce = authorization.nonce + 1 + }); for (key, child_did) in children { // Create a new identity record and link the primary key. Self::add_key_record(&key, KeyRecord::PrimaryKey(child_did)); - Self::deposit_event(RawEvent::DidCreated(child_did, key.clone(), vec![])); + Self::deposit_event(Event::DidCreated(child_did, key.clone(), vec![])); // Link new identity to parent identity. - ParentDid::insert(child_did, parent_did); - ChildDid::insert(parent_did, child_did, true); + ParentDid::::insert(child_did, parent_did); + ChildDid::::insert(parent_did, child_did, true); - Self::deposit_event(RawEvent::ChildDidCreated(parent_did, child_did, key)); + Self::deposit_event(Event::ChildDidCreated(parent_did, child_did, key)); } Ok(()) @@ -582,7 +585,7 @@ impl Pallet { let (_, caller_did) = Self::ensure_primary_key(origin)?; // Make sure that `child_did` is a child and get their parent identity. - let parent_did = ParentDid::get(child_did).ok_or(Error::::NoParentIdentity)?; + let parent_did = ParentDid::::get(child_did).ok_or(Error::::NoParentIdentity)?; // Only the parent or child can unlink `child_did` from their parent. if caller_did != parent_did && caller_did != child_did { @@ -590,12 +593,10 @@ impl Pallet { } // Unlink child identity from parent identity. - ParentDid::remove(child_did); - ChildDid::remove(parent_did, child_did); + ParentDid::::remove(child_did); + ChildDid::::remove(parent_did, child_did); - Self::deposit_event(RawEvent::ChildDidUnlinked( - caller_did, parent_did, child_did, - )); + Self::deposit_event(Event::ChildDidUnlinked(caller_did, parent_did, child_did)); Ok(()) } @@ -623,14 +624,14 @@ impl Pallet { Self::set_outdated_autorizations(Signatory::Account(key.clone())); } - Self::deposit_event(RawEvent::SecondaryKeysRemoved(did, keys)); + Self::deposit_event(Event::SecondaryKeysRemoved(did, keys)); Ok(()) } /// Sets all authorizations with auth_id less or equal to the current id as invalid for the /// `signatory_account`. fn set_outdated_autorizations(signatory_account: Signatory) { - let current_auth_id = CurrentAuthId::get(); + let current_auth_id = CurrentAuthId::::get(); OutdatedAuthorizations::::insert(signatory_account, current_auth_id); } @@ -699,9 +700,9 @@ impl Pallet { } // Update that identity's offchain authorization nonce. - OffChainAuthorizationNonce::mutate(did, |nonce| *nonce = authorization.nonce + 1); + OffChainAuthorizationNonce::::mutate(did, |nonce| *nonce = authorization.nonce + 1); - Self::deposit_event(RawEvent::SecondaryKeysAdded(did, additional_keys_si)); + Self::deposit_event(Event::SecondaryKeysAdded(did, additional_keys_si)); Ok(()) } @@ -738,7 +739,7 @@ impl Pallet { Self::set_key_permissions(&key, &permissions); let sk = SecondaryKey { key, permissions }; - Self::deposit_event(RawEvent::SecondaryKeysAdded(target_did, vec![sk])); + Self::deposit_event(Event::SecondaryKeysAdded(target_did, vec![sk])); } pub(crate) fn leave_identity(origin: T::RuntimeOrigin) -> DispatchResult { @@ -753,7 +754,7 @@ impl Pallet { // Unlink secondary key from the identity. Self::remove_key_record(&key, Some(did)); - Self::deposit_event(RawEvent::SecondaryKeyLeftIdentity(did, key)); + Self::deposit_event(Event::SecondaryKeyLeftIdentity(did, key)); Ok(()) } @@ -767,11 +768,11 @@ impl Pallet { ) -> DispatchResult { let (_, did) = Self::ensure_primary_key(origin)?; if freeze { - IsDidFrozen::insert(&did, true); - Self::deposit_event(RawEvent::SecondaryKeysFrozen(did)) + IsDidFrozen::::insert(&did, true); + Self::deposit_event(Event::SecondaryKeysFrozen(did)) } else { - IsDidFrozen::remove(&did); - Self::deposit_event(RawEvent::SecondaryKeysUnfrozen(did)); + IsDidFrozen::::remove(&did); + Self::deposit_event(Event::SecondaryKeysUnfrozen(did)); } Ok(()) } @@ -780,7 +781,7 @@ impl Pallet { fn make_did() -> Result { let nonce = Self::multi_purpose_nonce() + 7u64; // Even if this transaction fails, nonce should be increased for added unpredictability of dids - MultiPurposeNonce::put(&nonce); + MultiPurposeNonce::::put(&nonce); // TODO: Look into getting randomness from `pallet_babe`. // NB: We can't get the current block's hash while processing @@ -826,7 +827,7 @@ impl Pallet { // Give `InitialPOLYX` to the primary key for testing. let _ = T::Balances::deposit_creating(&sender, T::InitialPOLYX::get()); - Self::deposit_event(RawEvent::DidCreated(did, sender, secondary_keys.clone())); + Self::deposit_event(Event::DidCreated(did, sender, secondary_keys.clone())); // Add join identity authorizations for secondary keys. for sk in secondary_keys { @@ -884,7 +885,7 @@ impl Pallet { Self::set_key_permissions(&sk.key, &sk.permissions); } - Self::deposit_event(RawEvent::DidCreated(id, primary_key, secondary_keys)); + Self::deposit_event(Event::DidCreated(id, primary_key, secondary_keys)); } /// Ensure the `key` is a secondary key of the identity `did`. diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs index 71a60b09ff..9b7e103328 100644 --- a/pallets/identity/src/lib.rs +++ b/pallets/identity/src/lib.rs @@ -100,7 +100,7 @@ use frame_support::dispatch::{ use frame_support::traits::{ ChangeMembers, Currency, EnsureOrigin, Get, GetCallMetadata, InitializeMembers, }; -use frame_support::{decl_error, decl_event, decl_module, decl_storage, Parameter}; +use frame_support::Parameter; use frame_system::ensure_root; use polymesh_primitives::identity::limits::{ MAX_ASSETS, MAX_EXTRINSICS, MAX_PALLETS, MAX_PORTFOLIOS, @@ -208,85 +208,99 @@ pub trait WeightInfo { } } -/// The module's configuration trait. -pub trait Config: - frame_system::Config + pallet_timestamp::Config + pallet_base::Config + pallet_permissions::Config -{ - /// The overarching event type. - type RuntimeEvent: From> + Into<::RuntimeEvent>; - /// An extrinsic call. - type Proposal: Parameter - + Dispatchable< - RuntimeOrigin = ::RuntimeOrigin, - PostInfo = PostDispatchInfo, - > + GetCallMetadata - + GetDispatchInfo - + From>; - /// Group module - type CddServiceProviders: GroupTrait; - /// Balances module - type Balances: Currency; - /// Used to check and update CDD - type CddHandler: CddAndFeeDetails::RuntimeCall>; - - type Public: IdentifyAccount; - type OffChainSignature: Verify + Member + Decode + Encode + TypeInfo; - type ProtocolFee: ChargeProtocolFee; - - /// Origin for Governance Committee voting majority origin. - type GCVotingMajorityOrigin: EnsureOrigin; - - /// Weight information for extrinsics in the identity pallet. - type WeightInfo: WeightInfo; - - /// Identity functions - type IdentityFn: IdentityFnTrait; - - /// A type for identity-mapping the `Origin` type. Used by the scheduler. - type SchedulerOrigin: From>; - - /// POLYX given to primary keys of all new Identities - type InitialPOLYX: Get<>::Balance>; - - /// Maximum number of authorizations an identity can give. - type MaxGivenAuths: Get; -} - -decl_event!( - pub enum Event - where - AccountId = ::AccountId, - Moment = ::Moment, +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + /// Configure the pallet by specifying the parameters and types on which it depends. + #[pallet::config] + pub trait Config: + frame_system::Config + + pallet_timestamp::Config + + pallet_base::Config + + pallet_permissions::Config { + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// An extrinsic call. + type Proposal: Parameter + + Dispatchable< + RuntimeOrigin = ::RuntimeOrigin, + PostInfo = PostDispatchInfo, + > + GetCallMetadata + + GetDispatchInfo + + From>; + /// Group module + type CddServiceProviders: GroupTrait; + /// Balances module + type Balances: Currency; + /// Used to check and update CDD + type CddHandler: CddAndFeeDetails< + Self::AccountId, + ::RuntimeCall, + >; + + type Public: IdentifyAccount; + type OffChainSignature: Verify + Member + Decode + Encode + TypeInfo; + type ProtocolFee: ChargeProtocolFee; + + /// Origin for Governance Committee voting majority origin. + type GCVotingMajorityOrigin: EnsureOrigin; + + /// Weight information for extrinsics in the identity pallet. + type WeightInfo: WeightInfo; + + /// Identity functions + type IdentityFn: IdentityFnTrait; + + /// A type for identity-mapping the `Origin` type. Used by the scheduler. + type SchedulerOrigin: From>; + + /// POLYX given to primary keys of all new Identities + #[pallet::constant] + type InitialPOLYX: Get<>::Balance>; + + /// Maximum number of authorizations an identity can give. + #[pallet::constant] + type MaxGivenAuths: Get; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { /// Identity created. /// /// (DID, primary key, secondary keys) - DidCreated(IdentityId, AccountId, Vec>), + DidCreated(IdentityId, T::AccountId, Vec>), /// Secondary keys added to identity. /// /// (DID, new keys) - SecondaryKeysAdded(IdentityId, Vec>), + SecondaryKeysAdded(IdentityId, Vec>), /// Secondary keys removed from identity. /// /// (DID, the keys that got removed) - SecondaryKeysRemoved(IdentityId, Vec), + SecondaryKeysRemoved(IdentityId, Vec), /// A secondary key left their identity. /// /// (DID, secondary key) - SecondaryKeyLeftIdentity(IdentityId, AccountId), + SecondaryKeyLeftIdentity(IdentityId, T::AccountId), /// Secondary key permissions updated. /// /// (DID, updated secondary key, previous permissions, new permissions) - SecondaryKeyPermissionsUpdated(IdentityId, AccountId, Permissions, Permissions), + SecondaryKeyPermissionsUpdated(IdentityId, T::AccountId, Permissions, Permissions), /// Primary key of identity changed. /// /// (DID, old primary key account ID, new ID) - PrimaryKeyUpdated(IdentityId, AccountId, AccountId), + PrimaryKeyUpdated(IdentityId, T::AccountId, T::AccountId), /// Claim added to identity. /// @@ -309,31 +323,31 @@ decl_event!( AuthorizationAdded( IdentityId, Option, - Option, + Option, u64, - AuthorizationData, - Option, + AuthorizationData, + Option, ), /// Authorization revoked by the authorizer. /// /// (authorized_identity, authorized_key, auth_id) - AuthorizationRevoked(Option, Option, u64), + AuthorizationRevoked(Option, Option, u64), /// Authorization rejected by the user who was authorized. /// /// (authorized_identity, authorized_key, auth_id) - AuthorizationRejected(Option, Option, u64), + AuthorizationRejected(Option, Option, u64), /// Authorization consumed. /// /// (authorized_identity, authorized_key, auth_id) - AuthorizationConsumed(Option, Option, u64), + AuthorizationConsumed(Option, Option, u64), /// Accepting Authorization retry limit reached. /// /// (authorized_identity, authorized_key, auth_id) - AuthorizationRetryLimitReached(Option, Option, u64), + AuthorizationRetryLimitReached(Option, Option, u64), /// CDD requirement for updating primary key changed. /// @@ -344,7 +358,7 @@ decl_event!( /// `Moment`. /// /// (CDD provider DID, disable from date) - CddClaimsInvalidated(IdentityId, Moment), + CddClaimsInvalidated(IdentityId, T::Moment), /// All Secondary keys of the identity ID are frozen. /// @@ -364,176 +378,269 @@ decl_event!( /// Child identity created. /// /// (Parent DID, Child DID, primary key) - ChildDidCreated(IdentityId, IdentityId, AccountId), + ChildDidCreated(IdentityId, IdentityId, T::AccountId), /// Child identity unlinked from parent identity. /// /// (Caller DID, Parent DID, Child DID) ChildDidUnlinked(IdentityId, IdentityId, IdentityId), } -); - -decl_storage! { - trait Store for Pallet as Identity { - - /// DID -> identity info - pub DidRecords get(fn did_records): - map hasher(identity) IdentityId => Option>; - - /// DID -> bool that indicates if secondary keys are frozen. - pub IsDidFrozen get(fn is_did_frozen): map hasher(identity) IdentityId => bool; - - /// It stores the current gas fee payer for the current transaction - pub CurrentPayer: Option; - - /// (Target ID, claim type) (issuer,scope) -> Associated claims - pub Claims: double_map hasher(twox_64_concat) Claim1stKey, hasher(blake2_128_concat) Claim2ndKey => Option; - /// CustomClaimTypeId -> String constant - pub CustomClaims: map hasher(twox_64_concat) CustomClaimTypeId => Option>; - /// String constant -> CustomClaimTypeId - pub CustomClaimsInverse: map hasher(blake2_128_concat) Vec => Option; - /// The next `CustomClaimTypeId`. - pub CustomClaimIdSequence get(fn custom_claim_id_seq): CustomClaimTypeId; - - /// Map from AccountId to `KeyRecord` that holds the key's type and identity. - pub KeyRecords get(fn key_records): - map hasher(twox_64_concat) T::AccountId => Option>; - - /// A secondary key's extrinsic permissions. - pub KeyExtrinsicPermissions get(fn key_extrinsic_permissions): - map hasher(twox_64_concat) T::AccountId => Option; - - /// A secondary key's asset permissions. - pub KeyAssetPermissions get(fn key_asset_permissions): - map hasher(twox_64_concat) T::AccountId => Option; - - /// A secondary key's portfolio permissions. - pub KeyPortfolioPermissions get(fn key_portfolio_permissions): - map hasher(twox_64_concat) T::AccountId => Option; - - /// A reverse double map to allow finding all keys for an identity. - pub DidKeys get(fn did_keys): - double_map hasher(identity) IdentityId, hasher(twox_64_concat) T::AccountId => bool; - - /// Nonce to ensure unique actions. starts from 1. - pub MultiPurposeNonce get(fn multi_purpose_nonce) build(|_| 1u64): u64; - - /// Authorization nonce per Identity. Initially is 0. - pub OffChainAuthorizationNonce get(fn offchain_authorization_nonce): map hasher(identity) IdentityId => AuthorizationNonce; - /// All authorizations that an identity/key has - pub Authorizations get(fn authorizations): double_map hasher(blake2_128_concat) - Signatory, hasher(twox_64_concat) u64 => Option>; - - /// All authorizations that an identity has given. (Authorizer, auth_id -> authorized) - pub AuthorizationsGiven: double_map hasher(identity) - IdentityId, hasher(twox_64_concat) u64 => Signatory; - - /// A config flag that, if set, instructs an authorization from a CDD provider in order to - /// change the primary key of an identity. - pub CddAuthForPrimaryKeyRotation get(fn cdd_auth_for_primary_key_rotation): bool; - - /// Storage version. - StorageVersion get(fn storage_version) build(|_| Version::new(7)): Version; - - /// How many "strong" references to the account key. - /// - /// Strong references will block a key from leaving it's identity. - /// - /// Pallets using "strong" references to account keys: - /// * Relayer: For `user_key` and `paying_key` - /// - pub AccountKeyRefCount get(fn account_key_ref_count): - map hasher(blake2_128_concat) T::AccountId => u64; - - /// Parent identity if the DID is a child Identity. - pub ParentDid get(fn parent_did): - map hasher(identity) IdentityId => Option; - - /// All child identities of a parent (i.e ParentDID, ChildDID, true) - pub ChildDid get(fn child_did): - double_map hasher(identity) IdentityId, hasher(identity) IdentityId => bool; - - /// Track the number of authorizations given by each identity. - pub NumberOfGivenAuths get(fn number_of_given_auths): - map hasher(identity) IdentityId => u32; + #[pallet::pallet] + pub struct Pallet(_); + + /// DID -> identity info + #[pallet::storage] + #[pallet::getter(fn did_records)] + pub type DidRecords = + StorageMap<_, Identity, IdentityId, DidRecord, OptionQuery>; + + /// DID -> bool that indicates if secondary keys are frozen. + #[pallet::storage] + #[pallet::getter(fn is_did_frozen)] + pub type IsDidFrozen = StorageMap<_, Identity, IdentityId, bool, ValueQuery>; + + /// It stores the current gas fee payer for the current transaction. + #[pallet::storage] + pub type CurrentPayer = StorageValue<_, T::AccountId, OptionQuery>; + + /// (Target ID, claim type) (issuer,scope) -> Associated claims + #[pallet::storage] + #[pallet::unbounded] + pub type Claims = StorageDoubleMap< + _, + Twox64Concat, + Claim1stKey, + Blake2_128Concat, + Claim2ndKey, + IdentityClaim, + OptionQuery, + >; + + /// CusotmClaimTypeId -> String constant + #[pallet::storage] + #[pallet::unbounded] + pub type CustomClaims = + StorageMap<_, Twox64Concat, CustomClaimTypeId, Vec, OptionQuery>; + + /// String constant -> CustomClaimTypeId + #[pallet::storage] + #[pallet::unbounded] + pub type CustomClaimsInverse = + StorageMap<_, Blake2_128Concat, Vec, CustomClaimTypeId, OptionQuery>; + + /// The next `CustomClaimTypeId`. + #[pallet::storage] + #[pallet::getter(fn custom_claim_id_seq)] + pub type CustomClaimIdSequence = StorageValue<_, CustomClaimTypeId, ValueQuery>; + + /// Map from AccountId to `KeyRecord` that holds the key's type and identity. + #[pallet::storage] + #[pallet::getter(fn key_records)] + pub type KeyRecords = + StorageMap<_, Twox64Concat, T::AccountId, KeyRecord, OptionQuery>; + + /// A secondary key's extrinsic permissions. + #[pallet::storage] + #[pallet::unbounded] + #[pallet::getter(fn key_extrinsic_permissions)] + pub type KeyExtrinsicPermissions = + StorageMap<_, Twox64Concat, T::AccountId, ExtrinsicPermissions, OptionQuery>; + + /// A secondary key's asset permissions. + #[pallet::storage] + #[pallet::unbounded] + #[pallet::getter(fn key_asset_permissions)] + pub type KeyAssetPermissions = + StorageMap<_, Twox64Concat, T::AccountId, AssetPermissions, OptionQuery>; + + /// A secondary key's portfolio permissions. + #[pallet::storage] + #[pallet::unbounded] + #[pallet::getter(fn key_portfolio_permissions)] + pub type KeyPortfolioPermissions = + StorageMap<_, Twox64Concat, T::AccountId, PortfolioPermissions, OptionQuery>; + + /// A reverse double map to allow finding all keys for an identity. + #[pallet::storage] + #[pallet::getter(fn did_keys)] + pub type DidKeys = + StorageDoubleMap<_, Identity, IdentityId, Twox64Concat, T::AccountId, bool, ValueQuery>; + + /// Nonce to ensure unique actions. starts from 1. + #[pallet::storage] + #[pallet::getter(fn multi_purpose_nonce)] + pub type MultiPurposeNonce = StorageValue<_, u64, ValueQuery>; + + /// Authorization nonce per Identity. Initially is 0. + #[pallet::storage] + #[pallet::getter(fn offchain_authorization_nonce)] + pub type OffChainAuthorizationNonce = + StorageMap<_, Identity, IdentityId, AuthorizationNonce, ValueQuery>; + + /// All authorizations that an identity/key has + #[pallet::storage] + #[pallet::unbounded] + #[pallet::getter(fn authorizations)] + pub type Authorizations = StorageDoubleMap< + _, + Blake2_128Concat, + Signatory, + Twox64Concat, + u64, + Authorization, + OptionQuery, + >; + + /// All authorizations that an identity has given. (Authorizer, auth_id -> authorized) + #[pallet::storage] + pub type AuthorizationsGiven = StorageDoubleMap< + _, + Identity, + IdentityId, + Twox64Concat, + u64, + Signatory, + ValueQuery, + >; + + /// A config flag that, if set, instructs an authorization from a CDD provider in order to + /// change the primary key of an identity. + #[pallet::storage] + #[pallet::getter(fn cdd_auth_for_primary_key_rotation)] + pub type CddAuthForPrimaryKeyRotation = StorageValue<_, bool, ValueQuery>; + + /// Storage version. + #[pallet::storage] + pub type StorageVersion = StorageValue<_, Version, ValueQuery>; + + /// How many "strong" references to the account key. + /// + /// Strong references will block a key from leaving it's identity. + /// + /// Pallets using "strong" references to account keys: + /// * Relayer: For `user_key` and `paying_key` + /// + #[pallet::storage] + #[pallet::getter(fn account_key_ref_count)] + pub type AccountKeyRefCount = + StorageMap<_, Blake2_128Concat, T::AccountId, u64, ValueQuery>; + + /// Parent identity if the DID is a child Identity. + #[pallet::storage] + #[pallet::getter(fn parent_did)] + pub type ParentDid = StorageMap<_, Identity, IdentityId, IdentityId, OptionQuery>; + + /// All child identities of a parent (i.e ParentDID, ChildDID, true) + #[pallet::storage] + #[pallet::getter(fn child_did)] + pub type ChildDid = + StorageDoubleMap<_, Identity, IdentityId, Identity, IdentityId, bool, ValueQuery>; + + /// Track the number of authorizations given by each identity. + #[pallet::storage] + #[pallet::getter(fn number_of_given_auths)] + pub type NumberOfGivenAuths = StorageMap<_, Identity, IdentityId, u32, ValueQuery>; + + /// Tracks all authorizations that must be deleted + #[pallet::storage] + #[pallet::getter(fn outdated_authorizations)] + pub type OutdatedAuthorizations = + StorageMap<_, Blake2_128Concat, Signatory, u64, OptionQuery>; + + /// Controls the authorization id. + #[pallet::storage] + #[pallet::getter(fn current_auth_id)] + pub type CurrentAuthId = StorageValue<_, u64, ValueQuery>; + + /// GenesisConfig for the identity pallet. + #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] + pub struct GenesisConfig { + /// The initial identities to create. + pub identities: Vec>, + /// Secondary keys of identities at genesis. `identities` have to be initialized first. + pub secondary_keys: Vec<(T::AccountId, IdentityId)>, + } - /// Tracks all authorizations that must be deleted - pub OutdatedAuthorizations get(fn outdated_authorizations): - map hasher(blake2_128_concat) Signatory => Option; + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + MultiPurposeNonce::::put(1); + StorageVersion::::put(Version::new(7)); - /// Controls the authorization id. - pub CurrentAuthId get(fn current_auth_id): u64 - } - add_extra_genesis { - // Identities at genesis. - config(identities): Vec>; - // Secondary keys of identities at genesis. `identities` have to be initialised. - config(secondary_keys): Vec<(T::AccountId, IdentityId)>; - build(|config: &GenesisConfig| { polymesh_primitives::SYSTEMATIC_ISSUERS .iter() .copied() .for_each(>::register_systematic_id); // Add CDD claims to Treasury & BRR - let sys_issuers_with_cdd = [SystematicIssuers::Treasury, SystematicIssuers::BlockRewardReserve, SystematicIssuers::Settlement]; - let id_with_cdd = sys_issuers_with_cdd.iter() + let sys_issuers_with_cdd = [ + SystematicIssuers::Treasury, + SystematicIssuers::BlockRewardReserve, + SystematicIssuers::Settlement, + ]; + let id_with_cdd = sys_issuers_with_cdd + .iter() .map(|iss| iss.as_id()) .collect::>(); - >::add_systematic_cdd_claims(&id_with_cdd, SystematicIssuers::CDDProvider); + Pallet::::add_systematic_cdd_claims(&id_with_cdd, SystematicIssuers::CDDProvider); // Other - for gen_id in &config.identities { + for gen_id in &self.identities { let cdd_claim = Claim::CustomerDueDiligence(CddId::default()); // Direct storage change for registering the DID and providing the claim - >::ensure_no_id_record(gen_id.did).unwrap(); - ::mutate(|n| *n += 1_u64); - let expiry = gen_id.cdd_claim_expiry.iter().map(|m| T::Moment::from(*m as u32)).next(); + Pallet::::ensure_no_id_record(gen_id.did).unwrap(); + MultiPurposeNonce::::mutate(|n| *n += 1_u64); + let expiry = gen_id + .cdd_claim_expiry + .iter() + .map(|m| T::Moment::from(*m as u32)) + .next(); if let Some(primary_key) = &gen_id.primary_key { - >::do_register_id(primary_key.clone(), gen_id.did, gen_id.secondary_keys.clone()); + >::do_register_id( + primary_key.clone(), + gen_id.did, + gen_id.secondary_keys.clone(), + ); } for issuer in &gen_id.issuers { - >::unverified_add_claim_with_scope(gen_id.did, cdd_claim.clone(), None, *issuer, expiry); + >::unverified_add_claim_with_scope( + gen_id.did, + cdd_claim.clone(), + None, + *issuer, + expiry, + ); } } - for &(ref secondary_account_id, did) in &config.secondary_keys { + for &(ref secondary_account_id, did) in &self.secondary_keys { // Direct storage change for attaching some secondary keys to identities - >::ensure_id_record_exists(did).unwrap(); + Pallet::::ensure_id_record_exists(did).unwrap(); assert!( >::can_add_key_record(secondary_account_id), "Secondary key already linked" ); - ::mutate(|n| *n += 1_u64); + MultiPurposeNonce::::mutate(|n| *n += 1_u64); let sk = SecondaryKey::from_account_id(secondary_account_id.clone()); - >::add_key_record(secondary_account_id, KeyRecord::SecondaryKey(did)); - >::set_key_permissions(&sk.key, &sk.permissions); - >::deposit_event(RawEvent::SecondaryKeysAdded(did, vec![sk])); + Pallet::::add_key_record(secondary_account_id, KeyRecord::SecondaryKey(did)); + Pallet::::set_key_permissions(&sk.key, &sk.permissions); + Pallet::::deposit_event(Event::SecondaryKeysAdded(did, vec![sk])); } - }); + } } -} - -decl_module! { - /// The module declaration. - pub struct Module for enum Call where origin: T::RuntimeOrigin { - - type Error = Error; - - const MaxGivenAuths: u32 = T::MaxGivenAuths::get(); - - // Initializing events - // this is needed only if you are using events in your module - fn deposit_event() = default; + #[pallet::hooks] + impl Hooks> for Pallet { fn on_runtime_upgrade() -> Weight { Weight::zero() } + } - const InitialPOLYX: >::Balance = T::InitialPOLYX::get(); - + #[pallet::call] + impl Pallet { /// Register `target_account` with a new Identity. /// /// # Failure @@ -542,27 +649,31 @@ decl_module! { /// - `target_account` (primary key of the new Identity) can be linked to just one and only /// one identity. /// - External secondary keys can be linked to just one identity. - #[weight = ::WeightInfo::cdd_register_did(secondary_keys.len() as u32)] + #[pallet::weight(::WeightInfo::cdd_register_did(secondary_keys.len() as u32))] + #[pallet::call_index(0)] pub fn cdd_register_did( - origin, + origin: OriginFor, target_account: T::AccountId, - secondary_keys: Vec> - ) { + secondary_keys: Vec>, + ) -> DispatchResult { Self::base_cdd_register_did(origin, target_account, secondary_keys)?; + Ok(()) } /// Invalidates any claim generated by `cdd` from `disable_from` timestamps. /// /// You can also define an expiration time, /// which will invalidate all claims generated by that `cdd` and remove it as CDD member group. - #[weight = (::WeightInfo::invalidate_cdd_claims(), Operational, Pays::Yes)] + #[pallet::weight((::WeightInfo::invalidate_cdd_claims(), Operational, Pays::Yes))] + #[pallet::call_index(1)] pub fn invalidate_cdd_claims( - origin, + origin: OriginFor, cdd: IdentityId, disable_from: T::Moment, expiry: Option, - ) { + ) -> DispatchResult { Self::base_invalidate_cdd_claims(origin, cdd, disable_from, expiry)?; + Ok(()) } /// Call this with the new primary key. By invoking this method, caller accepts authorization @@ -578,8 +689,13 @@ decl_module! { /// # Arguments /// * `owner_auth_id` Authorization from the owner who initiated the change /// * `cdd_auth_id` Authorization from a CDD service provider - #[weight = ::WeightInfo::accept_primary_key()] - pub fn accept_primary_key(origin, rotation_auth_id: u64, optional_cdd_auth_id: Option) -> DispatchResult { + #[pallet::weight(::WeightInfo::accept_primary_key())] + #[pallet::call_index(2)] + pub fn accept_primary_key( + origin: OriginFor, + rotation_auth_id: u64, + optional_cdd_auth_id: Option, + ) -> DispatchResult { Self::accept_primary_key_rotation(origin, rotation_auth_id, optional_cdd_auth_id) } @@ -588,31 +704,39 @@ decl_module! { /// /// # Arguments /// * `auth_required` CDD Authorization required or not - #[weight = (::WeightInfo::change_cdd_requirement_for_mk_rotation(), Operational, Pays::Yes)] - pub fn change_cdd_requirement_for_mk_rotation(origin, auth_required: bool) { + #[pallet::weight((::WeightInfo::change_cdd_requirement_for_mk_rotation(), Operational, Pays::Yes))] + #[pallet::call_index(3)] + pub fn change_cdd_requirement_for_mk_rotation( + origin: OriginFor, + auth_required: bool, + ) -> DispatchResult { ensure_root(origin)?; - CddAuthForPrimaryKeyRotation::put(auth_required); - Self::deposit_event(RawEvent::CddRequirementForPrimaryKeyUpdated(auth_required)); + CddAuthForPrimaryKeyRotation::::put(auth_required); + Self::deposit_event(Event::CddRequirementForPrimaryKeyUpdated(auth_required)); + Ok(()) } /// Join an identity as a secondary key. - #[weight = ::WeightInfo::join_identity_as_key()] - pub fn join_identity_as_key(origin, auth_id: u64) -> DispatchResult { + #[pallet::weight(::WeightInfo::join_identity_as_key())] + #[pallet::call_index(4)] + pub fn join_identity_as_key(origin: OriginFor, auth_id: u64) -> DispatchResult { Self::join_identity(origin, auth_id) } /// Leave the secondary key's identity. - #[weight = ::WeightInfo::leave_identity_as_key()] - pub fn leave_identity_as_key(origin) -> DispatchResult { + #[pallet::weight(::WeightInfo::leave_identity_as_key())] + #[pallet::call_index(5)] + pub fn leave_identity_as_key(origin: OriginFor) -> DispatchResult { Self::leave_identity(origin) } /// Adds a new claim record or edits an existing one. /// /// Only called by did_issuer's secondary key. - #[weight = ::WeightInfo::add_claim()] + #[pallet::weight(::WeightInfo::add_claim())] + #[pallet::call_index(6)] pub fn add_claim( - origin, + origin: OriginFor, target: IdentityId, claim: Claim, expiry: Option, @@ -620,7 +744,9 @@ decl_module! { let issuer = Self::ensure_signed_and_validate_claim_target(origin, target)?; match &claim { - Claim::CustomerDueDiligence(..) => Self::base_add_cdd_claim(target, claim, issuer, expiry), + Claim::CustomerDueDiligence(..) => { + Self::base_add_cdd_claim(target, claim, issuer, expiry) + } _ => { Self::ensure_custom_scopes_limited(&claim)?; T::ProtocolFee::charge_fee(ProtocolOp::IdentityAddClaim)?; @@ -630,8 +756,13 @@ decl_module! { } /// Marks the specified claim as revoked. - #[weight = (::WeightInfo::revoke_claim(), revoke_claim_class(claim.claim_type()))] - pub fn revoke_claim(origin, target: IdentityId, claim: Claim) -> DispatchResult { + #[pallet::weight((::WeightInfo::revoke_claim(), revoke_claim_class(claim.claim_type())))] + #[pallet::call_index(7)] + pub fn revoke_claim( + origin: OriginFor, + target: IdentityId, + claim: Claim, + ) -> DispatchResult { let issuer = Self::ensure_perms(origin)?; let claim_type = claim.claim_type(); let scope = claim.as_scope().cloned(); @@ -642,54 +773,60 @@ decl_module! { /// /// # Errors /// - #[weight = ::WeightInfo::freeze_secondary_keys()] - pub fn freeze_secondary_keys(origin) -> DispatchResult { + #[pallet::weight(::WeightInfo::freeze_secondary_keys())] + #[pallet::call_index(8)] + pub fn freeze_secondary_keys(origin: OriginFor) -> DispatchResult { Self::set_frozen_secondary_key_flags(origin, true) } /// Re-enables all secondary keys of the caller's identity. - #[weight = ::WeightInfo::unfreeze_secondary_keys()] - pub fn unfreeze_secondary_keys(origin) -> DispatchResult { + #[pallet::weight(::WeightInfo::unfreeze_secondary_keys())] + #[pallet::call_index(9)] + pub fn unfreeze_secondary_keys(origin: OriginFor) -> DispatchResult { Self::set_frozen_secondary_key_flags(origin, false) } // Manage generic authorizations /// Adds an authorization. - #[weight = ::WeightInfo::add_authorization_full::(&data)] + #[pallet::weight(::WeightInfo::add_authorization_full::(&data))] + #[pallet::call_index(10)] pub fn add_authorization( - origin, + origin: OriginFor, target: Signatory, data: AuthorizationData, - expiry: Option - ) { + expiry: Option, + ) -> DispatchResult { Self::base_add_authorization(origin, target, data, expiry)?; + Ok(()) } /// Removes an authorization. - /// _auth_issuer_pays determines whether the issuer of the authorisation pays the transaction fee - #[weight = ::WeightInfo::remove_authorization()] + /// `_auth_issuer_pays` determines whether the issuer of the authorisation pays the transaction fee + #[pallet::weight(::WeightInfo::remove_authorization())] + #[pallet::call_index(11)] pub fn remove_authorization( - origin, + origin: OriginFor, target: Signatory, auth_id: u64, _auth_issuer_pays: bool, - ) { + ) -> DispatchResult { Self::base_remove_authorization(origin, target, auth_id)?; + Ok(()) } /// Assuming this is executed by the GC voting majority, adds a new cdd claim record. - #[weight = (::WeightInfo::add_claim(), Operational, Pays::Yes)] - pub fn gc_add_cdd_claim( - origin, - target: IdentityId, - ) { + #[pallet::weight((::WeightInfo::add_claim(), Operational, Pays::Yes))] + #[pallet::call_index(12)] + pub fn gc_add_cdd_claim(origin: OriginFor, target: IdentityId) -> DispatchResult { T::GCVotingMajorityOrigin::ensure_origin(origin)?; Self::add_systematic_cdd_claims(&[target], SystematicIssuers::Committee); + Ok(()) } /// Assuming this is executed by the GC voting majority, removes an existing cdd claim record. - #[weight = (::WeightInfo::add_claim(), Operational, Pays::Yes)] - pub fn gc_revoke_cdd_claim(origin, target: IdentityId) -> DispatchResult { + #[pallet::weight((::WeightInfo::add_claim(), Operational, Pays::Yes))] + #[pallet::call_index(13)] + pub fn gc_revoke_cdd_claim(origin: OriginFor, target: IdentityId) -> DispatchResult { T::GCVotingMajorityOrigin::ensure_origin(origin)?; Self::base_revoke_claim(target, ClaimType::CustomerDueDiligence, GC_DID, None) } @@ -698,8 +835,14 @@ decl_module! { /// `claim_type`, and `scope`. /// /// Please note that `origin` must be the issuer of the target claim. - #[weight = (::WeightInfo::revoke_claim_by_index(), revoke_claim_class(*claim_type))] - pub fn revoke_claim_by_index(origin, target: IdentityId, claim_type: ClaimType, scope: Option) -> DispatchResult { + #[pallet::weight((::WeightInfo::revoke_claim_by_index(), revoke_claim_class(*claim_type)))] + #[pallet::call_index(14)] + pub fn revoke_claim_by_index( + origin: OriginFor, + target: IdentityId, + claim_type: ClaimType, + scope: Option, + ) -> DispatchResult { let issuer = Self::ensure_perms(origin)?; Self::base_revoke_claim(target, claim_type, issuer, scope) } @@ -718,8 +861,13 @@ decl_module! { /// # Arguments /// * `owner_auth_id` Authorization from the owner who initiated the change /// * `cdd_auth_id` Authorization from a CDD service provider - #[weight = ::WeightInfo::rotate_primary_key_to_secondary()] - pub fn rotate_primary_key_to_secondary(origin, auth_id:u64, optional_cdd_auth_id: Option) -> DispatchResult { + #[pallet::weight(::WeightInfo::rotate_primary_key_to_secondary())] + #[pallet::call_index(15)] + pub fn rotate_primary_key_to_secondary( + origin: OriginFor, + auth_id: u64, + optional_cdd_auth_id: Option, + ) -> DispatchResult { Self::base_rotate_primary_key_to_secondary(origin, auth_id, optional_cdd_auth_id) } @@ -736,21 +884,29 @@ decl_module! { /// # Errors /// - Can only called by primary key owner. /// - Keys should be able to linked to any identity. - #[weight = ::WeightInfo::add_secondary_keys_full::(&additional_keys)] + #[pallet::weight(::WeightInfo::add_secondary_keys_full::(&additional_keys))] + #[pallet::call_index(16)] pub fn add_secondary_keys_with_authorization( - origin, + origin: OriginFor, additional_keys: Vec>, - expires_at: T::Moment - ) { + expires_at: T::Moment, + ) -> DispatchResult { Self::base_add_secondary_keys_with_authorization(origin, additional_keys, expires_at)?; + Ok(()) } /// Sets permissions for an specific `target_key` key. /// /// Only the primary key of an identity is able to set secondary key permissions. - #[weight = ::WeightInfo::set_secondary_key_permissions_full(&perms)] - pub fn set_secondary_key_permissions(origin, key: T::AccountId, perms: Permissions) { + #[pallet::weight(::WeightInfo::set_secondary_key_permissions_full(&perms))] + #[pallet::call_index(17)] + pub fn set_secondary_key_permissions( + origin: OriginFor, + key: T::AccountId, + perms: Permissions, + ) -> DispatchResult { Self::base_set_secondary_key_permissions(origin, key, perms)?; + Ok(()) } /// Removes specified secondary keys of a DID if present. @@ -758,9 +914,14 @@ decl_module! { /// # Errors /// /// The extrinsic can only called by primary key owner. - #[weight = ::WeightInfo::remove_secondary_keys(keys_to_remove.len() as u32)] - pub fn remove_secondary_keys(origin, keys_to_remove: Vec) { + #[pallet::weight(::WeightInfo::remove_secondary_keys(keys_to_remove.len() as u32))] + #[pallet::call_index(18)] + pub fn remove_secondary_keys( + origin: OriginFor, + keys_to_remove: Vec, + ) -> DispatchResult { Self::base_remove_secondary_keys(origin, keys_to_remove)?; + Ok(()) } /// Register custom claim type. @@ -769,9 +930,11 @@ decl_module! { /// * `CustomClaimTypeAlreadyExists` The type that is being registered already exists. /// * `CounterOverflow` CustomClaimTypeId has overflowed. /// * `TooLong` The type being registered is too lang. - #[weight = ::WeightInfo::register_custom_claim_type(ty.len() as u32)] - pub fn register_custom_claim_type(origin, ty: Vec) { + #[pallet::weight(::WeightInfo::register_custom_claim_type(ty.len() as u32))] + #[pallet::call_index(19)] + pub fn register_custom_claim_type(origin: OriginFor, ty: Vec) -> DispatchResult { Self::base_register_custom_claim_type(origin, ty)?; + Ok(()) } /// Register `target_account` with a new Identity and issue a CDD claim with a blank CddId @@ -782,16 +945,19 @@ decl_module! { /// - `target_account` (primary key of the new Identity) can be linked to just one and only /// one identity. /// - External secondary keys can be linked to just one identity. - #[weight = ::WeightInfo::cdd_register_did(secondary_keys.len() as u32).saturating_add(::WeightInfo::add_claim())] + #[pallet::weight(::WeightInfo::cdd_register_did(secondary_keys.len() as u32).saturating_add(::WeightInfo::add_claim()))] + #[pallet::call_index(20)] pub fn cdd_register_did_with_cdd( - origin, + origin: OriginFor, target_account: T::AccountId, secondary_keys: Vec>, - expiry: Option - ) { - let (cdd_did, target_did) = Self::base_cdd_register_did(origin, target_account, secondary_keys)?; + expiry: Option, + ) -> DispatchResult { + let (cdd_did, target_did) = + Self::base_cdd_register_did(origin, target_account, secondary_keys)?; let cdd_claim = Claim::CustomerDueDiligence(CddId::default()); Self::base_add_claim(target_did, cdd_claim, cdd_did, expiry)?; + Ok(()) } /// Create a child identity and make the `secondary_key` it's primary key. @@ -806,9 +972,14 @@ decl_module! { /// - `NotASigner` the `secondary_key` is not a secondary key of the caller's identity. /// - `AccountKeyIsBeingUsed` the `secondary_key` can't be unlinked from it's current identity. /// - `IsChildIdentity` the caller's identity is already a child identity and can't create child identities. - #[weight = ::WeightInfo::create_child_identity()] - pub fn create_child_identity(origin, secondary_key: T::AccountId) { + #[pallet::weight(::WeightInfo::create_child_identity())] + #[pallet::call_index(21)] + pub fn create_child_identity( + origin: OriginFor, + secondary_key: T::AccountId, + ) -> DispatchResult { Self::base_create_child_identity(origin, secondary_key)?; + Ok(()) } /// Create a child identities. @@ -826,13 +997,15 @@ decl_module! { /// - `AlreadyLinked` one of the keys is already linked to an identity. /// - `DuplicateKey` one of the keys is included multiple times. /// - `IsChildIdentity` the caller's identity is already a child identity and can't create child identities. - #[weight = ::WeightInfo::create_child_identities(child_keys.len() as u32)] + #[pallet::weight(::WeightInfo::create_child_identities(child_keys.len() as u32))] + #[pallet::call_index(22)] pub fn create_child_identities( - origin, + origin: OriginFor, child_keys: Vec>, - expires_at: T::Moment - ) { + expires_at: T::Moment, + ) -> DispatchResult { Self::base_create_child_identities(origin, child_keys, expires_at)?; + Ok(()) } /// Unlink a child identity from it's parent identity. @@ -846,15 +1019,19 @@ decl_module! { /// - `KeyNotAllowed` only the primary key of either the parent or child identity can unlink the identities. /// - `NoParentIdentity` the identity `child_did` doesn't have a parent identity. /// - `NotParentOrChildIdentity` the caller's identity isn't the parent or child identity. - #[weight = ::WeightInfo::unlink_child_identity()] - pub fn unlink_child_identity(origin, child_did: IdentityId) { + #[pallet::weight(::WeightInfo::unlink_child_identity())] + #[pallet::call_index(23)] + pub fn unlink_child_identity( + origin: OriginFor, + child_did: IdentityId, + ) -> DispatchResult { Self::base_unlink_child_identity(origin, child_did)?; + Ok(()) } } -} -decl_error! { - pub enum Error for Pallet { + #[pallet::error] + pub enum Error { /// One secondary or primary key can only belong to one DID AlreadyLinked, /// Caller is missing an identity. @@ -958,15 +1135,15 @@ impl IdentityFnTrait for Pallet { /// Fetches the fee payer from the context. fn current_payer() -> Option { - >::get() + CurrentPayer::::get() } /// Sets the fee payer in the context. fn set_current_payer(payer: Option) { if let Some(payer) = payer { - >::put(payer); + CurrentPayer::::put(payer); } else { - >::kill(); + CurrentPayer::::kill(); } } diff --git a/pallets/identity/src/types.rs b/pallets/identity/src/types.rs index e2d4481858..5d34e0334b 100644 --- a/pallets/identity/src/types.rs +++ b/pallets/identity/src/types.rs @@ -1,6 +1,6 @@ //! Runtime API definition for Identity module. -use codec::{Decode, Encode}; +use codec::{Decode, Encode, MaxEncodedLen}; use polymesh_primitives::{ClaimType, IdentityId, Permissions, Scope, SecondaryKey}; use scale_info::TypeInfo; use sp_std::{prelude::*, vec::Vec}; @@ -30,7 +30,7 @@ pub enum RpcDidRecords { IdNotFound, } -#[derive(Encode, Decode, PartialEq, Eq)] +#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Eq)] #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] pub enum DidStatus { Unknown, @@ -63,7 +63,18 @@ pub struct PermissionedCallOriginData { pub secondary_key: Option>, } -#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, Eq, Debug, PartialOrd, Ord)] +#[derive( + Encode, + Decode, + MaxEncodedLen, + TypeInfo, + Clone, + PartialEq, + Eq, + Debug, + PartialOrd, + Ord +)] pub struct Claim1stKey { pub target: IdentityId, pub claim_type: ClaimType, diff --git a/pallets/multisig/src/benchmarking.rs b/pallets/multisig/src/benchmarking.rs index 5c38e4c745..9fefcb8ec3 100644 --- a/pallets/multisig/src/benchmarking.rs +++ b/pallets/multisig/src/benchmarking.rs @@ -14,7 +14,6 @@ // along with this program. If not, see . use frame_benchmarking::benchmarks; -use frame_support::storage::StorageDoubleMap; use frame_system::RawOrigin; use pallet_identity::benchmarking::{User, UserBuilder}; diff --git a/pallets/runtime/common/src/cdd_check.rs b/pallets/runtime/common/src/cdd_check.rs index b32fc936cf..bb74a0910a 100644 --- a/pallets/runtime/common/src/cdd_check.rs +++ b/pallets/runtime/common/src/cdd_check.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use pallet_identity::{Config as IdentityConfig, Module as Identity}; +use pallet_identity::{Config as IdentityConfig, Pallet as Identity}; use polymesh_primitives::traits::CheckCdd; use polymesh_primitives::IdentityId; diff --git a/pallets/runtime/common/src/fee_details.rs b/pallets/runtime/common/src/fee_details.rs index 9b025da338..0a5ac6cc49 100644 --- a/pallets/runtime/common/src/fee_details.rs +++ b/pallets/runtime/common/src/fee_details.rs @@ -1,7 +1,7 @@ use codec::{Decode, Encode}; use core::convert::{TryFrom, TryInto}; use core::marker::PhantomData; -use pallet_identity::{Config as IdentityConfig, Context, Module as Identity}; +use pallet_identity::{Config as IdentityConfig, Context, Pallet as Identity}; use polymesh_primitives::{ traits::CddAndFeeDetails, AccountId, AuthorizationData, IdentityId, Signatory, TransactionError, }; @@ -150,7 +150,7 @@ where // in an existing identity that has a valid CDD. The auth should be valid. Ok(Call::Identity(pallet_identity::Call::remove_authorization { auth_id, - _auth_issuer_pays: true, + auth_issuer_pays: true, .. })) => is_auth_valid(caller, auth_id, CallType::RemoveAuthorization), // Call made by a user key to accept subsidy from a paying key. The auth should be valid. diff --git a/pallets/runtime/tests/src/contracts_test.rs b/pallets/runtime/tests/src/contracts_test.rs index dc87bd3bcf..508eb70e11 100644 --- a/pallets/runtime/tests/src/contracts_test.rs +++ b/pallets/runtime/tests/src/contracts_test.rs @@ -1,8 +1,6 @@ use codec::Encode; use frame_support::dispatch::{DispatchError, Weight}; -use frame_support::{ - assert_err_ignore_postinfo, assert_noop, assert_ok, assert_storage_noop, StorageMap, -}; +use frame_support::{assert_err_ignore_postinfo, assert_noop, assert_ok, assert_storage_noop}; use polymesh_contracts::{ Api, ApiCodeHash, ApiNextUpgrade, ChainVersion, ExtrinsicId, NextUpgrade, }; @@ -221,7 +219,7 @@ fn deploy_as_child_identity() { let contract_account_id = FrameContracts::contract_address(&alice.acc(), &hash, &[], &salt); let child_id = Identity::get_identity(&contract_account_id).unwrap(); - assert_eq!(ParentDid::get(child_id), Some(alice.did)); + assert_eq!(ParentDid::::get(child_id), Some(alice.did)); }) } diff --git a/pallets/runtime/tests/src/corporate_actions_test.rs b/pallets/runtime/tests/src/corporate_actions_test.rs index 4bb83c6e39..1ffb8c6133 100644 --- a/pallets/runtime/tests/src/corporate_actions_test.rs +++ b/pallets/runtime/tests/src/corporate_actions_test.rs @@ -9,7 +9,6 @@ use core::iter; use frame_support::{ assert_noop, assert_ok, dispatch::{DispatchError, DispatchResult}, - StorageDoubleMap, }; use pallet_asset::Assets; use pallet_corporate_actions::{ diff --git a/pallets/runtime/tests/src/fee_details.rs b/pallets/runtime/tests/src/fee_details.rs index c02a8d14ec..92214fd3aa 100644 --- a/pallets/runtime/tests/src/fee_details.rs +++ b/pallets/runtime/tests/src/fee_details.rs @@ -78,7 +78,7 @@ fn cdd_checks() { &RuntimeCall::Identity(identity::Call::remove_authorization { target: alice_signatory.clone(), auth_id: alice_auth_id, - _auth_issuer_pays: true + auth_issuer_pays: true }), &alice_account ), @@ -91,7 +91,7 @@ fn cdd_checks() { &RuntimeCall::Identity(identity::Call::remove_authorization { target: alice_signatory.clone(), auth_id: alice_auth_id, - _auth_issuer_pays: false + auth_issuer_pays: false }), &alice_account ), @@ -112,7 +112,7 @@ fn cdd_checks() { &RuntimeCall::Identity(identity::Call::remove_authorization { target: alice_signatory.clone(), auth_id: alice_auth_id, - _auth_issuer_pays: false + auth_issuer_pays: false }), &alice_account ), @@ -125,7 +125,7 @@ fn cdd_checks() { &RuntimeCall::Identity(identity::Call::remove_authorization { target: alice_signatory.clone(), auth_id: alice_auth_id, - _auth_issuer_pays: true + auth_issuer_pays: true }), &alice_account ), @@ -146,7 +146,7 @@ fn cdd_checks() { &RuntimeCall::Identity(identity::Call::remove_authorization { target: charlie_signatory.clone(), auth_id: charlie_auth_id, - _auth_issuer_pays: true + auth_issuer_pays: true }), &charlie_account ), @@ -159,7 +159,7 @@ fn cdd_checks() { &RuntimeCall::Identity(identity::Call::remove_authorization { target: charlie_signatory, auth_id: charlie_auth_id, - _auth_issuer_pays: false + auth_issuer_pays: false }), &charlie_account ), diff --git a/pallets/runtime/tests/src/identity_test.rs b/pallets/runtime/tests/src/identity_test.rs index 77faae877e..bd26ebacfe 100644 --- a/pallets/runtime/tests/src/identity_test.rs +++ b/pallets/runtime/tests/src/identity_test.rs @@ -13,13 +13,12 @@ use super::{ ExtBuilder, }; use codec::Encode; -use frame_support::{ - assert_noop, assert_ok, dispatch::DispatchResult, traits::Currency, StorageDoubleMap, - StorageMap, StorageValue, -}; +use frame_support::{assert_noop, assert_ok, dispatch::DispatchResult, traits::Currency}; use pallet_balances as balances; -use pallet_identity::{ChildDid, CustomClaimIdSequence, CustomClaims, CustomClaimsInverse}; -use pallet_identity::{Config as IdentityConfig, RawEvent}; +use pallet_identity::{ + ChildDid, CustomClaimIdSequence, CustomClaims, CustomClaimsInverse, ParentDid, +}; +use pallet_identity::{Config as IdentityConfig, Event}; use polymesh_primitives::asset::AssetId; use polymesh_primitives::{ constants::currency::POLY, @@ -43,7 +42,6 @@ type Asset = pallet_asset::Pallet; type Balances = balances::Pallet; type BaseError = pallet_base::Error; type Identity = pallet_identity::Pallet; -type ParentDid = pallet_identity::ParentDid; type MultiSig = pallet_multisig::Pallet; type System = frame_system::Pallet; type Timestamp = pallet_timestamp::Pallet; @@ -1964,14 +1962,14 @@ fn custom_claim_type_works() { let user = User::new(AccountKeyring::Alice); let register = |ty: &str| Identity::register_custom_claim_type(user.origin(), ty.into()); let seq_is = |num| { - assert_eq!(CustomClaimIdSequence::get().0, num); + assert_eq!(CustomClaimIdSequence::::get().0, num); }; let slot_has = |id, data: &str| { seq_is(id); let id = CustomClaimTypeId(id); let data = data.as_bytes().to_vec(); - assert_eq!(CustomClaims::get(id).as_ref(), Some(&data)); - assert_eq!(CustomClaimsInverse::get(data), Some(id)); + assert_eq!(CustomClaims::::get(id).as_ref(), Some(&data)); + assert_eq!(CustomClaimsInverse::::get(data), Some(id)); }; // Nothing so far. Generator (G) at 0. @@ -1998,7 +1996,7 @@ fn custom_claim_type_works() { slot_has(3, "foobar"); // Set G to max. Next registration fails. - CustomClaimIdSequence::put(CustomClaimTypeId(u32::MAX)); + CustomClaimIdSequence::::put(CustomClaimTypeId(u32::MAX)); assert_noop!(register("qux"), BaseError::CounterOverflow); }); } @@ -2043,7 +2041,7 @@ fn cdd_register_did_events() { let mut system_events = System::events(); assert_eq!( system_events.pop().unwrap().event, - super::storage::EventTest::Identity(RawEvent::AuthorizationAdded( + super::storage::EventTest::Identity(Event::AuthorizationAdded( alice_did, None, Some(AccountKeyring::Charlie.to_account_id()), @@ -2054,7 +2052,7 @@ fn cdd_register_did_events() { ); assert_eq!( system_events.pop().unwrap().event, - super::storage::EventTest::Identity(RawEvent::AuthorizationAdded( + super::storage::EventTest::Identity(Event::AuthorizationAdded( alice_did, None, Some(AccountKeyring::Dave.to_account_id()), @@ -2066,7 +2064,7 @@ fn cdd_register_did_events() { // Make sure a Did Created event was sent assert_eq!( system_events.pop().unwrap().event, - super::storage::EventTest::Identity(RawEvent::DidCreated( + super::storage::EventTest::Identity(Event::DidCreated( alice_did, alice_account_id, alice_secundary_keys.clone() @@ -2098,7 +2096,7 @@ fn do_child_identity_test() { let valid_cdd = |u: User| did_of(u).map(Identity::has_valid_cdd).unwrap_or_default(); let inc_acc_ref = |u: User| Identity::add_account_key_ref_count(&u.acc()); let rejoin_parent = |parent: User, child: User| { - ParentDid::insert(child.did, parent.did); + ParentDid::::insert(child.did, parent.did); }; // Create some secondary keys. @@ -2146,8 +2144,8 @@ fn do_child_identity_test() { // Ensure bob has a new identity. assert!(valid_cdd(bob)); assert_ne!(bob.did, alice.did); - assert_eq!(ParentDid::get(bob.did), Some(alice.did)); - assert_eq!(ChildDid::get(alice.did, bob.did), true); + assert_eq!(ParentDid::::get(bob.did), Some(alice.did)); + assert_eq!(ChildDid::::get(alice.did, bob.did), true); // Attach secondary key to child identity. let ferdie = User::new_with(bob.did, AccountKeyring::Ferdie); @@ -2211,8 +2209,8 @@ fn do_child_identity_test() { // Unlink child from parent again. exec_ok!(Identity::unlink_child_identity(bob.origin(), bob_did)); - assert_eq!(ParentDid::get(bob.did), None); - assert_eq!(ChildDid::get(alice.did, bob.did), false); + assert_eq!(ParentDid::::get(bob.did), None); + assert_eq!(ChildDid::::get(alice.did, bob.did), false); assert!(valid_cdd(bob)); @@ -2222,8 +2220,8 @@ fn do_child_identity_test() { let ferdie_did = did_of(ferdie).expect("Ferdie's new identity"); let ferdie = User::new_with(ferdie_did, AccountKeyring::Ferdie); assert!(valid_cdd(ferdie)); - assert_eq!(ParentDid::get(ferdie.did), Some(bob.did)); - assert_eq!(ChildDid::get(bob.did, ferdie.did), true); + assert_eq!(ParentDid::::get(ferdie.did), Some(bob.did)); + assert_eq!(ChildDid::::get(bob.did, ferdie.did), true); } #[test] diff --git a/pallets/runtime/tests/src/relayer_test.rs b/pallets/runtime/tests/src/relayer_test.rs index e706bff5f2..f5fe8f7a56 100644 --- a/pallets/runtime/tests/src/relayer_test.rs +++ b/pallets/runtime/tests/src/relayer_test.rs @@ -5,7 +5,6 @@ use super::{ use frame_support::{ assert_noop, assert_ok, dispatch::{DispatchInfo, Pays, PostDispatchInfo, Weight}, - StorageMap, }; use frame_system; use pallet_relayer::Subsidy; diff --git a/pallets/runtime/tests/src/staking/mock.rs b/pallets/runtime/tests/src/staking/mock.rs index 372b62c8bf..42bdbb402f 100644 --- a/pallets/runtime/tests/src/staking/mock.rs +++ b/pallets/runtime/tests/src/staking/mock.rs @@ -26,9 +26,7 @@ use frame_support::traits::{ KeyOwnerProofSystem, OnUnbalanced, OneSessionHandler, }; use frame_support::weights::constants::RocksDbWeight; -use frame_support::{ - assert_ok, ord_parameter_types, parameter_types, StorageDoubleMap, StorageMap, -}; +use frame_support::{assert_ok, ord_parameter_types, parameter_types}; use frame_system::{EnsureRoot, EnsureSignedBy}; use sp_core::H256; use sp_runtime::curve::PiecewiseLinear; diff --git a/pallets/runtime/tests/src/staking_extra_tests.rs b/pallets/runtime/tests/src/staking_extra_tests.rs index 0ac1731631..4fad1dde4e 100644 --- a/pallets/runtime/tests/src/staking_extra_tests.rs +++ b/pallets/runtime/tests/src/staking_extra_tests.rs @@ -1,4 +1,4 @@ -use frame_support::{assert_ok, StorageMap}; +use frame_support::assert_ok; use sp_keyring::AccountKeyring; use polymesh_primitives::{AuthorizationData, Permissions}; diff --git a/pallets/runtime/tests/src/storage.rs b/pallets/runtime/tests/src/storage.rs index 6f414a16ec..d9c749e424 100644 --- a/pallets/runtime/tests/src/storage.rs +++ b/pallets/runtime/tests/src/storage.rs @@ -12,7 +12,7 @@ use frame_support::traits::{ use frame_support::weights::{ RuntimeDbWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }; -use frame_support::{assert_ok, parameter_types, BoundedBTreeSet, StorageDoubleMap}; +use frame_support::{assert_ok, parameter_types, BoundedBTreeSet}; use smallvec::smallvec; use sp_core::crypto::{key_types, Pair as PairTrait}; use sp_core::sr25519::Pair; diff --git a/pallets/staking/src/benchmarking.rs b/pallets/staking/src/benchmarking.rs index 6cb756c73c..6e01352dfa 100644 --- a/pallets/staking/src/benchmarking.rs +++ b/pallets/staking/src/benchmarking.rs @@ -50,8 +50,6 @@ type MaxNominators = <::BenchmarkingConfig as BenchmarkingConfig // Polymesh change // ----------------------------------------------------------------- -use frame_support::StorageDoubleMap; - use pallet_identity::benchmarking::{User, UserBuilder}; use polymesh_primitives::identity_claim::ClaimType; use polymesh_primitives::{IdentityId, Permissions}; @@ -1010,7 +1008,7 @@ benchmarks! { target: nominator.0.did(), claim_type: ClaimType::CustomerDueDiligence }; - let _ = pallet_identity::Claims::clear_prefix(claim_first, 1, None); + let _ = pallet_identity::Claims::::clear_prefix(claim_first, 1, None); } let nominators: Vec = nominators.iter().map(|x| x.0.account()).collect(); diff --git a/primitives/src/identity.rs b/primitives/src/identity.rs index 9d3f8dff03..d06d98ac89 100644 --- a/primitives/src/identity.rs +++ b/primitives/src/identity.rs @@ -17,7 +17,7 @@ #[cfg(feature = "std")] use sp_runtime::{Deserialize, Serialize}; -use codec::{Decode, Encode}; +use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_core::H512; @@ -58,7 +58,7 @@ pub mod limits { /// Used to check if an identity exists and lookup its primary key. /// /// Asset Identities don't have a primary key. -#[derive(Encode, Decode, TypeInfo)] +#[derive(Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct DidRecord { diff --git a/primitives/src/secondary_key.rs b/primitives/src/secondary_key.rs index 4ceb62cc85..fbc49e53f9 100644 --- a/primitives/src/secondary_key.rs +++ b/primitives/src/secondary_key.rs @@ -15,7 +15,7 @@ use crate::asset::AssetId; use crate::{ExtrinsicName, IdentityId, PalletName, PortfolioId, SubsetRestriction}; -use codec::{Decode, Encode}; +use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; #[cfg(feature = "std")] use sp_runtime::{Deserialize, Serialize}; @@ -282,7 +282,7 @@ impl Permissions { } /// Account key record. -#[derive(Encode, Decode, TypeInfo)] +#[derive(Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum KeyRecord { @@ -339,7 +339,17 @@ impl KeyRecord { /// It supports different elements as a signer. #[allow(missing_docs)] -#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, Debug, TypeInfo)] +#[derive( + Encode, + Decode, + MaxEncodedLen, + Copy, + Clone, + PartialEq, + Eq, + Debug, + TypeInfo +)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum Signatory { #[cfg_attr(feature = "std", serde(alias = "identity"))]