mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 13:31:10 +00:00
Migrate membership, nicks, scored-pool and session to decl_error (#4463)
* Migrate membership, nicks, scored-pool and session to decl_error * Fix tests * Update frame/scored-pool/src/tests.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Remove InsufficientBalance error from scored-pool * Replace Error::<Test, DefaultInstance> with Error::<Test, _> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
committed by
Shawn Tabrizi
parent
9950ea98fc
commit
328563f8d4
@@ -125,7 +125,7 @@ use sp_runtime::{KeyTypeId, Perbill, RuntimeAppPublic, BoundToRuntimeAppPublic};
|
||||
use frame_support::weights::SimpleDispatchInfo;
|
||||
use sp_runtime::traits::{Convert, Zero, Member, OpaqueKeys};
|
||||
use sp_staking::SessionIndex;
|
||||
use frame_support::{dispatch, ConsensusEngineId, decl_module, decl_event, decl_storage};
|
||||
use frame_support::{dispatch, ConsensusEngineId, decl_module, decl_event, decl_storage, decl_error};
|
||||
use frame_support::{ensure, traits::{OnFreeBalanceZero, Get, FindAuthor, ValidatorRegistration}, Parameter};
|
||||
use frame_system::{self as system, ensure_signed};
|
||||
|
||||
@@ -464,12 +464,26 @@ decl_event!(
|
||||
}
|
||||
);
|
||||
|
||||
decl_error! {
|
||||
/// Error for the session module.
|
||||
pub enum Error for Module<T: Trait> {
|
||||
/// Invalid ownership proof.
|
||||
InvalidProof,
|
||||
/// No associated validator ID for account.
|
||||
NoAssociatedValidatorId,
|
||||
/// Registered duplicate key.
|
||||
DuplicatedKey,
|
||||
}
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
/// Used as first key for `NextKeys` and `KeyOwner` to put all the data into the same branch
|
||||
/// of the trie.
|
||||
const DEDUP_KEY_PREFIX: &[u8] = DEDUP_KEY_PREFIX;
|
||||
|
||||
type Error = Error<T>;
|
||||
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Sets the session key(s) of the function caller to `key`.
|
||||
@@ -486,12 +500,9 @@ decl_module! {
|
||||
fn set_keys(origin, keys: T::Keys, proof: Vec<u8>) -> dispatch::DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
ensure!(keys.ownership_proof_is_valid(&proof), "invalid ownership proof");
|
||||
ensure!(keys.ownership_proof_is_valid(&proof), Error::<T>::InvalidProof);
|
||||
|
||||
let who = match T::ValidatorIdOf::convert(who) {
|
||||
Some(val_id) => val_id,
|
||||
None => Err("no associated validator ID for account.")?,
|
||||
};
|
||||
let who = T::ValidatorIdOf::convert(who).ok_or(Error::<T>::NoAssociatedValidatorId)?;
|
||||
|
||||
Self::do_set_keys(&who, keys)?;
|
||||
|
||||
@@ -640,7 +651,7 @@ impl<T: Trait> Module<T> {
|
||||
// ensure keys are without duplication.
|
||||
ensure!(
|
||||
Self::key_owner(*id, key).map_or(true, |owner| &owner == who),
|
||||
"registered duplicate key"
|
||||
Error::<T>::DuplicatedKey,
|
||||
);
|
||||
|
||||
if let Some(old) = old_keys.as_ref().map(|k| k.get_raw(*id)) {
|
||||
|
||||
Reference in New Issue
Block a user