diff --git a/libs/utils/src/identity_provider.rs b/libs/utils/src/identity_provider.rs index 22a7bad..b6f0f94 100644 --- a/libs/utils/src/identity_provider.rs +++ b/libs/utils/src/identity_provider.rs @@ -1,9 +1,9 @@ use sp_runtime::DispatchResult; -/// Provides methods to work with an account's identity. +/// Provides methods to retrieve an account's identity. pub trait IdentityProvider { /// Stored account's identity. - type Identity: Default; + type Identity; /// Returns identity for the supplied account [if it exists]. fn identity(who: &T::AccountId) -> Option; @@ -12,9 +12,15 @@ pub trait IdentityProvider { fn has_identity(who: &T::AccountId) -> bool { Self::identity(who).is_some() } +} + +/// Provides methods to set an account's identity. +pub trait IdentitySetter { + /// Idenity information to be associated with the account. + type IdentityInfo: Default; /// Attempts to set identity for the account. - fn set_identity(account: T::AccountId, identity: Self::Identity) -> DispatchResult; + fn set_identity(account: T::AccountId, identity: Self::IdentityInfo) -> DispatchResult; /// Attempts to remove identity of the account. fn remove_identity(account: &T::AccountId) -> DispatchResult; diff --git a/substrate/frame/elections-phragmen/src/lib.rs b/substrate/frame/elections-phragmen/src/lib.rs index 4d15826..f61ce21 100644 --- a/substrate/frame/elections-phragmen/src/lib.rs +++ b/substrate/frame/elections-phragmen/src/lib.rs @@ -114,7 +114,7 @@ use sp_runtime::{ DispatchError, Perbill, RuntimeDebug, }; use sp_std::{cmp::Ordering, prelude::*}; -use utils::IdentityProvider; +use utils::*; mod benchmarking; pub mod weights; @@ -296,7 +296,10 @@ pub mod pallet { type WeightInfo: WeightInfo; /// Verifies account submitted as a candidate. + #[cfg(not(any(test, feature = "runtime-benchmarks")))] type CandidateIdentityProvider: IdentityProvider; + #[cfg(any(test, feature = "runtime-benchmarks"))] + type CandidateIdentityProvider: IdentityProvider + IdentitySetter; } #[pallet::hooks] @@ -1325,6 +1328,7 @@ mod tests { BuildStorage, DispatchResult, }; use substrate_test_utils::assert_eq_uvec; + use utils::IdentitySetter; parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = @@ -1455,6 +1459,10 @@ mod tests { fn identity(account: &AccountId) -> Option { ValidCandidates::::get(account) } + } + + impl IdentitySetter for CandidateIdentityProvider { + type IdentityInfo = (); fn set_identity(account: AccountId, (): ()) -> DispatchResult { ValidCandidates::::insert(account, ());