diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index f92ca963bb62d..3732adfb9a78d 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1131,7 +1131,7 @@ construct_runtime!( ElectionProviderMultiPhase: pallet_election_provider_multi_phase::{Pallet, Call, Storage, Event, ValidateUnsigned}, Staking: pallet_staking::{Pallet, Call, Config, Storage, Event}, Session: pallet_session::{Pallet, Call, Storage, Event, Config}, - Democracy: pallet_democracy::{Pallet, Call, Storage, Config, Event}, + Democracy: pallet_democracy::{Pallet, Call, Storage, Config, Event}, Council: pallet_collective::::{Pallet, Call, Storage, Origin, Event, Config}, TechnicalCommittee: pallet_collective::::{Pallet, Call, Storage, Origin, Event, Config}, Elections: pallet_elections_phragmen::{Pallet, Call, Storage, Event, Config}, diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 2e7af74b22d5c..6cf35553f5367 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -21,9 +21,8 @@ use super::*; use frame_benchmarking::{benchmarks, account, whitelist_account, impl_benchmark_test_suite}; use frame_support::{ - assert_noop, assert_ok, IterableStorageMap, - traits::{Currency, Get, EnsureOrigin, OnInitialize, UnfilteredDispatchable, - schedule::DispatchTime}, + assert_noop, assert_ok, + traits::{Currency, Get, EnsureOrigin, OnInitialize, UnfilteredDispatchable, schedule::DispatchTime}, }; use frame_system::{RawOrigin, Pallet as System, self}; use sp_runtime::traits::{Bounded, One}; @@ -69,13 +68,13 @@ fn add_referendum(n: u32) -> Result { vote_threshold, 0u32.into(), ); - let referendum_index: ReferendumIndex = ReferendumCount::get() - 1; + let referendum_index: ReferendumIndex = ReferendumCount::::get() - 1; T::Scheduler::schedule_named( (DEMOCRACY_ID, referendum_index).encode(), DispatchTime::At(1u32.into()), None, 63, - system::RawOrigin::Root.into(), + frame_system::RawOrigin::Root.into(), Call::enact_proposal(proposal_hash, referendum_index).into(), ).map_err(|_| "failed to schedule named")?; Ok(referendum_index) @@ -360,7 +359,7 @@ benchmarks! { assert_eq!(Democracy::::referendum_count(), r, "referenda not created"); // Launch external - LastTabledWasExternal::put(false); + LastTabledWasExternal::::put(false); let origin = T::ExternalMajorityOrigin::successful_origin(); let proposal_hash = T::Hashing::hash_of(&r); @@ -402,7 +401,7 @@ benchmarks! { // Launch public assert!(add_proposal::(r).is_ok(), "proposal not created"); - LastTabledWasExternal::put(true); + LastTabledWasExternal::::put(true); let block_number = T::LaunchPeriod::get(); @@ -760,7 +759,7 @@ benchmarks! { }: enact_proposal(RawOrigin::Root, proposal_hash, 0) verify { // Fails due to mismatched origin - assert_last_event::(RawEvent::Executed(0, false).into()); + assert_last_event::(Event::::Executed(0, false).into()); } #[extra] diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 6fdff1aa5a6a9..70b943bf00d54 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -159,15 +159,12 @@ use sp_runtime::{ }; use codec::{Encode, Decode, Input}; use frame_support::{ - decl_module, decl_storage, decl_event, decl_error, ensure, Parameter, - weights::{Weight, DispatchClass, Pays}, + ensure, weights::Weight, traits::{ Currency, ReservableCurrency, LockableCurrency, WithdrawReasons, LockIdentifier, Get, - OnUnbalanced, BalanceStatus, schedule::{Named as ScheduleNamed, DispatchTime}, EnsureOrigin + OnUnbalanced, BalanceStatus, schedule::{Named as ScheduleNamed, DispatchTime}, }, - dispatch::DispatchResultWithPostInfo, }; -use frame_system::{self as system, ensure_signed, ensure_root}; mod vote_threshold; mod vote; @@ -179,6 +176,7 @@ pub use vote_threshold::{Approved, VoteThreshold}; pub use vote::{Vote, AccountVote, Voting}; pub use conviction::Conviction; pub use types::{ReferendumInfo, ReferendumStatus, Tally, UnvoteScope, Delegations}; +pub use pallet::*; #[cfg(test)] mod tests; @@ -203,108 +201,6 @@ type BalanceOf = <::Currency as Currency< = <::Currency as Currency<::AccountId>>::NegativeImbalance; -pub trait Config: frame_system::Config + Sized { - type Proposal: Parameter + Dispatchable + From>; - type Event: From> + Into<::Event>; - - /// Currency type for this module. - type Currency: ReservableCurrency - + LockableCurrency; - - /// The minimum period of locking and the period between a proposal being approved and enacted. - /// - /// It should generally be a little more than the unstake period to ensure that - /// voting stakers have an opportunity to remove themselves from the system in the case where - /// they are on the losing side of a vote. - type EnactmentPeriod: Get; - - /// How often (in blocks) new public referenda are launched. - type LaunchPeriod: Get; - - /// How often (in blocks) to check for new votes. - type VotingPeriod: Get; - - /// The minimum amount to be used as a deposit for a public referendum proposal. - type MinimumDeposit: Get>; - - /// Origin from which the next tabled referendum may be forced. This is a normal - /// "super-majority-required" referendum. - type ExternalOrigin: EnsureOrigin; - - /// Origin from which the next tabled referendum may be forced; this allows for the tabling of - /// a majority-carries referendum. - type ExternalMajorityOrigin: EnsureOrigin; - - /// Origin from which the next tabled referendum may be forced; this allows for the tabling of - /// a negative-turnout-bias (default-carries) referendum. - type ExternalDefaultOrigin: EnsureOrigin; - - /// Origin from which the next majority-carries (or more permissive) referendum may be tabled to - /// vote according to the `FastTrackVotingPeriod` asynchronously in a similar manner to the - /// emergency origin. It retains its threshold method. - type FastTrackOrigin: EnsureOrigin; - - /// Origin from which the next majority-carries (or more permissive) referendum may be tabled to - /// vote immediately and asynchronously in a similar manner to the emergency origin. It retains - /// its threshold method. - type InstantOrigin: EnsureOrigin; - - /// Indicator for whether an emergency origin is even allowed to happen. Some chains may want - /// to set this permanently to `false`, others may want to condition it on things such as - /// an upgrade having happened recently. - type InstantAllowed: Get; - - /// Minimum voting period allowed for a fast-track referendum. - type FastTrackVotingPeriod: Get; - - /// Origin from which any referendum may be cancelled in an emergency. - type CancellationOrigin: EnsureOrigin; - - /// Origin from which proposals may be blacklisted. - type BlacklistOrigin: EnsureOrigin; - - /// Origin from which a proposal may be cancelled and its backers slashed. - type CancelProposalOrigin: EnsureOrigin; - - /// Origin for anyone able to veto proposals. - /// - /// # Warning - /// - /// The number of Vetoers for a proposal must be small, extrinsics are weighted according to - /// [MAX_VETOERS](./const.MAX_VETOERS.html) - type VetoOrigin: EnsureOrigin; - - /// Period in blocks where an external proposal may not be re-submitted after being vetoed. - type CooloffPeriod: Get; - - /// The amount of balance that must be deposited per byte of preimage stored. - type PreimageByteDeposit: Get>; - - /// An origin that can provide a preimage using operational extrinsics. - type OperationalPreimageOrigin: EnsureOrigin; - - /// Handler for the unbalanced reduction when slashing a preimage deposit. - type Slash: OnUnbalanced>; - - /// The Scheduler. - type Scheduler: ScheduleNamed; - - /// Overarching type of all pallets origins. - type PalletsOrigin: From>; - - /// The maximum number of votes for an account. - /// - /// Also used to compute weight, an overly big value can - /// lead to extrinsic with very big weight: see `delegate` for instance. - type MaxVotes: Get; - - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; - - /// The maximum number of public proposals that can exist at any time. - type MaxProposals: Get; -} - #[derive(Clone, Encode, Decode, RuntimeDebug)] pub enum PreimageStatus { /// The preimage is imminently needed at the argument. @@ -337,90 +233,273 @@ enum Releases { V1, } -decl_storage! { - trait Store for Module as Democracy { - // TODO: Refactor public proposal queue into its own pallet. - // https://github.com/paritytech/substrate/issues/5322 - /// The number of (public) proposals that have been made so far. - pub PublicPropCount get(fn public_prop_count) build(|_| 0 as PropIndex) : PropIndex; - /// The public proposals. Unsorted. The second item is the proposal's hash. - pub PublicProps get(fn public_props): Vec<(PropIndex, T::Hash, T::AccountId)>; - /// Those who have locked a deposit. - /// - /// TWOX-NOTE: Safe, as increasing integer keys are safe. - pub DepositOf get(fn deposit_of): - map hasher(twox_64_concat) PropIndex => Option<(Vec, BalanceOf)>; - - /// Map of hashes to the proposal preimage, along with who registered it and their deposit. - /// The block number is the block at which it was deposited. - // TODO: Refactor Preimages into its own pallet. - // https://github.com/paritytech/substrate/issues/5322 - pub Preimages: - map hasher(identity) T::Hash - => Option, T::BlockNumber>>; - - /// The next free referendum index, aka the number of referenda started so far. - pub ReferendumCount get(fn referendum_count) build(|_| 0 as ReferendumIndex): ReferendumIndex; - /// The lowest referendum index representing an unbaked referendum. Equal to - /// `ReferendumCount` if there isn't a unbaked referendum. - pub LowestUnbaked get(fn lowest_unbaked) build(|_| 0 as ReferendumIndex): ReferendumIndex; - - /// Information concerning any given referendum. - /// - /// TWOX-NOTE: SAFE as indexes are not under an attacker’s control. - pub ReferendumInfoOf get(fn referendum_info): - map hasher(twox_64_concat) ReferendumIndex - => Option>>; - - /// All votes for a particular voter. We store the balance for the number of votes that we - /// have recorded. The second item is the total amount of delegations, that will be added. - /// - /// TWOX-NOTE: SAFE as `AccountId`s are crypto hashes anyway. - pub VotingOf: map hasher(twox_64_concat) T::AccountId => Voting, T::AccountId, T::BlockNumber>; - - /// Accounts for which there are locks in action which may be removed at some point in the - /// future. The value is the block number at which the lock expires and may be removed. - /// - /// TWOX-NOTE: OK ― `AccountId` is a secure hash. - pub Locks get(fn locks): map hasher(twox_64_concat) T::AccountId => Option; - - /// True if the last referendum tabled was submitted externally. False if it was a public - /// proposal. - // TODO: There should be any number of tabling origins, not just public and "external" (council). - // https://github.com/paritytech/substrate/issues/5322 - pub LastTabledWasExternal: bool; - - /// The referendum to be tabled whenever it would be valid to table an external proposal. - /// This happens when a referendum needs to be tabled and one of two conditions are met: - /// - `LastTabledWasExternal` is `false`; or - /// - `PublicProps` is empty. - pub NextExternal: Option<(T::Hash, VoteThreshold)>; - - /// A record of who vetoed what. Maps proposal hash to a possible existent block number - /// (until when it may not be resubmitted) and who vetoed it. - pub Blacklist: map hasher(identity) T::Hash => Option<(T::BlockNumber, Vec)>; - - /// Record of all proposals that have been subject to emergency cancellation. - pub Cancellations: map hasher(identity) T::Hash => bool; - - /// Storage version of the pallet. - /// - /// New networks start with last version. - StorageVersion build(|_| Some(Releases::V1)): Option; +#[frame_support::pallet] +pub mod pallet { + use sp_runtime::DispatchResult; + use frame_support::{ + pallet_prelude::*, Parameter, + weights::{DispatchClass, Pays}, traits::EnsureOrigin, dispatch::DispatchResultWithPostInfo, + }; + use frame_system::{pallet_prelude::*, ensure_signed, ensure_root}; + use super::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config + Sized { + type Proposal: Parameter + Dispatchable + From>; + type Event: From> + IsType<::Event>; + + /// Currency type for this pallet. + type Currency: ReservableCurrency + + LockableCurrency; + + /// The minimum period of locking and the period between a proposal being approved and enacted. + /// + /// It should generally be a little more than the unstake period to ensure that + /// voting stakers have an opportunity to remove themselves from the system in the case where + /// they are on the losing side of a vote. + #[pallet::constant] + type EnactmentPeriod: Get; + + /// How often (in blocks) new public referenda are launched. + #[pallet::constant] + type LaunchPeriod: Get; + + /// How often (in blocks) to check for new votes. + #[pallet::constant] + type VotingPeriod: Get; + + /// The minimum amount to be used as a deposit for a public referendum proposal. + #[pallet::constant] + type MinimumDeposit: Get>; + + /// Origin from which the next tabled referendum may be forced. This is a normal + /// "super-majority-required" referendum. + type ExternalOrigin: EnsureOrigin; + + /// Origin from which the next tabled referendum may be forced; this allows for the tabling of + /// a majority-carries referendum. + type ExternalMajorityOrigin: EnsureOrigin; + + /// Origin from which the next tabled referendum may be forced; this allows for the tabling of + /// a negative-turnout-bias (default-carries) referendum. + type ExternalDefaultOrigin: EnsureOrigin; + + /// Origin from which the next majority-carries (or more permissive) referendum may be tabled to + /// vote according to the `FastTrackVotingPeriod` asynchronously in a similar manner to the + /// emergency origin. It retains its threshold method. + type FastTrackOrigin: EnsureOrigin; + + /// Origin from which the next majority-carries (or more permissive) referendum may be tabled to + /// vote immediately and asynchronously in a similar manner to the emergency origin. It retains + /// its threshold method. + type InstantOrigin: EnsureOrigin; + + /// Indicator for whether an emergency origin is even allowed to happen. Some chains may want + /// to set this permanently to `false`, others may want to condition it on things such as + /// an upgrade having happened recently. + type InstantAllowed: Get; + + /// Minimum voting period allowed for a fast-track referendum. + #[pallet::constant] + type FastTrackVotingPeriod: Get; + + /// Origin from which any referendum may be cancelled in an emergency. + type CancellationOrigin: EnsureOrigin; + + /// Origin from which proposals may be blacklisted. + type BlacklistOrigin: EnsureOrigin; + + /// Origin from which a proposal may be cancelled and its backers slashed. + type CancelProposalOrigin: EnsureOrigin; + + /// Origin for anyone able to veto proposals. + /// + /// # Warning + /// + /// The number of Vetoers for a proposal must be small, extrinsics are weighted according to + /// [MAX_VETOERS](./const.MAX_VETOERS.html) + type VetoOrigin: EnsureOrigin; + + /// Period in blocks where an external proposal may not be re-submitted after being vetoed. + #[pallet::constant] + type CooloffPeriod: Get; + + /// The amount of balance that must be deposited per byte of preimage stored. + #[pallet::constant] + type PreimageByteDeposit: Get>; + + /// An origin that can provide a preimage using operational extrinsics. + type OperationalPreimageOrigin: EnsureOrigin; + + /// Handler for the unbalanced reduction when slashing a preimage deposit. + type Slash: OnUnbalanced>; + + /// The Scheduler. + type Scheduler: ScheduleNamed; + + /// Overarching type of all pallets origins. + type PalletsOrigin: From>; + + /// The maximum number of votes for an account. + /// + /// Also used to compute weight, an overly big value can + /// lead to extrinsic with very big weight: see `delegate` for instance. + #[pallet::constant] + type MaxVotes: Get; + + /// Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; + + /// The maximum number of public proposals that can exist at any time. + type MaxProposals: Get; } -} -decl_event! { - pub enum Event where - Balance = BalanceOf, - ::AccountId, - ::Hash, - ::BlockNumber, - { + // TODO: Refactor public proposal queue into its own pallet. + // https://github.com/paritytech/substrate/issues/5322 + /// The number of (public) proposals that have been made so far. + #[pallet::storage] + #[pallet::getter(fn public_prop_count)] + pub type PublicPropCount = StorageValue<_, PropIndex, ValueQuery>; + + /// The public proposals. Unsorted. The second item is the proposal's hash. + #[pallet::storage] + #[pallet::getter(fn public_props)] + pub type PublicProps = StorageValue<_, Vec<(PropIndex, T::Hash, T::AccountId)>, ValueQuery>; + + /// Those who have locked a deposit. + /// + /// TWOX-NOTE: Safe, as increasing integer keys are safe. + #[pallet::storage] + #[pallet::getter(fn deposit_of)] + pub type DepositOf = StorageMap< + _, + Twox64Concat, PropIndex, + (Vec, BalanceOf), + >; + + /// Map of hashes to the proposal preimage, along with who registered it and their deposit. + /// The block number is the block at which it was deposited. + // TODO: Refactor Preimages into its own pallet. + // https://github.com/paritytech/substrate/issues/5322 + #[pallet::storage] + pub type Preimages = StorageMap< + _, + Identity, T::Hash, + PreimageStatus, T::BlockNumber>, + >; + + /// The next free referendum index, aka the number of referenda started so far. + #[pallet::storage] + #[pallet::getter(fn referendum_count)] + pub type ReferendumCount = StorageValue<_, ReferendumIndex, ValueQuery>; + + /// The lowest referendum index representing an unbaked referendum. Equal to + /// `ReferendumCount` if there isn't a unbaked referendum. + #[pallet::storage] + #[pallet::getter(fn lowest_unbaked)] + pub type LowestUnbaked = StorageValue<_, ReferendumIndex, ValueQuery>; + + /// Information concerning any given referendum. + /// + /// TWOX-NOTE: SAFE as indexes are not under an attacker’s control. + #[pallet::storage] + #[pallet::getter(fn referendum_info)] + pub type ReferendumInfoOf = StorageMap< + _, + Twox64Concat, ReferendumIndex, + ReferendumInfo>, + >; + + /// All votes for a particular voter. We store the balance for the number of votes that we + /// have recorded. The second item is the total amount of delegations, that will be added. + /// + /// TWOX-NOTE: SAFE as `AccountId`s are crypto hashes anyway. + #[pallet::storage] + pub type VotingOf = StorageMap< + _, Twox64Concat, T::AccountId, + Voting, T::AccountId, T::BlockNumber>, + ValueQuery, + >; + + /// Accounts for which there are locks in action which may be removed at some point in the + /// future. The value is the block number at which the lock expires and may be removed. + /// + /// TWOX-NOTE: OK ― `AccountId` is a secure hash. + #[pallet::storage] + #[pallet::getter(fn locks)] + pub type Locks = StorageMap<_, Twox64Concat, T::AccountId, T::BlockNumber>; + + /// True if the last referendum tabled was submitted externally. False if it was a public + /// proposal. + // TODO: There should be any number of tabling origins, not just public and "external" (council). + // https://github.com/paritytech/substrate/issues/5322 + #[pallet::storage] + pub type LastTabledWasExternal = StorageValue<_, bool, ValueQuery>; + + /// The referendum to be tabled whenever it would be valid to table an external proposal. + /// This happens when a referendum needs to be tabled and one of two conditions are met: + /// - `LastTabledWasExternal` is `false`; or + /// - `PublicProps` is empty. + #[pallet::storage] + pub type NextExternal = StorageValue<_, (T::Hash, VoteThreshold)>; + + /// A record of who vetoed what. Maps proposal hash to a possible existent block number + /// (until when it may not be resubmitted) and who vetoed it. + #[pallet::storage] + pub type Blacklist = StorageMap<_, Identity, T::Hash, (T::BlockNumber, Vec)>; + + /// Record of all proposals that have been subject to emergency cancellation. + #[pallet::storage] + pub type Cancellations = StorageMap<_, Identity, T::Hash, bool, ValueQuery>; + + /// Storage version of the pallet. + /// + /// New networks start with last version. + #[pallet::storage] + pub(crate) type StorageVersion = StorageValue<_, Releases>; + + #[pallet::genesis_config] + pub struct GenesisConfig { + _phantom: sp_std::marker::PhantomData, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + GenesisConfig { + _phantom: Default::default(), + } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + PublicPropCount::::put(0 as PropIndex); + ReferendumCount::::put(0 as ReferendumIndex); + LowestUnbaked::::put(0 as ReferendumIndex); + StorageVersion::::put(Releases::V1); + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + #[pallet::metadata( + T::AccountId = "AccountId", + Vec = "Vec", + BalanceOf = "Balance", + T::BlockNumber = "BlockNumber", + T::Hash = "Hash", + )] + pub enum Event { /// A motion has been proposed by a public account. \[proposal_index, deposit\] - Proposed(PropIndex, Balance), + Proposed(PropIndex, BalanceOf), /// A public proposal has been tabled for referendum vote. \[proposal_index, deposit, depositors\] - Tabled(PropIndex, Balance, Vec), + Tabled(PropIndex, BalanceOf, Vec), /// An external proposal has been tabled. ExternalTabled, /// A referendum has begun. \[ref_index, threshold\] @@ -434,34 +513,33 @@ decl_event! { /// A proposal has been enacted. \[ref_index, is_ok\] Executed(ReferendumIndex, bool), /// An account has delegated their vote to another account. \[who, target\] - Delegated(AccountId, AccountId), + Delegated(T::AccountId, T::AccountId), /// An \[account\] has cancelled a previous delegation operation. - Undelegated(AccountId), + Undelegated(T::AccountId), /// An external proposal has been vetoed. \[who, proposal_hash, until\] - Vetoed(AccountId, Hash, BlockNumber), + Vetoed(T::AccountId, T::Hash, T::BlockNumber), /// A proposal's preimage was noted, and the deposit taken. \[proposal_hash, who, deposit\] - PreimageNoted(Hash, AccountId, Balance), + PreimageNoted(T::Hash, T::AccountId, BalanceOf), /// A proposal preimage was removed and used (the deposit was returned). /// \[proposal_hash, provider, deposit\] - PreimageUsed(Hash, AccountId, Balance), + PreimageUsed(T::Hash, T::AccountId, BalanceOf), /// A proposal could not be executed because its preimage was invalid. /// \[proposal_hash, ref_index\] - PreimageInvalid(Hash, ReferendumIndex), + PreimageInvalid(T::Hash, ReferendumIndex), /// A proposal could not be executed because its preimage was missing. /// \[proposal_hash, ref_index\] - PreimageMissing(Hash, ReferendumIndex), + PreimageMissing(T::Hash, ReferendumIndex), /// A registered preimage was removed and the deposit collected by the reaper. /// \[proposal_hash, provider, deposit, reaper\] - PreimageReaped(Hash, AccountId, Balance, AccountId), + PreimageReaped(T::Hash, T::AccountId, BalanceOf, T::AccountId), /// An \[account\] has been unlocked successfully. - Unlocked(AccountId), + Unlocked(T::AccountId), /// A proposal \[hash\] has been blacklisted permanently. - Blacklisted(Hash), + Blacklisted(T::Hash), } -} -decl_error! { - pub enum Error for Module { + #[pallet::error] + pub enum Error { /// Value too low ValueLow, /// Proposal does not exist @@ -530,42 +608,20 @@ decl_error! { /// Maximum number of proposals reached. TooManyProposals, } -} - -decl_module! { - pub struct Module for enum Call where origin: T::Origin { - type Error = Error; - - /// The minimum period of locking and the period between a proposal being approved and enacted. - /// - /// It should generally be a little more than the unstake period to ensure that - /// voting stakers have an opportunity to remove themselves from the system in the case where - /// they are on the losing side of a vote. - const EnactmentPeriod: T::BlockNumber = T::EnactmentPeriod::get(); - - /// How often (in blocks) new public referenda are launched. - const LaunchPeriod: T::BlockNumber = T::LaunchPeriod::get(); - - /// How often (in blocks) to check for new votes. - const VotingPeriod: T::BlockNumber = T::VotingPeriod::get(); - - /// The minimum amount to be used as a deposit for a public referendum proposal. - const MinimumDeposit: BalanceOf = T::MinimumDeposit::get(); - - /// Minimum voting period allowed for an emergency referendum. - const FastTrackVotingPeriod: T::BlockNumber = T::FastTrackVotingPeriod::get(); - /// Period in blocks where an external proposal may not be re-submitted after being vetoed. - const CooloffPeriod: T::BlockNumber = T::CooloffPeriod::get(); - - /// The amount of balance that must be deposited per byte of preimage stored. - const PreimageByteDeposit: BalanceOf = T::PreimageByteDeposit::get(); - - /// The maximum number of votes for an account. - const MaxVotes: u32 = T::MaxVotes::get(); - - fn deposit_event() = default; + #[pallet::hooks] + impl Hooks> for Pallet { + /// Weight: see `begin_block` + fn on_initialize(n: T::BlockNumber) -> Weight { + Self::begin_block(n).unwrap_or_else(|e| { + sp_runtime::print(e); + 0 + }) + } + } + #[pallet::call] + impl Pallet { /// Propose a sensitive action to be taken. /// /// The dispatch origin of this call must be _Signed_ and the sender must @@ -577,11 +633,12 @@ decl_module! { /// Emits `Proposed`. /// /// Weight: `O(p)` - #[weight = T::WeightInfo::propose()] - fn propose(origin, + #[pallet::weight(T::WeightInfo::propose())] + pub(crate) fn propose( + origin: OriginFor, proposal_hash: T::Hash, - #[compact] value: BalanceOf, - ) { + #[pallet::compact] value: BalanceOf, + ) -> DispatchResult { let who = ensure_signed(origin)?; ensure!(value >= T::MinimumDeposit::get(), Error::::ValueLow); @@ -598,12 +655,13 @@ decl_module! { } T::Currency::reserve(&who, value)?; - PublicPropCount::put(index + 1); + PublicPropCount::::put(index + 1); >::insert(index, (&[&who][..], value)); >::append((index, proposal_hash, who)); - Self::deposit_event(RawEvent::Proposed(index, value)); + Self::deposit_event(Event::::Proposed(index, value)); + Ok(()) } /// Signals agreement with a particular proposal. @@ -616,8 +674,12 @@ decl_module! { /// proposal. Extrinsic is weighted according to this value with no refund. /// /// Weight: `O(S)` where S is the number of seconds a proposal already has. - #[weight = T::WeightInfo::second(*seconds_upper_bound)] - fn second(origin, #[compact] proposal: PropIndex, #[compact] seconds_upper_bound: u32) { + #[pallet::weight(T::WeightInfo::second(*seconds_upper_bound))] + pub(crate) fn second( + origin: OriginFor, + #[pallet::compact] proposal: PropIndex, + #[pallet::compact] seconds_upper_bound: u32, + ) -> DispatchResult { let who = ensure_signed(origin)?; let seconds = Self::len_of_deposit_of(proposal) @@ -628,6 +690,7 @@ decl_module! { T::Currency::reserve(&who, deposit.1)?; deposit.0.push(who); >::insert(proposal, deposit); + Ok(()) } /// Vote in a referendum. If `vote.is_aye()`, the vote is to enact the proposal; @@ -639,10 +702,13 @@ decl_module! { /// - `vote`: The vote configuration. /// /// Weight: `O(R)` where R is the number of referendums the voter has voted on. - #[weight = T::WeightInfo::vote_new(T::MaxVotes::get()) - .max(T::WeightInfo::vote_existing(T::MaxVotes::get()))] - fn vote(origin, - #[compact] ref_index: ReferendumIndex, + #[pallet::weight( + T::WeightInfo::vote_new(T::MaxVotes::get()) + .max(T::WeightInfo::vote_existing(T::MaxVotes::get())) + )] + pub(crate) fn vote( + origin: OriginFor, + #[pallet::compact] ref_index: ReferendumIndex, vote: AccountVote>, ) -> DispatchResult { let who = ensure_signed(origin)?; @@ -657,8 +723,8 @@ decl_module! { /// -`ref_index`: The index of the referendum to cancel. /// /// Weight: `O(1)`. - #[weight = (T::WeightInfo::emergency_cancel(), DispatchClass::Operational)] - fn emergency_cancel(origin, ref_index: ReferendumIndex) { + #[pallet::weight((T::WeightInfo::emergency_cancel(), DispatchClass::Operational))] + pub(crate) fn emergency_cancel(origin: OriginFor, ref_index: ReferendumIndex) -> DispatchResult { T::CancellationOrigin::ensure_origin(origin)?; let status = Self::referendum_status(ref_index)?; @@ -667,6 +733,7 @@ decl_module! { >::insert(h, true); Self::internal_cancel_referendum(ref_index); + Ok(()) } /// Schedule a referendum to be tabled once it is legal to schedule an external @@ -678,8 +745,8 @@ decl_module! { /// /// Weight: `O(V)` with V number of vetoers in the blacklist of proposal. /// Decoding vec of length V. Charged as maximum - #[weight = T::WeightInfo::external_propose(MAX_VETOERS)] - fn external_propose(origin, proposal_hash: T::Hash) { + #[pallet::weight(T::WeightInfo::external_propose(MAX_VETOERS))] + pub(crate) fn external_propose(origin: OriginFor, proposal_hash: T::Hash) -> DispatchResult { T::ExternalOrigin::ensure_origin(origin)?; ensure!(!>::exists(), Error::::DuplicateProposal); if let Some((until, _)) = >::get(proposal_hash) { @@ -689,6 +756,7 @@ decl_module! { ); } >::put((proposal_hash, VoteThreshold::SuperMajorityApprove)); + Ok(()) } /// Schedule a majority-carries referendum to be tabled next once it is legal to schedule @@ -702,10 +770,14 @@ decl_module! { /// pre-scheduled `external_propose` call. /// /// Weight: `O(1)` - #[weight = T::WeightInfo::external_propose_majority()] - fn external_propose_majority(origin, proposal_hash: T::Hash) { + #[pallet::weight(T::WeightInfo::external_propose_majority())] + pub(crate) fn external_propose_majority( + origin: OriginFor, + proposal_hash: T::Hash, + ) -> DispatchResult { T::ExternalMajorityOrigin::ensure_origin(origin)?; >::put((proposal_hash, VoteThreshold::SimpleMajority)); + Ok(()) } /// Schedule a negative-turnout-bias referendum to be tabled next once it is legal to @@ -719,10 +791,14 @@ decl_module! { /// pre-scheduled `external_propose` call. /// /// Weight: `O(1)` - #[weight = T::WeightInfo::external_propose_default()] - fn external_propose_default(origin, proposal_hash: T::Hash) { + #[pallet::weight(T::WeightInfo::external_propose_default())] + pub(crate) fn external_propose_default( + origin: OriginFor, + proposal_hash: T::Hash, + ) -> DispatchResult { T::ExternalDefaultOrigin::ensure_origin(origin)?; >::put((proposal_hash, VoteThreshold::SuperMajorityAgainst)); + Ok(()) } /// Schedule the currently externally-proposed majority-carries referendum to be tabled @@ -740,12 +816,13 @@ decl_module! { /// Emits `Started`. /// /// Weight: `O(1)` - #[weight = T::WeightInfo::fast_track()] - fn fast_track(origin, + #[pallet::weight(T::WeightInfo::fast_track())] + pub(crate) fn fast_track( + origin: OriginFor, proposal_hash: T::Hash, voting_period: T::BlockNumber, delay: T::BlockNumber, - ) { + ) -> DispatchResult { // Rather complicated bit of code to ensure that either: // - `voting_period` is at least `FastTrackVotingPeriod` and `origin` is `FastTrackOrigin`; or // - `InstantAllowed` is `true` and `origin` is `InstantOrigin`. @@ -774,6 +851,7 @@ decl_module! { >::kill(); let now = >::block_number(); Self::inject_referendum(now + voting_period, proposal_hash, threshold, delay); + Ok(()) } /// Veto and blacklist the external proposal hash. @@ -785,8 +863,8 @@ decl_module! { /// Emits `Vetoed`. /// /// Weight: `O(V + log(V))` where V is number of `existing vetoers` - #[weight = T::WeightInfo::veto_external(MAX_VETOERS)] - fn veto_external(origin, proposal_hash: T::Hash) { + #[pallet::weight(T::WeightInfo::veto_external(MAX_VETOERS))] + pub(crate) fn veto_external(origin: OriginFor, proposal_hash: T::Hash) -> DispatchResult { let who = T::VetoOrigin::ensure_origin(origin)?; if let Some((e_proposal_hash, _)) = >::get() { @@ -805,8 +883,9 @@ decl_module! { let until = >::block_number() + T::CooloffPeriod::get(); >::insert(&proposal_hash, (until, existing_vetoers)); - Self::deposit_event(RawEvent::Vetoed(who, proposal_hash, until)); + Self::deposit_event(Event::::Vetoed(who, proposal_hash, until)); >::kill(); + Ok(()) } /// Remove a referendum. @@ -816,10 +895,14 @@ decl_module! { /// - `ref_index`: The index of the referendum to cancel. /// /// # Weight: `O(1)`. - #[weight = T::WeightInfo::cancel_referendum()] - fn cancel_referendum(origin, #[compact] ref_index: ReferendumIndex) { + #[pallet::weight(T::WeightInfo::cancel_referendum())] + pub(crate) fn cancel_referendum( + origin: OriginFor, + #[pallet::compact] ref_index: ReferendumIndex, + ) -> DispatchResult { ensure_root(origin)?; Self::internal_cancel_referendum(ref_index); + Ok(()) } /// Cancel a proposal queued for enactment. @@ -829,19 +912,12 @@ decl_module! { /// - `which`: The index of the referendum to cancel. /// /// Weight: `O(D)` where `D` is the items in the dispatch queue. Weighted as `D = 10`. - #[weight = (T::WeightInfo::cancel_queued(10), DispatchClass::Operational)] - fn cancel_queued(origin, which: ReferendumIndex) { + #[pallet::weight((T::WeightInfo::cancel_queued(10), DispatchClass::Operational))] + pub(crate) fn cancel_queued(origin: OriginFor, which: ReferendumIndex) -> DispatchResult { ensure_root(origin)?; T::Scheduler::cancel_named((DEMOCRACY_ID, which).encode()) .map_err(|_| Error::::ProposalMissing)?; - } - - /// Weight: see `begin_block` - fn on_initialize(n: T::BlockNumber) -> Weight { - Self::begin_block(n).unwrap_or_else(|e| { - sp_runtime::print(e); - 0 - }) + Ok(()) } /// Delegate the voting power (with some given conviction) of the sending account. @@ -866,9 +942,9 @@ decl_module! { /// voted on. Weight is charged as if maximum votes. // NOTE: weight must cover an incorrect voting of origin with max votes, this is ensure // because a valid delegation cover decoding a direct voting with max votes. - #[weight = T::WeightInfo::delegate(T::MaxVotes::get())] + #[pallet::weight(T::WeightInfo::delegate(T::MaxVotes::get()))] pub fn delegate( - origin, + origin: OriginFor, to: T::AccountId, conviction: Conviction, balance: BalanceOf @@ -893,8 +969,8 @@ decl_module! { /// voted on. Weight is charged as if maximum votes. // NOTE: weight must cover an incorrect voting of origin with max votes, this is ensure // because a valid delegation cover decoding a direct voting with max votes. - #[weight = T::WeightInfo::undelegate(T::MaxVotes::get().into())] - fn undelegate(origin) -> DispatchResultWithPostInfo { + #[pallet::weight(T::WeightInfo::undelegate(T::MaxVotes::get().into()))] + pub(crate) fn undelegate(origin: OriginFor) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; let votes = Self::try_undelegate(who)?; Ok(Some(T::WeightInfo::undelegate(votes)).into()) @@ -905,10 +981,11 @@ decl_module! { /// The dispatch origin of this call must be _Root_. /// /// Weight: `O(1)`. - #[weight = T::WeightInfo::clear_public_proposals()] - fn clear_public_proposals(origin) { + #[pallet::weight(T::WeightInfo::clear_public_proposals())] + pub(crate) fn clear_public_proposals(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; >::kill(); + Ok(()) } /// Register the preimage for an upcoming proposal. This doesn't require the proposal to be @@ -921,19 +998,24 @@ decl_module! { /// Emits `PreimageNoted`. /// /// Weight: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). - #[weight = T::WeightInfo::note_preimage(encoded_proposal.len() as u32)] - fn note_preimage(origin, encoded_proposal: Vec) { + #[pallet::weight(T::WeightInfo::note_preimage(encoded_proposal.len() as u32))] + pub(crate) fn note_preimage(origin: OriginFor, encoded_proposal: Vec) -> DispatchResult { Self::note_preimage_inner(ensure_signed(origin)?, encoded_proposal)?; + Ok(()) } /// Same as `note_preimage` but origin is `OperationalPreimageOrigin`. - #[weight = ( + #[pallet::weight(( T::WeightInfo::note_preimage(encoded_proposal.len() as u32), DispatchClass::Operational, - )] - fn note_preimage_operational(origin, encoded_proposal: Vec) { + ))] + pub(crate) fn note_preimage_operational( + origin: OriginFor, + encoded_proposal: Vec, + ) -> DispatchResult { let who = T::OperationalPreimageOrigin::ensure_origin(origin)?; Self::note_preimage_inner(who, encoded_proposal)?; + Ok(()) } /// Register the preimage for an upcoming proposal. This requires the proposal to be @@ -948,8 +1030,11 @@ decl_module! { /// Emits `PreimageNoted`. /// /// Weight: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). - #[weight = T::WeightInfo::note_imminent_preimage(encoded_proposal.len() as u32)] - fn note_imminent_preimage(origin, encoded_proposal: Vec) -> DispatchResultWithPostInfo { + #[pallet::weight(T::WeightInfo::note_imminent_preimage(encoded_proposal.len() as u32))] + pub(crate) fn note_imminent_preimage( + origin: OriginFor, + encoded_proposal: Vec, + ) -> DispatchResultWithPostInfo { Self::note_imminent_preimage_inner(ensure_signed(origin)?, encoded_proposal)?; // We check that this preimage was not uploaded before in `note_imminent_preimage_inner`, // thus this call can only be successful once. If successful, user does not pay a fee. @@ -957,11 +1042,14 @@ decl_module! { } /// Same as `note_imminent_preimage` but origin is `OperationalPreimageOrigin`. - #[weight = ( + #[pallet::weight(( T::WeightInfo::note_imminent_preimage(encoded_proposal.len() as u32), DispatchClass::Operational, - )] - fn note_imminent_preimage_operational(origin, encoded_proposal: Vec) -> DispatchResultWithPostInfo { + ))] + pub(crate) fn note_imminent_preimage_operational( + origin: OriginFor, + encoded_proposal: Vec, + ) -> DispatchResultWithPostInfo { let who = T::OperationalPreimageOrigin::ensure_origin(origin)?; Self::note_imminent_preimage_inner(who, encoded_proposal)?; // We check that this preimage was not uploaded before in `note_imminent_preimage_inner`, @@ -984,8 +1072,12 @@ decl_module! { /// Emits `PreimageReaped`. /// /// Weight: `O(D)` where D is length of proposal. - #[weight = T::WeightInfo::reap_preimage(*proposal_len_upper_bound)] - fn reap_preimage(origin, proposal_hash: T::Hash, #[compact] proposal_len_upper_bound: u32) { + #[pallet::weight(T::WeightInfo::reap_preimage(*proposal_len_upper_bound))] + pub(crate) fn reap_preimage( + origin: OriginFor, + proposal_hash: T::Hash, + #[pallet::compact] proposal_len_upper_bound: u32, + ) -> DispatchResult { let who = ensure_signed(origin)?; ensure!( @@ -1009,7 +1101,8 @@ decl_module! { let res = T::Currency::repatriate_reserved(&provider, &who, deposit, BalanceStatus::Free); debug_assert!(res.is_ok()); >::remove(&proposal_hash); - Self::deposit_event(RawEvent::PreimageReaped(proposal_hash, provider, deposit, who)); + Self::deposit_event(Event::::PreimageReaped(proposal_hash, provider, deposit, who)); + Ok(()) } /// Unlock tokens that have an expired lock. @@ -1019,11 +1112,14 @@ decl_module! { /// - `target`: The account to remove the lock on. /// /// Weight: `O(R)` with R number of vote of target. - #[weight = T::WeightInfo::unlock_set(T::MaxVotes::get()) - .max(T::WeightInfo::unlock_remove(T::MaxVotes::get()))] - fn unlock(origin, target: T::AccountId) { + #[pallet::weight( + T::WeightInfo::unlock_set(T::MaxVotes::get()) + .max(T::WeightInfo::unlock_remove(T::MaxVotes::get())) + )] + pub(crate) fn unlock(origin: OriginFor, target: T::AccountId) -> DispatchResult { ensure_signed(origin)?; Self::update_lock(&target); + Ok(()) } /// Remove a vote for a referendum. @@ -1053,8 +1149,8 @@ decl_module! { /// /// Weight: `O(R + log R)` where R is the number of referenda that `target` has voted on. /// Weight is calculated for the maximum number of vote. - #[weight = T::WeightInfo::remove_vote(T::MaxVotes::get())] - fn remove_vote(origin, index: ReferendumIndex) -> DispatchResult { + #[pallet::weight(T::WeightInfo::remove_vote(T::MaxVotes::get()))] + pub(crate) fn remove_vote(origin: OriginFor, index: ReferendumIndex) -> DispatchResult { let who = ensure_signed(origin)?; Self::try_remove_vote(&who, index, UnvoteScope::Any) } @@ -1074,8 +1170,12 @@ decl_module! { /// /// Weight: `O(R + log R)` where R is the number of referenda that `target` has voted on. /// Weight is calculated for the maximum number of vote. - #[weight = T::WeightInfo::remove_other_vote(T::MaxVotes::get())] - fn remove_other_vote(origin, target: T::AccountId, index: ReferendumIndex) -> DispatchResult { + #[pallet::weight(T::WeightInfo::remove_other_vote(T::MaxVotes::get()))] + pub(crate) fn remove_other_vote( + origin: OriginFor, + target: T::AccountId, + index: ReferendumIndex, + ) -> DispatchResult { let who = ensure_signed(origin)?; let scope = if target == who { UnvoteScope::Any } else { UnvoteScope::OnlyExpired }; Self::try_remove_vote(&target, index, scope)?; @@ -1083,8 +1183,12 @@ decl_module! { } /// Enact a proposal from a referendum. For now we just make the weight be the maximum. - #[weight = T::BlockWeights::get().max_block] - fn enact_proposal(origin, proposal_hash: T::Hash, index: ReferendumIndex) -> DispatchResult { + #[pallet::weight(T::BlockWeights::get().max_block)] + pub(crate) fn enact_proposal( + origin: OriginFor, + proposal_hash: T::Hash, + index: ReferendumIndex, + ) -> DispatchResult { ensure_root(origin)?; Self::do_enact_proposal(proposal_hash, index) } @@ -1104,11 +1208,11 @@ decl_module! { /// /// Weight: `O(p)` (though as this is an high-privilege dispatch, we assume it has a /// reasonable value). - #[weight = (T::WeightInfo::blacklist(T::MaxProposals::get()), DispatchClass::Operational)] - fn blacklist(origin, + #[pallet::weight((T::WeightInfo::blacklist(T::MaxProposals::get()), DispatchClass::Operational))] + pub(crate) fn blacklist(origin: OriginFor, proposal_hash: T::Hash, maybe_ref_index: Option, - ) { + ) -> DispatchResult { T::BlacklistOrigin::ensure_origin(origin)?; // Insert the proposal into the blacklist. @@ -1141,7 +1245,8 @@ decl_module! { } } - Self::deposit_event(RawEvent::Blacklisted(proposal_hash)); + Self::deposit_event(Event::::Blacklisted(proposal_hash)); + Ok(()) } /// Remove a proposal. @@ -1151,8 +1256,11 @@ decl_module! { /// - `prop_index`: The index of the proposal to cancel. /// /// Weight: `O(p)` where `p = PublicProps::::decode_len()` - #[weight = T::WeightInfo::cancel_proposal(T::MaxProposals::get())] - fn cancel_proposal(origin, #[compact] prop_index: PropIndex) { + #[pallet::weight(T::WeightInfo::cancel_proposal(T::MaxProposals::get()))] + pub(crate) fn cancel_proposal( + origin: OriginFor, + #[pallet::compact] prop_index: PropIndex, + ) -> DispatchResult { T::CancelProposalOrigin::ensure_origin(origin)?; PublicProps::::mutate(|props| props.retain(|p| p.0 != prop_index)); @@ -1161,11 +1269,13 @@ decl_module! { T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0); } } + + Ok(()) } } } -impl Module { +impl Pallet { // exposed immutables. /// Get the amount locked in support of `proposal`; `None` if proposal isn't a valid proposal @@ -1205,7 +1315,7 @@ impl Module { threshold: VoteThreshold, delay: T::BlockNumber ) -> ReferendumIndex { - >::inject_referendum( + >::inject_referendum( >::block_number() + T::VotingPeriod::get(), proposal_hash, threshold, @@ -1215,7 +1325,7 @@ impl Module { /// Remove a referendum. pub fn internal_cancel_referendum(ref_index: ReferendumIndex) { - Self::deposit_event(RawEvent::Cancelled(ref_index)); + Self::deposit_event(Event::::Cancelled(ref_index)); ReferendumInfoOf::::remove(ref_index); } @@ -1305,7 +1415,7 @@ impl Module { Some(ReferendumInfo::Finished{end, approved}) => if let Some((lock_periods, balance)) = votes[i].1.locked_if(approved) { let unlock_at = end + T::EnactmentPeriod::get() * lock_periods.into(); - let now = system::Pallet::::block_number(); + let now = frame_system::Pallet::::block_number(); if now < unlock_at { ensure!(matches!(scope, UnvoteScope::Any), Error::::NoPermission); prior.accumulate(unlock_at, balance) @@ -1432,7 +1542,7 @@ impl Module { } => { // remove any delegation votes to our current target. let votes = Self::reduce_upstream_delegation(&target, conviction.votes(balance)); - let now = system::Pallet::::block_number(); + let now = frame_system::Pallet::::block_number(); let lock_periods = conviction.lock_periods().into(); prior.accumulate(now + T::EnactmentPeriod::get() * lock_periods, balance); voting.set_common(delegations, prior); @@ -1452,7 +1562,7 @@ impl Module { /// a security hole) but may be reduced from what they are currently. fn update_lock(who: &T::AccountId) { let lock_needed = VotingOf::::mutate(who, |voting| { - voting.rejig(system::Pallet::::block_number()); + voting.rejig(frame_system::Pallet::::block_number()); voting.locked_balance() }); if lock_needed.is_zero() { @@ -1470,17 +1580,17 @@ impl Module { delay: T::BlockNumber, ) -> ReferendumIndex { let ref_index = Self::referendum_count(); - ReferendumCount::put(ref_index + 1); + ReferendumCount::::put(ref_index + 1); let status = ReferendumStatus { end, proposal_hash, threshold, delay, tally: Default::default() }; let item = ReferendumInfo::Ongoing(status); >::insert(ref_index, item); - Self::deposit_event(RawEvent::Started(ref_index, threshold)); + Self::deposit_event(Event::::Started(ref_index, threshold)); ref_index } /// Table the next waiting proposal for a vote. fn launch_next(now: T::BlockNumber) -> DispatchResult { - if LastTabledWasExternal::take() { + if LastTabledWasExternal::::take() { Self::launch_public(now).or_else(|_| Self::launch_external(now)) } else { Self::launch_external(now).or_else(|_| Self::launch_public(now)) @@ -1490,8 +1600,8 @@ impl Module { /// Table the waiting external proposal for a vote, if there is one. fn launch_external(now: T::BlockNumber) -> DispatchResult { if let Some((proposal, threshold)) = >::take() { - LastTabledWasExternal::put(true); - Self::deposit_event(RawEvent::ExternalTabled); + LastTabledWasExternal::::put(true); + Self::deposit_event(Event::::ExternalTabled); Self::inject_referendum( now + T::VotingPeriod::get(), proposal, @@ -1520,7 +1630,7 @@ impl Module { for d in &depositors { T::Currency::unreserve(d, deposit); } - Self::deposit_event(RawEvent::Tabled(prop_index, deposit, depositors)); + Self::deposit_event(Event::::Tabled(prop_index, deposit, depositors)); Self::inject_referendum( now + T::VotingPeriod::get(), proposal, @@ -1540,19 +1650,19 @@ impl Module { if let Ok(proposal) = T::Proposal::decode(&mut &data[..]) { let err_amount = T::Currency::unreserve(&provider, deposit); debug_assert!(err_amount.is_zero()); - Self::deposit_event(RawEvent::PreimageUsed(proposal_hash, provider, deposit)); + Self::deposit_event(Event::::PreimageUsed(proposal_hash, provider, deposit)); let ok = proposal.dispatch(frame_system::RawOrigin::Root.into()).is_ok(); - Self::deposit_event(RawEvent::Executed(index, ok)); + Self::deposit_event(Event::::Executed(index, ok)); Ok(()) } else { T::Slash::on_unbalanced(T::Currency::slash_reserved(&provider, deposit).0); - Self::deposit_event(RawEvent::PreimageInvalid(proposal_hash, index)); + Self::deposit_event(Event::::PreimageInvalid(proposal_hash, index)); Err(Error::::PreimageInvalid.into()) } } else { - Self::deposit_event(RawEvent::PreimageMissing(proposal_hash, index)); + Self::deposit_event(Event::::PreimageMissing(proposal_hash, index)); Err(Error::::PreimageMissing.into()) } } @@ -1566,7 +1676,7 @@ impl Module { let approved = status.threshold.approved(status.tally, total_issuance); if approved { - Self::deposit_event(RawEvent::Passed(index)); + Self::deposit_event(Event::::Passed(index)); if status.delay.is_zero() { let _ = Self::do_enact_proposal(status.proposal_hash, index); } else { @@ -1582,14 +1692,14 @@ impl Module { DispatchTime::At(when), None, 63, - system::RawOrigin::Root.into(), + frame_system::RawOrigin::Root.into(), Call::enact_proposal(status.proposal_hash, index).into(), ).is_err() { frame_support::print("LOGIC ERROR: bake_referendum/schedule_named failed"); } } } else { - Self::deposit_event(RawEvent::NotPassed(index)); + Self::deposit_event(Event::::NotPassed(index)); } Ok(approved) @@ -1718,7 +1828,7 @@ impl Module { }; >::insert(proposal_hash, a); - Self::deposit_event(RawEvent::PreimageNoted(proposal_hash, who, deposit)); + Self::deposit_event(Event::::PreimageNoted(proposal_hash, who, deposit)); Ok(()) } @@ -1741,7 +1851,7 @@ impl Module { }; >::insert(proposal_hash, a); - Self::deposit_event(RawEvent::PreimageNoted(proposal_hash, who, free)); + Self::deposit_event(Event::::PreimageNoted(proposal_hash, who, free)); Ok(()) } diff --git a/frame/democracy/src/tests.rs b/frame/democracy/src/tests.rs index 73bbb5481dade..9c7b21ad91574 100644 --- a/frame/democracy/src/tests.rs +++ b/frame/democracy/src/tests.rs @@ -22,8 +22,8 @@ use super::*; use codec::Encode; use frame_support::{ assert_noop, assert_ok, parameter_types, ord_parameter_types, - traits::{SortedMembers, OnInitialize, Filter}, - weights::Weight, + traits::{SortedMembers, OnInitialize, Filter, GenesisBuild}, + weights::Weight, storage::StorageMap, }; use sp_core::H256; use sp_runtime::{ @@ -63,7 +63,7 @@ frame_support::construct_runtime!( System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Scheduler: pallet_scheduler::{Pallet, Call, Storage, Config, Event}, - Democracy: pallet_democracy::{Pallet, Call, Storage, Config, Event}, + Democracy: pallet_democracy::{Pallet, Call, Storage, Config, Event}, } ); @@ -195,7 +195,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { pallet_balances::GenesisConfig::{ balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)], }.assimilate_storage(&mut t).unwrap(); - pallet_democracy::GenesisConfig::default().assimilate_storage(&mut t).unwrap(); + pallet_democracy::GenesisConfig::::default().assimilate_storage(&mut t).unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext diff --git a/frame/democracy/src/tests/decoders.rs b/frame/democracy/src/tests/decoders.rs index 0331ea3934479..32e5e3ecf7ae4 100644 --- a/frame/democracy/src/tests/decoders.rs +++ b/frame/democracy/src/tests/decoders.rs @@ -18,7 +18,7 @@ //! The for various partial storage decoders use super::*; -use frame_support::storage::{migration, StorageMap, unhashed}; +use frame_support::storage::{migration, unhashed}; #[test] fn test_decode_compact_u32_at() {