Make decl_module not require a return type for functions (#1230)

If no return type is specified, `Result` is added and
`Ok(())` is returned by default.

Closes: #1182
This commit is contained in:
Bastian Köcher
2018-12-10 13:36:37 +01:00
committed by GitHub
parent 52ba9a5605
commit acf1b77bcd
17 changed files with 134 additions and 147 deletions
+3 -7
View File
@@ -35,7 +35,7 @@ extern crate srml_system as system;
extern crate srml_consensus as consensus;
use sr_std::prelude::*;
use support::{StorageValue, dispatch::Result};
use support::StorageValue;
use system::ensure_signed;
pub trait Trait: consensus::Trait + system::Trait {
@@ -47,26 +47,22 @@ decl_module! {
// Simple declaration of the `Module` type. Lets the macro know what its working on.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn upgrade(origin, new: Vec<u8>) -> Result {
fn upgrade(origin, new: Vec<u8>) {
// This is a public call, so we ensure that the origin is some signed account.
let _sender = ensure_signed(origin)?;
ensure!(_sender == Self::key(), "only the current upgrade key can use the upgrade_key module");
<consensus::Module<T>>::set_code(new)?;
Self::deposit_event(RawEvent::Upgraded);
Ok(())
}
fn set_key(origin, new: T::AccountId) -> Result {
fn set_key(origin, new: T::AccountId) {
// This is a public call, so we ensure that the origin is some signed account.
let _sender = ensure_signed(origin)?;
ensure!(_sender == Self::key(), "only the current upgrade key can use the upgrade_key module");
Self::deposit_event(RawEvent::KeyChanged(Self::key()));
<Key<T>>::put(new);
Ok(())
}
}
}