mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-23 14:15:44 +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:
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -45,7 +45,7 @@ extern crate sr_primitives as primitives;
|
|||||||
// depend on it being around.
|
// depend on it being around.
|
||||||
extern crate srml_system as system;
|
extern crate srml_system as system;
|
||||||
|
|
||||||
use runtime_support::{StorageValue, StorageMap, dispatch::Result, Parameter};
|
use runtime_support::{StorageValue, StorageMap, Parameter};
|
||||||
use primitives::traits::{Member, SimpleArithmetic, Zero};
|
use primitives::traits::{Member, SimpleArithmetic, Zero};
|
||||||
use system::ensure_signed;
|
use system::ensure_signed;
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ decl_module! {
|
|||||||
/// Issue a new class of fungible assets. There are, and will only ever be, `total`
|
/// Issue a new class of fungible assets. There are, and will only ever be, `total`
|
||||||
/// such assets and they'll all belong to the `origin` initially. It will have an
|
/// such assets and they'll all belong to the `origin` initially. It will have an
|
||||||
/// identifier `AssetId` instance: this will be specified in the `Issued` event.
|
/// identifier `AssetId` instance: this will be specified in the `Issued` event.
|
||||||
fn issue(origin, total: T::Balance) -> Result {
|
fn issue(origin, total: T::Balance) {
|
||||||
let origin = ensure_signed(origin)?;
|
let origin = ensure_signed(origin)?;
|
||||||
|
|
||||||
let id = Self::next_asset_id();
|
let id = Self::next_asset_id();
|
||||||
@@ -75,11 +75,10 @@ decl_module! {
|
|||||||
<Balances<T>>::insert((id, origin.clone()), total);
|
<Balances<T>>::insert((id, origin.clone()), total);
|
||||||
|
|
||||||
Self::deposit_event(RawEvent::Issued(id, origin, total));
|
Self::deposit_event(RawEvent::Issued(id, origin, total));
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Move some assets from one holder to another.
|
/// Move some assets from one holder to another.
|
||||||
fn transfer(origin, id: AssetId, target: T::AccountId, amount: T::Balance) -> Result {
|
fn transfer(origin, id: AssetId, target: T::AccountId, amount: T::Balance) {
|
||||||
let origin = ensure_signed(origin)?;
|
let origin = ensure_signed(origin)?;
|
||||||
let origin_account = (id, origin.clone());
|
let origin_account = (id, origin.clone());
|
||||||
let origin_balance = <Balances<T>>::get(&origin_account);
|
let origin_balance = <Balances<T>>::get(&origin_account);
|
||||||
@@ -88,20 +87,16 @@ decl_module! {
|
|||||||
Self::deposit_event(RawEvent::Transfered(id, origin, target.clone(), amount));
|
Self::deposit_event(RawEvent::Transfered(id, origin, target.clone(), amount));
|
||||||
<Balances<T>>::insert(origin_account, origin_balance - amount);
|
<Balances<T>>::insert(origin_account, origin_balance - amount);
|
||||||
<Balances<T>>::mutate((id, target), |balance| *balance += amount);
|
<Balances<T>>::mutate((id, target), |balance| *balance += amount);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destroy any assets of `id` owned by `origin`.
|
/// Destroy any assets of `id` owned by `origin`.
|
||||||
fn destroy(origin, id: AssetId) -> Result {
|
fn destroy(origin, id: AssetId) {
|
||||||
let origin = ensure_signed(origin)?;
|
let origin = ensure_signed(origin)?;
|
||||||
|
|
||||||
let balance = <Balances<T>>::take((id, origin.clone()));
|
let balance = <Balances<T>>::take((id, origin.clone()));
|
||||||
ensure!(!balance.is_zero(), "origin balance should be non-zero");
|
ensure!(!balance.is_zero(), "origin balance should be non-zero");
|
||||||
|
|
||||||
Self::deposit_event(RawEvent::Destroyed(id, origin, balance));
|
Self::deposit_event(RawEvent::Destroyed(id, origin, balance));
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ decl_module! {
|
|||||||
origin,
|
origin,
|
||||||
dest: RawAddress<T::AccountId, T::AccountIndex>,
|
dest: RawAddress<T::AccountId, T::AccountIndex>,
|
||||||
value: <T::Balance as HasCompact>::Type
|
value: <T::Balance as HasCompact>::Type
|
||||||
) -> Result {
|
) {
|
||||||
let transactor = ensure_signed(origin)?;
|
let transactor = ensure_signed(origin)?;
|
||||||
|
|
||||||
let dest = Self::lookup(dest)?;
|
let dest = Self::lookup(dest)?;
|
||||||
@@ -170,8 +170,6 @@ decl_module! {
|
|||||||
Self::set_free_balance_creating(&dest, new_to_balance);
|
Self::set_free_balance_creating(&dest, new_to_balance);
|
||||||
Self::deposit_event(RawEvent::Transfer(transactor, dest, value, fee));
|
Self::deposit_event(RawEvent::Transfer(transactor, dest, value, fee));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the balances of a given account.
|
/// Set the balances of a given account.
|
||||||
@@ -179,11 +177,10 @@ decl_module! {
|
|||||||
who: RawAddress<T::AccountId, T::AccountIndex>,
|
who: RawAddress<T::AccountId, T::AccountIndex>,
|
||||||
free: <T::Balance as HasCompact>::Type,
|
free: <T::Balance as HasCompact>::Type,
|
||||||
reserved: <T::Balance as HasCompact>::Type
|
reserved: <T::Balance as HasCompact>::Type
|
||||||
) -> Result {
|
) {
|
||||||
let who = Self::lookup(who)?;
|
let who = Self::lookup(who)?;
|
||||||
Self::set_free_balance(&who, free.into());
|
Self::set_free_balance(&who, free.into());
|
||||||
Self::set_reserved_balance(&who, reserved.into());
|
Self::set_reserved_balance(&who, reserved.into());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ use rstd::prelude::*;
|
|||||||
use rstd::result;
|
use rstd::result;
|
||||||
use parity_codec::Encode;
|
use parity_codec::Encode;
|
||||||
use runtime_support::{storage, Parameter};
|
use runtime_support::{storage, Parameter};
|
||||||
use runtime_support::dispatch::Result;
|
|
||||||
use runtime_support::storage::StorageValue;
|
use runtime_support::storage::StorageValue;
|
||||||
use runtime_support::storage::unhashed::StorageVec;
|
use runtime_support::storage::unhashed::StorageVec;
|
||||||
use primitives::CheckInherentError;
|
use primitives::CheckInherentError;
|
||||||
@@ -142,16 +141,15 @@ decl_storage! {
|
|||||||
decl_module! {
|
decl_module! {
|
||||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||||
/// Report some misbehaviour.
|
/// Report some misbehaviour.
|
||||||
fn report_misbehavior(origin, _report: Vec<u8>) -> Result {
|
fn report_misbehavior(origin, _report: Vec<u8>) {
|
||||||
ensure_signed(origin)?;
|
ensure_signed(origin)?;
|
||||||
// TODO.
|
// TODO.
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Note the previous block's validator missed their opportunity to propose a block.
|
/// Note the previous block's validator missed their opportunity to propose a block.
|
||||||
/// This only comes in if 2/3+1 of the validators agree that no proposal was submitted.
|
/// This only comes in if 2/3+1 of the validators agree that no proposal was submitted.
|
||||||
/// It's only relevant for the previous block.
|
/// It's only relevant for the previous block.
|
||||||
fn note_offline(origin, offline_val_indices: Vec<u32>) -> Result {
|
fn note_offline(origin, offline_val_indices: Vec<u32>) {
|
||||||
ensure_inherent(origin)?;
|
ensure_inherent(origin)?;
|
||||||
assert!(
|
assert!(
|
||||||
<system::Module<T>>::extrinsic_index() == Some(T::NOTE_OFFLINE_POSITION),
|
<system::Module<T>>::extrinsic_index() == Some(T::NOTE_OFFLINE_POSITION),
|
||||||
@@ -162,34 +160,28 @@ decl_module! {
|
|||||||
for validator_index in offline_val_indices.into_iter() {
|
for validator_index in offline_val_indices.into_iter() {
|
||||||
T::OnOfflineValidator::on_offline_validator(validator_index as usize);
|
T::OnOfflineValidator::on_offline_validator(validator_index as usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make some on-chain remark.
|
/// Make some on-chain remark.
|
||||||
fn remark(origin, _remark: Vec<u8>) -> Result {
|
fn remark(origin, _remark: Vec<u8>) {
|
||||||
ensure_signed(origin)?;
|
ensure_signed(origin)?;
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the number of pages in the WebAssembly environment's heap.
|
/// Set the number of pages in the WebAssembly environment's heap.
|
||||||
fn set_heap_pages(pages: u64) -> Result {
|
fn set_heap_pages(pages: u64) {
|
||||||
storage::unhashed::put_raw(well_known_keys::HEAP_PAGES, &pages.encode());
|
storage::unhashed::put_raw(well_known_keys::HEAP_PAGES, &pages.encode());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the new code.
|
/// Set the new code.
|
||||||
pub fn set_code(new: Vec<u8>) -> Result {
|
pub fn set_code(new: Vec<u8>) {
|
||||||
storage::unhashed::put_raw(well_known_keys::CODE, &new);
|
storage::unhashed::put_raw(well_known_keys::CODE, &new);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set some items of storage.
|
/// Set some items of storage.
|
||||||
fn set_storage(items: Vec<KeyValue>) -> Result {
|
fn set_storage(items: Vec<KeyValue>) {
|
||||||
for i in &items {
|
for i in &items {
|
||||||
storage::unhashed::put_raw(&i.0, &i.1);
|
storage::unhashed::put_raw(&i.0, &i.1);
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_finalise() {
|
fn on_finalise() {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use rstd::result;
|
|||||||
use codec::Compact;
|
use codec::Compact;
|
||||||
use substrate_primitives::u32_trait::Value as U32;
|
use substrate_primitives::u32_trait::Value as U32;
|
||||||
use primitives::traits::{Hash, EnsureOrigin};
|
use primitives::traits::{Hash, EnsureOrigin};
|
||||||
use srml_support::dispatch::{Result, Dispatchable, Parameter};
|
use srml_support::dispatch::{Dispatchable, Parameter};
|
||||||
use srml_support::{StorageValue, StorageMap};
|
use srml_support::{StorageValue, StorageMap};
|
||||||
use super::{Trait as CouncilTrait, Module as Council};
|
use super::{Trait as CouncilTrait, Module as Council};
|
||||||
use system::{self, ensure_signed};
|
use system::{self, ensure_signed};
|
||||||
@@ -68,7 +68,7 @@ decl_event!(
|
|||||||
decl_module! {
|
decl_module! {
|
||||||
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
|
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
|
||||||
fn deposit_event() = default;
|
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 who = ensure_signed(origin)?;
|
||||||
let threshold = threshold.into();
|
let threshold = threshold.into();
|
||||||
|
|
||||||
@@ -90,10 +90,9 @@ decl_module! {
|
|||||||
|
|
||||||
Self::deposit_event(RawEvent::Proposed(who, index, proposal_hash, threshold));
|
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 who = ensure_signed(origin)?;
|
||||||
let index = index.into();
|
let index = index.into();
|
||||||
|
|
||||||
@@ -154,8 +153,6 @@ decl_module! {
|
|||||||
// update voting
|
// update voting
|
||||||
<Voting<T>>::insert(&proposal, 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
|
/// Set candidate approvals. Approval slots stay valid as long as candidates in those slots
|
||||||
/// are registered.
|
/// 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 who = ensure_signed(origin)?;
|
||||||
let index: VoteIndex = index.into();
|
let index: VoteIndex = index.into();
|
||||||
|
|
||||||
@@ -110,7 +110,6 @@ decl_module! {
|
|||||||
}
|
}
|
||||||
<LastActiveOf<T>>::insert(&who, index);
|
<LastActiveOf<T>>::insert(&who, index);
|
||||||
<ApprovalsOf<T>>::insert(&who, votes);
|
<ApprovalsOf<T>>::insert(&who, votes);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a voter. For it not to be a bond-consuming no-op, all approved candidate indices
|
/// 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: Address<T::AccountId, T::AccountIndex>,
|
||||||
who_index: Compact<u32>,
|
who_index: Compact<u32>,
|
||||||
assumed_vote_index: Compact<VoteIndex>
|
assumed_vote_index: Compact<VoteIndex>
|
||||||
) -> Result {
|
) {
|
||||||
let reporter = ensure_signed(origin)?;
|
let reporter = ensure_signed(origin)?;
|
||||||
let assumed_vote_index: VoteIndex = assumed_vote_index.into();
|
let assumed_vote_index: VoteIndex = assumed_vote_index.into();
|
||||||
|
|
||||||
@@ -166,11 +165,10 @@ decl_module! {
|
|||||||
<balances::Module<T>>::slash_reserved(&reporter, Self::voting_bond());
|
<balances::Module<T>>::slash_reserved(&reporter, Self::voting_bond());
|
||||||
Self::deposit_event(RawEvent::BadReaperSlashed(reporter));
|
Self::deposit_event(RawEvent::BadReaperSlashed(reporter));
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a voter. All votes are cancelled and the voter deposit is returned.
|
/// 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)?;
|
let who = ensure_signed(origin)?;
|
||||||
|
|
||||||
ensure!(!Self::presentation_active(), "cannot retract when presenting");
|
ensure!(!Self::presentation_active(), "cannot retract when presenting");
|
||||||
@@ -183,13 +181,12 @@ decl_module! {
|
|||||||
|
|
||||||
Self::remove_voter(&who, index, voters);
|
Self::remove_voter(&who, index, voters);
|
||||||
<balances::Module<T>>::unreserve(&who, Self::voting_bond());
|
<balances::Module<T>>::unreserve(&who, Self::voting_bond());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Submit oneself for candidacy.
|
/// Submit oneself for candidacy.
|
||||||
///
|
///
|
||||||
/// Account must have enough transferrable funds in it to pay the bond.
|
/// 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)?;
|
let who = ensure_signed(origin)?;
|
||||||
|
|
||||||
ensure!(!Self::is_a_candidate(&who), "duplicate candidate submission");
|
ensure!(!Self::is_a_candidate(&who), "duplicate candidate submission");
|
||||||
@@ -215,7 +212,6 @@ decl_module! {
|
|||||||
}
|
}
|
||||||
<Candidates<T>>::put(candidates);
|
<Candidates<T>>::put(candidates);
|
||||||
<CandidateCount<T>>::put(count as u32 + 1);
|
<CandidateCount<T>>::put(count as u32 + 1);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Claim that `signed` is one of the top Self::carry_count() + current_vote().1 candidates.
|
/// 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
|
/// 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
|
/// election when they expire. If more, then a new vote will be started if one is not already
|
||||||
/// in progress.
|
/// in progress.
|
||||||
fn set_desired_seats(count: Compact<u32>) -> Result {
|
fn set_desired_seats(count: Compact<u32>) {
|
||||||
let count: u32 = count.into();
|
let count: u32 = count.into();
|
||||||
<DesiredSeats<T>>::put(count);
|
<DesiredSeats<T>>::put(count);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a particular member. A tally will happen instantly (if not already in a presentation
|
/// 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.
|
/// period) to fill the seat if removal means that the desired members are not met.
|
||||||
/// This is effective immediately.
|
/// 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 who = <balances::Module<T>>::lookup(who)?;
|
||||||
let new_council: Vec<(T::AccountId, T::BlockNumber)> = Self::active_council()
|
let new_council: Vec<(T::AccountId, T::BlockNumber)> = Self::active_council()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|i| i.0 != who)
|
.filter(|i| i.0 != who)
|
||||||
.collect();
|
.collect();
|
||||||
<ActiveCouncil<T>>::put(new_council);
|
<ActiveCouncil<T>>::put(new_council);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the presentation duration. If there is currently a vote being presented for, will
|
/// Set the presentation duration. If there is currently a vote being presented for, will
|
||||||
/// invoke `finalise_vote`.
|
/// 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());
|
<PresentationDuration<T>>::put(count.into());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the presentation duration. If there is current a vote being presented for, will
|
/// Set the presentation duration. If there is current a vote being presented for, will
|
||||||
/// invoke `finalise_vote`.
|
/// 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());
|
<TermDuration<T>>::put(count.into());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_finalise(n: T::BlockNumber) {
|
fn on_finalise(n: T::BlockNumber) {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ decl_module! {
|
|||||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||||
fn deposit_event() = default;
|
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 who = ensure_signed(origin)?;
|
||||||
|
|
||||||
let expiry = <system::Module<T>>::block_number() + Self::voting_period();
|
let expiry = <system::Module<T>>::block_number() + Self::voting_period();
|
||||||
@@ -54,11 +54,9 @@ decl_module! {
|
|||||||
<ProposalOf<T>>::insert(proposal_hash, *proposal);
|
<ProposalOf<T>>::insert(proposal_hash, *proposal);
|
||||||
<ProposalVoters<T>>::insert(proposal_hash, vec![who.clone()]);
|
<ProposalVoters<T>>::insert(proposal_hash, vec![who.clone()]);
|
||||||
<CouncilVoteOf<T>>::insert((proposal_hash, who.clone()), true);
|
<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)?;
|
let who = ensure_signed(origin)?;
|
||||||
|
|
||||||
ensure!(Self::is_councillor(&who), "only councillors may vote on council proposals");
|
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()));
|
<ProposalVoters<T>>::mutate(proposal, |voters| voters.push(who.clone()));
|
||||||
}
|
}
|
||||||
<CouncilVoteOf<T>>::insert((proposal, who), approve);
|
<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)?;
|
let who = ensure_signed(origin)?;
|
||||||
|
|
||||||
ensure!(Self::is_councillor(&who), "only councillors may veto council proposals");
|
ensure!(Self::is_councillor(&who), "only councillors may veto council proposals");
|
||||||
@@ -96,17 +93,14 @@ decl_module! {
|
|||||||
for (c, _) in <Council<T>>::active_council() {
|
for (c, _) in <Council<T>>::active_council() {
|
||||||
<CouncilVoteOf<T>>::remove((proposal_hash, c));
|
<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());
|
<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());
|
<VotingPeriod<T>>::put(blocks.into());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_finalise(n: T::BlockNumber) {
|
fn on_finalise(n: T::BlockNumber) {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ decl_module! {
|
|||||||
origin,
|
origin,
|
||||||
proposal: Box<T::Proposal>,
|
proposal: Box<T::Proposal>,
|
||||||
value: <T::Balance as HasCompact>::Type
|
value: <T::Balance as HasCompact>::Type
|
||||||
) -> Result {
|
) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
let value = value.into();
|
let value = value.into();
|
||||||
|
|
||||||
@@ -80,11 +80,10 @@ decl_module! {
|
|||||||
let mut props = Self::public_props();
|
let mut props = Self::public_props();
|
||||||
props.push((index, (*proposal).clone(), who));
|
props.push((index, (*proposal).clone(), who));
|
||||||
<PublicProps<T>>::put(props);
|
<PublicProps<T>>::put(props);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Propose a sensitive action to be taken.
|
/// Propose a sensitive action to be taken.
|
||||||
fn second(origin, proposal: Compact<PropIndex>) -> Result {
|
fn second(origin, proposal: Compact<PropIndex>) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
let proposal: PropIndex = proposal.into();
|
let proposal: PropIndex = proposal.into();
|
||||||
let mut deposit = Self::deposit_of(proposal)
|
let mut deposit = Self::deposit_of(proposal)
|
||||||
@@ -93,12 +92,11 @@ decl_module! {
|
|||||||
.map_err(|_| "seconder's balance too low")?;
|
.map_err(|_| "seconder's balance too low")?;
|
||||||
deposit.1.push(who);
|
deposit.1.push(who);
|
||||||
<DepositOf<T>>::insert(proposal, deposit);
|
<DepositOf<T>>::insert(proposal, deposit);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Vote in a referendum. If `approve_proposal` is true, the vote is to enact the proposal;
|
/// Vote in a referendum. If `approve_proposal` is true, the vote is to enact the proposal;
|
||||||
/// false would be a vote to keep the status quo.
|
/// false would be a vote to keep the status quo.
|
||||||
fn vote(origin, ref_index: Compact<ReferendumIndex>, approve_proposal: bool) -> Result {
|
fn vote(origin, ref_index: Compact<ReferendumIndex>, approve_proposal: bool) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
let ref_index = ref_index.into();
|
let ref_index = ref_index.into();
|
||||||
ensure!(Self::is_active_referendum(ref_index), "vote given for invalid referendum.");
|
ensure!(Self::is_active_referendum(ref_index), "vote given for invalid referendum.");
|
||||||
@@ -108,7 +106,6 @@ decl_module! {
|
|||||||
<VotersFor<T>>::mutate(ref_index, |voters| voters.push(who.clone()));
|
<VotersFor<T>>::mutate(ref_index, |voters| voters.push(who.clone()));
|
||||||
}
|
}
|
||||||
<VoteOf<T>>::insert(&(ref_index, who), approve_proposal);
|
<VoteOf<T>>::insert(&(ref_index, who), approve_proposal);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start a referendum.
|
/// Start a referendum.
|
||||||
@@ -121,9 +118,8 @@ decl_module! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a referendum.
|
/// Remove a referendum.
|
||||||
fn cancel_referendum(ref_index: Compact<ReferendumIndex>) -> Result {
|
fn cancel_referendum(ref_index: Compact<ReferendumIndex>) {
|
||||||
Self::clear_referendum(ref_index.into());
|
Self::clear_referendum(ref_index.into());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_finalise(n: T::BlockNumber) {
|
fn on_finalise(n: T::BlockNumber) {
|
||||||
|
|||||||
@@ -173,12 +173,11 @@ decl_module! {
|
|||||||
// calls to be executed - we don't need to care why. Because it's privileged, we can
|
// calls to be executed - we don't need to care why. Because it's privileged, we can
|
||||||
// assume it's a one-off operation and substantial processing/storage/memory can be used
|
// assume it's a one-off operation and substantial processing/storage/memory can be used
|
||||||
// without worrying about gameability or attack scenarios.
|
// without worrying about gameability or attack scenarios.
|
||||||
fn set_dummy(new_value: T::Balance) -> Result {
|
// If you not specify `Result` explicitly as return value, it will be added automatically
|
||||||
|
// for you and `Ok(())` will be returned.
|
||||||
|
fn set_dummy(new_value: T::Balance) {
|
||||||
// Put the new value into storage.
|
// Put the new value into storage.
|
||||||
<Dummy<T>>::put(new_value);
|
<Dummy<T>>::put(new_value);
|
||||||
|
|
||||||
// All good.
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The signature could also look like: `fn on_finalise()`
|
// The signature could also look like: `fn on_finalise()`
|
||||||
|
|||||||
@@ -189,10 +189,9 @@ decl_module! {
|
|||||||
fn deposit_event() = default;
|
fn deposit_event() = default;
|
||||||
|
|
||||||
/// Report some misbehaviour.
|
/// Report some misbehaviour.
|
||||||
fn report_misbehavior(origin, _report: Vec<u8>) -> Result {
|
fn report_misbehavior(origin, _report: Vec<u8>) {
|
||||||
ensure_signed(origin)?;
|
ensure_signed(origin)?;
|
||||||
// TODO: https://github.com/paritytech/substrate/issues/1112
|
// TODO: https://github.com/paritytech/substrate/issues/1112
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_finalise(block_number: T::BlockNumber) {
|
fn on_finalise(block_number: T::BlockNumber) {
|
||||||
|
|||||||
@@ -93,17 +93,15 @@ decl_module! {
|
|||||||
|
|
||||||
/// Sets the session key of `_validator` to `_key`. This doesn't take effect until the next
|
/// Sets the session key of `_validator` to `_key`. This doesn't take effect until the next
|
||||||
/// session.
|
/// session.
|
||||||
fn set_key(origin, key: T::SessionKey) -> Result {
|
fn set_key(origin, key: T::SessionKey) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
// set new value for next session
|
// set new value for next session
|
||||||
<NextKeyFor<T>>::insert(who, key);
|
<NextKeyFor<T>>::insert(who, key);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a new session length. Won't kick in until the next session change (at current length).
|
/// Set a new session length. Won't kick in until the next session change (at current length).
|
||||||
fn set_length(new: <T::BlockNumber as HasCompact>::Type) -> Result {
|
fn set_length(new: <T::BlockNumber as HasCompact>::Type) {
|
||||||
<NextSessionLength<T>>::put(new.into());
|
<NextSessionLength<T>>::put(new.into());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Forces a new session.
|
/// Forces a new session.
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ decl_module! {
|
|||||||
/// Declare the desire to stake for the transactor.
|
/// Declare the desire to stake for the transactor.
|
||||||
///
|
///
|
||||||
/// Effects will be felt at the beginning of the next era.
|
/// Effects will be felt at the beginning of the next era.
|
||||||
fn stake(origin) -> Result {
|
fn stake(origin) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
ensure!(Self::nominating(&who).is_none(), "Cannot stake if already nominating.");
|
ensure!(Self::nominating(&who).is_none(), "Cannot stake if already nominating.");
|
||||||
let mut intentions = <Intentions<T>>::get();
|
let mut intentions = <Intentions<T>>::get();
|
||||||
@@ -115,7 +115,6 @@ decl_module! {
|
|||||||
<Bondage<T>>::insert(&who, T::BlockNumber::max_value());
|
<Bondage<T>>::insert(&who, T::BlockNumber::max_value());
|
||||||
intentions.push(who);
|
intentions.push(who);
|
||||||
<Intentions<T>>::put(intentions);
|
<Intentions<T>>::put(intentions);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retract the desire to stake for the transactor.
|
/// Retract the desire to stake for the transactor.
|
||||||
@@ -131,7 +130,7 @@ decl_module! {
|
|||||||
Self::apply_unstake(&who, intentions_index as usize)
|
Self::apply_unstake(&who, intentions_index as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nominate(origin, target: Address<T::AccountId, T::AccountIndex>) -> Result {
|
fn nominate(origin, target: Address<T::AccountId, T::AccountIndex>) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
let target = <balances::Module<T>>::lookup(target)?;
|
let target = <balances::Module<T>>::lookup(target)?;
|
||||||
|
|
||||||
@@ -148,13 +147,11 @@ decl_module! {
|
|||||||
|
|
||||||
// Update bondage
|
// Update bondage
|
||||||
<Bondage<T>>::insert(&who, T::BlockNumber::max_value());
|
<Bondage<T>>::insert(&who, T::BlockNumber::max_value());
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Will panic if called when source isn't currently nominating target.
|
/// Will panic if called when source isn't currently nominating target.
|
||||||
/// Updates Nominating, NominatorsFor and NominationBalance.
|
/// Updates Nominating, NominatorsFor and NominationBalance.
|
||||||
fn unnominate(origin, target_index: Compact<u32>) -> Result {
|
fn unnominate(origin, target_index: Compact<u32>) {
|
||||||
let source = ensure_signed(origin)?;
|
let source = ensure_signed(origin)?;
|
||||||
let target_index: u32 = target_index.into();
|
let target_index: u32 = target_index.into();
|
||||||
let target_index = target_index as usize;
|
let target_index = target_index as usize;
|
||||||
@@ -180,7 +177,6 @@ decl_module! {
|
|||||||
source,
|
source,
|
||||||
<system::Module<T>>::block_number() + Self::bonding_duration()
|
<system::Module<T>>::block_number() + Self::bonding_duration()
|
||||||
);
|
);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the given account's preference for slashing behaviour should they be a validator.
|
/// Set the given account's preference for slashing behaviour should they be a validator.
|
||||||
@@ -190,7 +186,7 @@ decl_module! {
|
|||||||
origin,
|
origin,
|
||||||
intentions_index: Compact<u32>,
|
intentions_index: Compact<u32>,
|
||||||
prefs: ValidatorPrefs<T::Balance>
|
prefs: ValidatorPrefs<T::Balance>
|
||||||
) -> Result {
|
) {
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
let intentions_index: u32 = intentions_index.into();
|
let intentions_index: u32 = intentions_index.into();
|
||||||
|
|
||||||
@@ -199,27 +195,22 @@ decl_module! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<ValidatorPreferences<T>>::insert(who, prefs);
|
<ValidatorPreferences<T>>::insert(who, prefs);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the number of sessions in an era.
|
/// Set the number of sessions in an era.
|
||||||
fn set_sessions_per_era(new: <T::BlockNumber as HasCompact>::Type) -> Result {
|
fn set_sessions_per_era(new: <T::BlockNumber as HasCompact>::Type) {
|
||||||
<NextSessionsPerEra<T>>::put(new.into());
|
<NextSessionsPerEra<T>>::put(new.into());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The length of the bonding duration in eras.
|
/// The length of the bonding duration in eras.
|
||||||
fn set_bonding_duration(new: <T::BlockNumber as HasCompact>::Type) -> Result {
|
fn set_bonding_duration(new: <T::BlockNumber as HasCompact>::Type) {
|
||||||
<BondingDuration<T>>::put(new.into());
|
<BondingDuration<T>>::put(new.into());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The ideal number of validators.
|
/// The ideal number of validators.
|
||||||
fn set_validator_count(new: Compact<u32>) -> Result {
|
fn set_validator_count(new: Compact<u32>) {
|
||||||
let new: u32 = new.into();
|
let new: u32 = new.into();
|
||||||
<ValidatorCount<T>>::put(new);
|
<ValidatorCount<T>>::put(new);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Force there to be a new era. This also forces a new session immediately after.
|
/// Force there to be a new era. This also forces a new session immediately after.
|
||||||
@@ -229,10 +220,9 @@ decl_module! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the offline slash grace period.
|
/// Set the offline slash grace period.
|
||||||
fn set_offline_slash_grace(new: Compact<u32>) -> Result {
|
fn set_offline_slash_grace(new: Compact<u32>) {
|
||||||
let new: u32 = new.into();
|
let new: u32 = new.into();
|
||||||
<OfflineSlashGrace<T>>::put(new);
|
<OfflineSlashGrace<T>>::put(new);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,9 @@ macro_rules! decl_module {
|
|||||||
{ $( $on_finalise:tt )* }
|
{ $( $on_finalise:tt )* }
|
||||||
[ $($t:tt)* ]
|
[ $($t:tt)* ]
|
||||||
$(#[doc = $doc_attr:tt])*
|
$(#[doc = $doc_attr:tt])*
|
||||||
$fn_vis:vis fn $fn_name:ident($origin:ident $(, $param_name:ident : $param:ty)* ) -> $result:ty { $( $impl:tt )* }
|
$fn_vis:vis fn $fn_name:ident(
|
||||||
|
$origin:ident $(, $param_name:ident : $param:ty)*
|
||||||
|
) $( -> $result:ty )* { $( $impl:tt )* }
|
||||||
$($rest:tt)*
|
$($rest:tt)*
|
||||||
) => {
|
) => {
|
||||||
decl_module!(@normalize
|
decl_module!(@normalize
|
||||||
@@ -179,7 +181,9 @@ macro_rules! decl_module {
|
|||||||
[
|
[
|
||||||
$($t)*
|
$($t)*
|
||||||
$(#[doc = $doc_attr])*
|
$(#[doc = $doc_attr])*
|
||||||
$fn_vis fn $fn_name($origin $( , $param_name : $param )* ) -> $result { $( $impl )* }
|
$fn_vis fn $fn_name(
|
||||||
|
$origin $( , $param_name : $param )*
|
||||||
|
) $( -> $result )* { $( $impl )* }
|
||||||
]
|
]
|
||||||
$($rest)*
|
$($rest)*
|
||||||
);
|
);
|
||||||
@@ -192,12 +196,16 @@ macro_rules! decl_module {
|
|||||||
{ $( $on_finalise:tt )* }
|
{ $( $on_finalise:tt )* }
|
||||||
[ $($t:tt)* ]
|
[ $($t:tt)* ]
|
||||||
$(#[doc = $doc_attr:tt])*
|
$(#[doc = $doc_attr:tt])*
|
||||||
$fn_vis:vis fn $fn_name:ident($origin:ident : T::Origin $(, $param_name:ident : $param:ty)* ) -> $result:ty { $( $impl:tt )* }
|
$fn_vis:vis fn $fn_name:ident(
|
||||||
|
$origin:ident : T::Origin $(, $param_name:ident : $param:ty)*
|
||||||
|
) $( -> $result:ty )* { $( $impl:tt )* }
|
||||||
$($rest:tt)*
|
$($rest:tt)*
|
||||||
) => {
|
) => {
|
||||||
compile_error!("\
|
compile_error!(
|
||||||
first parameter of dispatch should be marked `origin` only, with no type specified (a bit like `self`)\n\
|
"First parameter of dispatch should be marked `origin` only, with no type specified \
|
||||||
(For root-matching dispatches, ensure the first parameter does not use the `T::Origin` type.)")
|
(a bit like `self`). (For root-matching dispatches, ensure the first parameter does \
|
||||||
|
not use the `T::Origin` type.)"
|
||||||
|
)
|
||||||
};
|
};
|
||||||
(@normalize
|
(@normalize
|
||||||
$(#[$attr:meta])*
|
$(#[$attr:meta])*
|
||||||
@@ -207,12 +215,16 @@ first parameter of dispatch should be marked `origin` only, with no type specifi
|
|||||||
{ $( $on_finalise:tt )* }
|
{ $( $on_finalise:tt )* }
|
||||||
[ $($t:tt)* ]
|
[ $($t:tt)* ]
|
||||||
$(#[doc = $doc_attr:tt])*
|
$(#[doc = $doc_attr:tt])*
|
||||||
$fn_vis:vis fn $fn_name:ident(origin : $origin:ty $(, $param_name:ident : $param:ty)* ) -> $result:ty { $( $impl:tt )* }
|
$fn_vis:vis fn $fn_name:ident(
|
||||||
|
origin : $origin:ty $(, $param_name:ident : $param:ty)*
|
||||||
|
) $( -> $result:ty )* { $( $impl:tt )* }
|
||||||
$($rest:tt)*
|
$($rest:tt)*
|
||||||
) => {
|
) => {
|
||||||
compile_error!("\
|
compile_error!(
|
||||||
first parameter of dispatch should be marked `origin` only, with no type specified (a bit like `self`)\n\
|
"First parameter of dispatch should be marked `origin` only, with no type specified \
|
||||||
(For root-matching dispatches, ensure the first parameter is not named`origin`.)")
|
(a bit like `self`). (For root-matching dispatches, ensure the first parameter does \
|
||||||
|
not use the `T::Origin` type.)"
|
||||||
|
)
|
||||||
};
|
};
|
||||||
(@normalize
|
(@normalize
|
||||||
$(#[$attr:meta])*
|
$(#[$attr:meta])*
|
||||||
@@ -222,7 +234,9 @@ first parameter of dispatch should be marked `origin` only, with no type specifi
|
|||||||
{ $( $on_finalise:tt )* }
|
{ $( $on_finalise:tt )* }
|
||||||
[ $($t:tt)* ]
|
[ $($t:tt)* ]
|
||||||
$(#[doc = $doc_attr:tt])*
|
$(#[doc = $doc_attr:tt])*
|
||||||
$fn_vis:vis fn $fn_name:ident($( $param_name:ident : $param:ty),* ) -> $result:ty { $( $impl:tt )* }
|
$fn_vis:vis fn $fn_name:ident(
|
||||||
|
$( $param_name:ident : $param:ty),*
|
||||||
|
) $( -> $result:ty )* { $( $impl:tt )* }
|
||||||
$($rest:tt)*
|
$($rest:tt)*
|
||||||
) => {
|
) => {
|
||||||
decl_module!(@normalize
|
decl_module!(@normalize
|
||||||
@@ -234,7 +248,9 @@ first parameter of dispatch should be marked `origin` only, with no type specifi
|
|||||||
[
|
[
|
||||||
$($t)*
|
$($t)*
|
||||||
$(#[doc = $doc_attr])*
|
$(#[doc = $doc_attr])*
|
||||||
$fn_vis fn $fn_name(root $( , $param_name : $param )* ) -> $result { $( $impl )* }
|
$fn_vis fn $fn_name(
|
||||||
|
root $( , $param_name : $param )*
|
||||||
|
) $( -> $result )* { $( $impl )* }
|
||||||
]
|
]
|
||||||
$($rest)*
|
$($rest)*
|
||||||
);
|
);
|
||||||
@@ -340,7 +356,23 @@ first parameter of dispatch should be marked `origin` only, with no type specifi
|
|||||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||||
$origin_ty:ty;
|
$origin_ty:ty;
|
||||||
root;
|
root;
|
||||||
$vis:vis fn $name:ident ( root $(, $param:ident : $param_ty:ty )* ) -> $result:ty { $( $impl:tt )* }
|
$vis:vis fn $name:ident ( root $(, $param:ident : $param_ty:ty )* ) { $( $impl:tt )* }
|
||||||
|
) => {
|
||||||
|
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||||
|
$vis fn $name($( $param: $param_ty ),* ) -> $crate::dispatch::Result {
|
||||||
|
{ $( $impl )* }
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(@impl_function
|
||||||
|
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||||
|
$origin_ty:ty;
|
||||||
|
root;
|
||||||
|
$vis:vis fn $name:ident (
|
||||||
|
root $(, $param:ident : $param_ty:ty )*
|
||||||
|
) -> $result:ty { $( $impl:tt )* }
|
||||||
) => {
|
) => {
|
||||||
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||||
$vis fn $name($( $param: $param_ty ),* ) -> $result {
|
$vis fn $name($( $param: $param_ty ),* ) -> $result {
|
||||||
@@ -348,11 +380,32 @@ first parameter of dispatch should be marked `origin` only, with no type specifi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
(@impl_function
|
(@impl_function
|
||||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||||
$origin_ty:ty;
|
$origin_ty:ty;
|
||||||
$ignore:ident;
|
$ignore:ident;
|
||||||
$vis:vis fn $name:ident ( $origin:ident $(, $param:ident : $param_ty:ty )* ) -> $result:ty { $( $impl:tt )* }
|
$vis:vis fn $name:ident (
|
||||||
|
$origin:ident $(, $param:ident : $param_ty:ty )*
|
||||||
|
) { $( $impl:tt )* }
|
||||||
|
) => {
|
||||||
|
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||||
|
$vis fn $name(
|
||||||
|
$origin: $origin_ty $(, $param: $param_ty )*
|
||||||
|
) -> $crate::dispatch::Result {
|
||||||
|
{ $( $impl )* }
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(@impl_function
|
||||||
|
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||||
|
$origin_ty:ty;
|
||||||
|
$ignore:ident;
|
||||||
|
$vis:vis fn $name:ident (
|
||||||
|
$origin:ident $(, $param:ident : $param_ty:ty )*
|
||||||
|
) -> $result:ty { $( $impl:tt )* }
|
||||||
) => {
|
) => {
|
||||||
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||||
$vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result {
|
$vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result {
|
||||||
@@ -369,7 +422,7 @@ first parameter of dispatch should be marked `origin` only, with no type specifi
|
|||||||
$(#[doc = $doc_attr:tt])*
|
$(#[doc = $doc_attr:tt])*
|
||||||
$fn_vis:vis fn $fn_name:ident(
|
$fn_vis:vis fn $fn_name:ident(
|
||||||
$from:ident $( , $param_name:ident : $param:ty)*
|
$from:ident $( , $param_name:ident : $param:ty)*
|
||||||
) -> $result:ty { $( $impl:tt )* }
|
) $( -> $result:ty )* { $( $impl:tt )* }
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
{ $( $deposit_event:tt )* }
|
{ $( $deposit_event:tt )* }
|
||||||
@@ -409,7 +462,9 @@ first parameter of dispatch should be marked `origin` only, with no type specifi
|
|||||||
$mod_type<$trait_instance: $trait_name>;
|
$mod_type<$trait_instance: $trait_name>;
|
||||||
$origin_type;
|
$origin_type;
|
||||||
$from;
|
$from;
|
||||||
$fn_vis fn $fn_name ($from $(, $param_name : $param )* ) -> $result { $( $impl )* }
|
$fn_vis fn $fn_name (
|
||||||
|
$from $(, $param_name : $param )*
|
||||||
|
) $( -> $result )* { $( $impl )* }
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
|
||||||
@@ -542,7 +597,7 @@ first parameter of dispatch should be marked `origin` only, with no type specifi
|
|||||||
}
|
}
|
||||||
__dispatch_impl_metadata! {
|
__dispatch_impl_metadata! {
|
||||||
$mod_type $trait_instance $trait_name $call_type $origin_type
|
$mod_type $trait_instance $trait_name $call_type $origin_type
|
||||||
{$( $(#[doc = $doc_attr])* fn $fn_name($from $(, $param_name : $param )*) -> $result; )*}
|
{$( $(#[doc = $doc_attr])* fn $fn_name($from $(, $param_name : $param )*); )*}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -764,13 +819,13 @@ macro_rules! __call_to_metadata {
|
|||||||
$(
|
$(
|
||||||
, $param_name:ident : $param:ty
|
, $param_name:ident : $param:ty
|
||||||
)*
|
)*
|
||||||
) -> $result:ty;
|
);
|
||||||
)*}
|
)*}
|
||||||
) => {
|
) => {
|
||||||
$crate::dispatch::CallMetadata {
|
$crate::dispatch::CallMetadata {
|
||||||
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($call_type)),
|
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($call_type)),
|
||||||
functions: __functions_to_metadata!(0; $origin_type;; $(
|
functions: __functions_to_metadata!(0; $origin_type;; $(
|
||||||
fn $fn_name( $( $param_name: $param ),* ) -> $result;
|
fn $fn_name( $( $param_name: $param ),* );
|
||||||
$( $doc_attr ),*;
|
$( $doc_attr ),*;
|
||||||
)*),
|
)*),
|
||||||
}
|
}
|
||||||
@@ -789,14 +844,14 @@ macro_rules! __functions_to_metadata{
|
|||||||
$(
|
$(
|
||||||
$param_name:ident : $param:ty
|
$param_name:ident : $param:ty
|
||||||
),*
|
),*
|
||||||
) -> $result:ty;
|
);
|
||||||
$( $fn_doc:expr ),*;
|
$( $fn_doc:expr ),*;
|
||||||
$( $rest:tt )*
|
$( $rest:tt )*
|
||||||
) => {
|
) => {
|
||||||
__functions_to_metadata!(
|
__functions_to_metadata!(
|
||||||
$fn_id + 1; $origin_type;
|
$fn_id + 1; $origin_type;
|
||||||
$( $function_metadata, )* __function_to_metadata!(
|
$( $function_metadata, )* __function_to_metadata!(
|
||||||
fn $fn_name($( $param_name : $param ),*) -> $result; $( $fn_doc ),*; $fn_id;
|
fn $fn_name($( $param_name : $param ),*); $( $fn_doc ),*; $fn_id;
|
||||||
);
|
);
|
||||||
$($rest)*
|
$($rest)*
|
||||||
)
|
)
|
||||||
@@ -817,7 +872,7 @@ macro_rules! __function_to_metadata {
|
|||||||
(
|
(
|
||||||
fn $fn_name:ident(
|
fn $fn_name:ident(
|
||||||
$($param_name:ident : $param:ty),*
|
$($param_name:ident : $param:ty),*
|
||||||
) -> $result:ty;
|
);
|
||||||
$( $fn_doc:expr ),*;
|
$( $fn_doc:expr ),*;
|
||||||
$fn_id:expr;
|
$fn_id:expr;
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ extern crate parity_codec as codec;
|
|||||||
|
|
||||||
use codec::HasCompact;
|
use codec::HasCompact;
|
||||||
use runtime_support::{StorageValue, Parameter};
|
use runtime_support::{StorageValue, Parameter};
|
||||||
use runtime_support::dispatch::Result;
|
|
||||||
use runtime_primitives::CheckInherentError;
|
use runtime_primitives::CheckInherentError;
|
||||||
use runtime_primitives::traits::{
|
use runtime_primitives::traits::{
|
||||||
As, SimpleArithmetic, Zero, ProvideInherent, Block as BlockT, Extrinsic
|
As, SimpleArithmetic, Zero, ProvideInherent, Block as BlockT, Extrinsic
|
||||||
@@ -75,7 +74,7 @@ decl_module! {
|
|||||||
/// if this call hasn't been invoked by that time.
|
/// if this call hasn't been invoked by that time.
|
||||||
///
|
///
|
||||||
/// The timestamp should be greater than the previous one by the amount specified by `block_period`.
|
/// The timestamp should be greater than the previous one by the amount specified by `block_period`.
|
||||||
fn set(origin, now: <T::Moment as HasCompact>::Type) -> Result {
|
fn set(origin, now: <T::Moment as HasCompact>::Type) {
|
||||||
ensure_inherent(origin)?;
|
ensure_inherent(origin)?;
|
||||||
let now = now.into();
|
let now = now.into();
|
||||||
|
|
||||||
@@ -91,7 +90,6 @@ decl_module! {
|
|||||||
);
|
);
|
||||||
<Self as Store>::Now::put(now);
|
<Self as Store>::Now::put(now);
|
||||||
<Self as Store>::DidUpdate::put(true);
|
<Self as Store>::DidUpdate::put(true);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_finalise() {
|
fn on_finalise() {
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ extern crate srml_balances as balances;
|
|||||||
|
|
||||||
use rstd::prelude::*;
|
use rstd::prelude::*;
|
||||||
use runtime_support::{StorageValue, StorageMap};
|
use runtime_support::{StorageValue, StorageMap};
|
||||||
use runtime_support::dispatch::Result;
|
|
||||||
use runtime_primitives::{Permill, traits::{Zero, EnsureOrigin}};
|
use runtime_primitives::{Permill, traits::{Zero, EnsureOrigin}};
|
||||||
use codec::{HasCompact, Compact};
|
use codec::{HasCompact, Compact};
|
||||||
use balances::{OnDilution, address::Address};
|
use balances::{OnDilution, address::Address};
|
||||||
@@ -77,7 +76,7 @@ decl_module! {
|
|||||||
origin,
|
origin,
|
||||||
value: <T::Balance as HasCompact>::Type,
|
value: <T::Balance as HasCompact>::Type,
|
||||||
beneficiary: Address<T::AccountId, T::AccountIndex>
|
beneficiary: Address<T::AccountId, T::AccountIndex>
|
||||||
) -> Result {
|
) {
|
||||||
let proposer = ensure_signed(origin)?;
|
let proposer = ensure_signed(origin)?;
|
||||||
let beneficiary = <balances::Module<T>>::lookup(beneficiary)?;
|
let beneficiary = <balances::Module<T>>::lookup(beneficiary)?;
|
||||||
let value = value.into();
|
let value = value.into();
|
||||||
@@ -91,17 +90,12 @@ decl_module! {
|
|||||||
<Proposals<T>>::insert(c, Proposal { proposer, value, beneficiary, bond });
|
<Proposals<T>>::insert(c, Proposal { proposer, value, beneficiary, bond });
|
||||||
|
|
||||||
Self::deposit_event(RawEvent::Proposed(c));
|
Self::deposit_event(RawEvent::Proposed(c));
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the balance of funds available to spend.
|
/// 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.
|
// Put the new value into storage.
|
||||||
<Pot<T>>::put(new_pot.into());
|
<Pot<T>>::put(new_pot.into());
|
||||||
|
|
||||||
// All good.
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (Re-)configure this module.
|
/// (Re-)configure this module.
|
||||||
@@ -110,16 +104,15 @@ decl_module! {
|
|||||||
proposal_bond_minimum: <T::Balance as HasCompact>::Type,
|
proposal_bond_minimum: <T::Balance as HasCompact>::Type,
|
||||||
spend_period: <T::BlockNumber as HasCompact>::Type,
|
spend_period: <T::BlockNumber as HasCompact>::Type,
|
||||||
burn: Permill
|
burn: Permill
|
||||||
) -> Result {
|
) {
|
||||||
<ProposalBond<T>>::put(proposal_bond);
|
<ProposalBond<T>>::put(proposal_bond);
|
||||||
<ProposalBondMinimum<T>>::put(proposal_bond_minimum.into());
|
<ProposalBondMinimum<T>>::put(proposal_bond_minimum.into());
|
||||||
<SpendPeriod<T>>::put(spend_period.into());
|
<SpendPeriod<T>>::put(spend_period.into());
|
||||||
<Burn<T>>::put(burn);
|
<Burn<T>>::put(burn);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reject a proposed spend. The original deposit will be slashed.
|
/// 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)?;
|
T::RejectOrigin::ensure_origin(origin)?;
|
||||||
let proposal_id: ProposalIndex = proposal_id.into();
|
let proposal_id: ProposalIndex = proposal_id.into();
|
||||||
|
|
||||||
@@ -127,21 +120,17 @@ decl_module! {
|
|||||||
|
|
||||||
let value = proposal.bond;
|
let value = proposal.bond;
|
||||||
let _ = <balances::Module<T>>::slash_reserved(&proposal.proposer, value);
|
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
|
/// Approve a proposal. At a later time, the proposal will be allocated to the beneficiary
|
||||||
/// and the original deposit will be returned.
|
/// 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)?;
|
T::ApproveOrigin::ensure_origin(origin)?;
|
||||||
let proposal_id = proposal_id.into();
|
let proposal_id = proposal_id.into();
|
||||||
|
|
||||||
ensure!(<Proposals<T>>::exists(proposal_id), "No proposal at that index");
|
ensure!(<Proposals<T>>::exists(proposal_id), "No proposal at that index");
|
||||||
|
|
||||||
<Approvals<T>>::mutate(|v| v.push(proposal_id));
|
<Approvals<T>>::mutate(|v| v.push(proposal_id));
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_finalise(n: T::BlockNumber) {
|
fn on_finalise(n: T::BlockNumber) {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ extern crate srml_system as system;
|
|||||||
extern crate srml_consensus as consensus;
|
extern crate srml_consensus as consensus;
|
||||||
|
|
||||||
use sr_std::prelude::*;
|
use sr_std::prelude::*;
|
||||||
use support::{StorageValue, dispatch::Result};
|
use support::StorageValue;
|
||||||
use system::ensure_signed;
|
use system::ensure_signed;
|
||||||
|
|
||||||
pub trait Trait: consensus::Trait + system::Trait {
|
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.
|
// 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 {
|
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||||
fn deposit_event() = default;
|
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.
|
// This is a public call, so we ensure that the origin is some signed account.
|
||||||
let _sender = ensure_signed(origin)?;
|
let _sender = ensure_signed(origin)?;
|
||||||
ensure!(_sender == Self::key(), "only the current upgrade key can use the upgrade_key module");
|
ensure!(_sender == Self::key(), "only the current upgrade key can use the upgrade_key module");
|
||||||
|
|
||||||
<consensus::Module<T>>::set_code(new)?;
|
<consensus::Module<T>>::set_code(new)?;
|
||||||
Self::deposit_event(RawEvent::Upgraded);
|
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.
|
// This is a public call, so we ensure that the origin is some signed account.
|
||||||
let _sender = ensure_signed(origin)?;
|
let _sender = ensure_signed(origin)?;
|
||||||
ensure!(_sender == Self::key(), "only the current upgrade key can use the upgrade_key module");
|
ensure!(_sender == Self::key(), "only the current upgrade key can use the upgrade_key module");
|
||||||
|
|
||||||
Self::deposit_event(RawEvent::KeyChanged(Self::key()));
|
Self::deposit_event(RawEvent::KeyChanged(Self::key()));
|
||||||
<Key<T>>::put(new);
|
<Key<T>>::put(new);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user