More decl_error! migrations (#4427)

* Update assets to `decl_error`

* Update aura to `decl_error`

* Update authority discovery to `decl_error`

* Update collective to `decl_error`

* Update evm to `decl_error!`

* Fix error with replace

* Revert "Update authority discovery to `decl_error`"

This reverts commit 26e8f3c56656963d847e984c6f2c8e1f88014899.

* Revert "Update aura to `decl_error`"

This reverts commit 8f17c44ca8375a4a755710aaab7ad4d9522c4376.

* Update democracy to `decl_error`

* Update finality-tracker to `decl_error`

* Update grandpa to `decl_error`

* `assert` to `ensure` in dispatchable function
This commit is contained in:
Shawn Tabrizi
2019-12-18 10:50:21 +01:00
committed by Gavin Wood
parent 9550c845f3
commit 57c19bcf4e
6 changed files with 323 additions and 194 deletions
+16 -6
View File
@@ -19,9 +19,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
use sp_inherents::{InherentIdentifier, ProvideInherent, InherentData, MakeFatalError};
use sp_runtime::traits::{One, Zero, SaturatedConversion};
use sp_runtime::traits::{One, Zero, SaturatedConversion, ModuleDispatchError};
use sp_std::{prelude::*, result, cmp, vec};
use frame_support::{decl_module, decl_storage};
use frame_support::{decl_module, decl_storage, decl_error, ensure};
use frame_support::traits::Get;
use frame_system::{ensure_none, Trait as SystemTrait};
use sp_finality_tracker::{INHERENT_IDENTIFIER, FinalizedInherentData};
@@ -56,8 +56,18 @@ decl_storage! {
}
}
decl_error! {
pub enum Error {
/// Final hint must be updated only once in the block
AlreadyUpdated,
/// Finalized height above block number
BadHint,
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
type Error = Error;
/// The number of recent samples to keep from this chain. Default is 101.
const WindowSize: T::BlockNumber = T::WindowSize::get();
@@ -67,11 +77,11 @@ decl_module! {
/// Hint that the author of this block thinks the best finalized
/// block is the given number.
fn final_hint(origin, #[compact] hint: T::BlockNumber) {
ensure_none(origin)?;
assert!(!<Self as Store>::Update::exists(), "Final hint must be updated only once in the block");
assert!(
ensure_none(origin).map_err(|e| e.as_str())?;
ensure!(!<Self as Store>::Update::exists(), Error::AlreadyUpdated);
ensure!(
frame_system::Module::<T>::block_number() >= hint,
"Finalized height above block number",
Error::BadHint,
);
<Self as Store>::Update::put(hint);
}