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
+5 -16
View File
@@ -40,7 +40,6 @@ extern crate srml_balances as balances;
use rstd::prelude::*;
use runtime_support::{StorageValue, StorageMap};
use runtime_support::dispatch::Result;
use runtime_primitives::{Permill, traits::{Zero, EnsureOrigin}};
use codec::{HasCompact, Compact};
use balances::{OnDilution, address::Address};
@@ -77,7 +76,7 @@ decl_module! {
origin,
value: <T::Balance as HasCompact>::Type,
beneficiary: Address<T::AccountId, T::AccountIndex>
) -> Result {
) {
let proposer = ensure_signed(origin)?;
let beneficiary = <balances::Module<T>>::lookup(beneficiary)?;
let value = value.into();
@@ -91,17 +90,12 @@ decl_module! {
<Proposals<T>>::insert(c, Proposal { proposer, value, beneficiary, bond });
Self::deposit_event(RawEvent::Proposed(c));
Ok(())
}
/// Set the balance of funds available to spend.
fn set_pot(new_pot: <T::Balance as HasCompact>::Type) -> Result {
fn set_pot(new_pot: <T::Balance as HasCompact>::Type) {
// Put the new value into storage.
<Pot<T>>::put(new_pot.into());
// All good.
Ok(())
}
/// (Re-)configure this module.
@@ -110,16 +104,15 @@ decl_module! {
proposal_bond_minimum: <T::Balance as HasCompact>::Type,
spend_period: <T::BlockNumber as HasCompact>::Type,
burn: Permill
) -> Result {
) {
<ProposalBond<T>>::put(proposal_bond);
<ProposalBondMinimum<T>>::put(proposal_bond_minimum.into());
<SpendPeriod<T>>::put(spend_period.into());
<Burn<T>>::put(burn);
Ok(())
}
/// Reject a proposed spend. The original deposit will be slashed.
fn reject_proposal(origin, proposal_id: Compact<ProposalIndex>) -> Result {
fn reject_proposal(origin, proposal_id: Compact<ProposalIndex>) {
T::RejectOrigin::ensure_origin(origin)?;
let proposal_id: ProposalIndex = proposal_id.into();
@@ -127,21 +120,17 @@ decl_module! {
let value = proposal.bond;
let _ = <balances::Module<T>>::slash_reserved(&proposal.proposer, value);
Ok(())
}
/// Approve a proposal. At a later time, the proposal will be allocated to the beneficiary
/// and the original deposit will be returned.
fn approve_proposal(origin, proposal_id: Compact<ProposalIndex>) -> Result {
fn approve_proposal(origin, proposal_id: Compact<ProposalIndex>) {
T::ApproveOrigin::ensure_origin(origin)?;
let proposal_id = proposal_id.into();
ensure!(<Proposals<T>>::exists(proposal_id), "No proposal at that index");
<Approvals<T>>::mutate(|v| v.push(proposal_id));
Ok(())
}
fn on_finalise(n: T::BlockNumber) {