Migrate generic-asset, identity and im-online to decl_error (#4473)

* Migrate generic-asset, identity and im-online to decl_error

* Update democracy tests

* Update nicks test
This commit is contained in:
Stanislav Tkach
2019-12-21 16:10:29 +02:00
committed by Shawn Tabrizi
parent f6cbf4421f
commit 2c2e0d772d
8 changed files with 153 additions and 77 deletions
+14 -3
View File
@@ -89,7 +89,7 @@ use sp_staking::{
offence::{ReportOffence, Offence, Kind},
};
use frame_support::{
decl_module, decl_event, decl_storage, print, Parameter, debug,
decl_module, decl_event, decl_storage, print, Parameter, debug, decl_error,
traits::Get,
};
use frame_system::{self as system, ensure_none};
@@ -243,9 +243,20 @@ decl_storage! {
}
}
decl_error! {
/// Error for the im-online module.
pub enum Error for Module<T: Trait> {
/// Non existent public key.
InvalidKey,
/// Duplicated heartbeat.
DuplicatedHeartbeat,
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
fn heartbeat(
@@ -274,9 +285,9 @@ decl_module! {
&network_state
);
} else if exists {
Err("Duplicated heartbeat.")?
Err(Error::<T>::DuplicatedHeartbeat)?
} else {
Err("Non existent public key.")?
Err(Error::<T>::InvalidKey)?
}
}