mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 06:41:06 +00:00
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:
@@ -21,7 +21,7 @@ use rstd::result;
|
||||
use codec::Compact;
|
||||
use substrate_primitives::u32_trait::Value as U32;
|
||||
use primitives::traits::{Hash, EnsureOrigin};
|
||||
use srml_support::dispatch::{Result, Dispatchable, Parameter};
|
||||
use srml_support::dispatch::{Dispatchable, Parameter};
|
||||
use srml_support::{StorageValue, StorageMap};
|
||||
use super::{Trait as CouncilTrait, Module as Council};
|
||||
use system::{self, ensure_signed};
|
||||
@@ -68,7 +68,7 @@ decl_event!(
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
|
||||
fn deposit_event() = default;
|
||||
fn propose(origin, threshold: Compact<u32>, proposal: Box<<T as Trait>::Proposal>) -> Result {
|
||||
fn propose(origin, threshold: Compact<u32>, proposal: Box<<T as Trait>::Proposal>) {
|
||||
let who = ensure_signed(origin)?;
|
||||
let threshold = threshold.into();
|
||||
|
||||
@@ -90,10 +90,9 @@ decl_module! {
|
||||
|
||||
Self::deposit_event(RawEvent::Proposed(who, index, proposal_hash, threshold));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn vote(origin, proposal: T::Hash, index: Compact<ProposalIndex>, approve: bool) -> Result {
|
||||
fn vote(origin, proposal: T::Hash, index: Compact<ProposalIndex>, approve: bool) {
|
||||
let who = ensure_signed(origin)?;
|
||||
let index = index.into();
|
||||
|
||||
@@ -154,8 +153,6 @@ decl_module! {
|
||||
// update voting
|
||||
<Voting<T>>::insert(&proposal, voting);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ decl_module! {
|
||||
|
||||
/// Set candidate approvals. Approval slots stay valid as long as candidates in those slots
|
||||
/// are registered.
|
||||
fn set_approvals(origin, votes: Vec<bool>, index: Compact<VoteIndex>) -> Result {
|
||||
fn set_approvals(origin, votes: Vec<bool>, index: Compact<VoteIndex>) {
|
||||
let who = ensure_signed(origin)?;
|
||||
let index: VoteIndex = index.into();
|
||||
|
||||
@@ -110,7 +110,6 @@ decl_module! {
|
||||
}
|
||||
<LastActiveOf<T>>::insert(&who, index);
|
||||
<ApprovalsOf<T>>::insert(&who, votes);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a voter. For it not to be a bond-consuming no-op, all approved candidate indices
|
||||
@@ -124,7 +123,7 @@ decl_module! {
|
||||
who: Address<T::AccountId, T::AccountIndex>,
|
||||
who_index: Compact<u32>,
|
||||
assumed_vote_index: Compact<VoteIndex>
|
||||
) -> Result {
|
||||
) {
|
||||
let reporter = ensure_signed(origin)?;
|
||||
let assumed_vote_index: VoteIndex = assumed_vote_index.into();
|
||||
|
||||
@@ -166,11 +165,10 @@ decl_module! {
|
||||
<balances::Module<T>>::slash_reserved(&reporter, Self::voting_bond());
|
||||
Self::deposit_event(RawEvent::BadReaperSlashed(reporter));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a voter. All votes are cancelled and the voter deposit is returned.
|
||||
fn retract_voter(origin, index: Compact<u32>) -> Result {
|
||||
fn retract_voter(origin, index: Compact<u32>) {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
ensure!(!Self::presentation_active(), "cannot retract when presenting");
|
||||
@@ -183,13 +181,12 @@ decl_module! {
|
||||
|
||||
Self::remove_voter(&who, index, voters);
|
||||
<balances::Module<T>>::unreserve(&who, Self::voting_bond());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Submit oneself for candidacy.
|
||||
///
|
||||
/// Account must have enough transferrable funds in it to pay the bond.
|
||||
fn submit_candidacy(origin, slot: Compact<u32>) -> Result {
|
||||
fn submit_candidacy(origin, slot: Compact<u32>) {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
ensure!(!Self::is_a_candidate(&who), "duplicate candidate submission");
|
||||
@@ -215,7 +212,6 @@ decl_module! {
|
||||
}
|
||||
<Candidates<T>>::put(candidates);
|
||||
<CandidateCount<T>>::put(count as u32 + 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Claim that `signed` is one of the top Self::carry_count() + current_vote().1 candidates.
|
||||
@@ -276,37 +272,33 @@ decl_module! {
|
||||
/// Set the desired member count; if lower than the current count, then seats will not be up
|
||||
/// election when they expire. If more, then a new vote will be started if one is not already
|
||||
/// in progress.
|
||||
fn set_desired_seats(count: Compact<u32>) -> Result {
|
||||
fn set_desired_seats(count: Compact<u32>) {
|
||||
let count: u32 = count.into();
|
||||
<DesiredSeats<T>>::put(count);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a particular member. A tally will happen instantly (if not already in a presentation
|
||||
/// period) to fill the seat if removal means that the desired members are not met.
|
||||
/// This is effective immediately.
|
||||
fn remove_member(who: Address<T::AccountId, T::AccountIndex>) -> Result {
|
||||
fn remove_member(who: Address<T::AccountId, T::AccountIndex>) {
|
||||
let who = <balances::Module<T>>::lookup(who)?;
|
||||
let new_council: Vec<(T::AccountId, T::BlockNumber)> = Self::active_council()
|
||||
.into_iter()
|
||||
.filter(|i| i.0 != who)
|
||||
.collect();
|
||||
<ActiveCouncil<T>>::put(new_council);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the presentation duration. If there is currently a vote being presented for, will
|
||||
/// invoke `finalise_vote`.
|
||||
fn set_presentation_duration(count: <T::BlockNumber as HasCompact>::Type) -> Result {
|
||||
fn set_presentation_duration(count: <T::BlockNumber as HasCompact>::Type) {
|
||||
<PresentationDuration<T>>::put(count.into());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the presentation duration. If there is current a vote being presented for, will
|
||||
/// invoke `finalise_vote`.
|
||||
fn set_term_duration(count: <T::BlockNumber as HasCompact>::Type) -> Result {
|
||||
fn set_term_duration(count: <T::BlockNumber as HasCompact>::Type) {
|
||||
<TermDuration<T>>::put(count.into());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_finalise(n: T::BlockNumber) {
|
||||
|
||||
@@ -35,7 +35,7 @@ decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn deposit_event() = default;
|
||||
|
||||
fn propose(origin, proposal: Box<T::Proposal>) -> Result {
|
||||
fn propose(origin, proposal: Box<T::Proposal>) {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
let expiry = <system::Module<T>>::block_number() + Self::voting_period();
|
||||
@@ -54,11 +54,9 @@ decl_module! {
|
||||
<ProposalOf<T>>::insert(proposal_hash, *proposal);
|
||||
<ProposalVoters<T>>::insert(proposal_hash, vec![who.clone()]);
|
||||
<CouncilVoteOf<T>>::insert((proposal_hash, who.clone()), true);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn vote(origin, proposal: T::Hash, approve: bool) -> Result {
|
||||
fn vote(origin, proposal: T::Hash, approve: bool) {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
ensure!(Self::is_councillor(&who), "only councillors may vote on council proposals");
|
||||
@@ -67,10 +65,9 @@ decl_module! {
|
||||
<ProposalVoters<T>>::mutate(proposal, |voters| voters.push(who.clone()));
|
||||
}
|
||||
<CouncilVoteOf<T>>::insert((proposal, who), approve);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn veto(origin, proposal_hash: T::Hash) -> Result {
|
||||
fn veto(origin, proposal_hash: T::Hash) {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
ensure!(Self::is_councillor(&who), "only councillors may veto council proposals");
|
||||
@@ -96,17 +93,14 @@ decl_module! {
|
||||
for (c, _) in <Council<T>>::active_council() {
|
||||
<CouncilVoteOf<T>>::remove((proposal_hash, c));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_cooloff_period(blocks: <T::BlockNumber as HasCompact>::Type) -> Result {
|
||||
fn set_cooloff_period(blocks: <T::BlockNumber as HasCompact>::Type) {
|
||||
<CooloffPeriod<T>>::put(blocks.into());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_voting_period(blocks: <T::BlockNumber as HasCompact>::Type) -> Result {
|
||||
fn set_voting_period(blocks: <T::BlockNumber as HasCompact>::Type) {
|
||||
<VotingPeriod<T>>::put(blocks.into());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_finalise(n: T::BlockNumber) {
|
||||
|
||||
Reference in New Issue
Block a user