Migrate away from SimpleDispatchInfo (#5686)

* Migrate away from SimpleDispatchInfo

* Fix imports

* Better doc

* Update lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Kian Paimani
2020-04-22 09:20:28 +02:00
committed by GitHub
parent 25c3ab2c1e
commit 50a7e12b3f
40 changed files with 458 additions and 405 deletions
+15 -15
View File
@@ -30,7 +30,7 @@ use sp_runtime::{
};
use frame_support::{
decl_storage, decl_event, ensure, decl_module, decl_error,
weights::{Weight, MINIMUM_WEIGHT, SimpleDispatchInfo},
weights::{Weight, MINIMUM_WEIGHT, DispatchClass},
traits::{
Currency, ExistenceRequirement, Get, LockableCurrency, LockIdentifier, BalanceStatus,
OnUnbalanced, ReservableCurrency, WithdrawReason, WithdrawReasons, ChangeMembers
@@ -405,13 +405,13 @@ decl_module! {
/// - Two extra DB entries, one DB change.
/// - Argument `votes` is limited in length to number of candidates.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(2_500_000_000)]
#[weight = 2_500_000_000]
fn set_approvals(
origin,
votes: Vec<bool>,
#[compact] index: VoteIndex,
hint: SetIndex,
#[compact] value: BalanceOf<T>
#[compact] value: BalanceOf<T>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::do_set_approvals(who, votes, index, hint, value)
@@ -423,12 +423,12 @@ decl_module! {
/// # <weight>
/// - Same as `set_approvals` with one additional storage read.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(2_500_000_000)]
#[weight = 2_500_000_000]
fn proxy_set_approvals(origin,
votes: Vec<bool>,
#[compact] index: VoteIndex,
hint: SetIndex,
#[compact] value: BalanceOf<T>
#[compact] value: BalanceOf<T>,
) -> DispatchResult {
let who = Self::proxy(ensure_signed(origin)?).ok_or(Error::<T>::NotProxy)?;
Self::do_set_approvals(who, votes, index, hint, value)
@@ -446,13 +446,13 @@ decl_module! {
/// - O(1).
/// - Two fewer DB entries, one DB change.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(2_500_000_000)]
#[weight = 2_500_000_000]
fn reap_inactive_voter(
origin,
#[compact] reporter_index: u32,
who: <T::Lookup as StaticLookup>::Source,
#[compact] who_index: u32,
#[compact] assumed_vote_index: VoteIndex
#[compact] assumed_vote_index: VoteIndex,
) {
let reporter = ensure_signed(origin)?;
let who = T::Lookup::lookup(who)?;
@@ -520,7 +520,7 @@ decl_module! {
/// - O(1).
/// - Two fewer DB entries, one DB change.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(1_250_000_000)]
#[weight = 1_250_000_000]
fn retract_voter(origin, #[compact] index: u32) {
let who = ensure_signed(origin)?;
@@ -548,7 +548,7 @@ decl_module! {
/// - Independent of input.
/// - Three DB changes.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(2_500_000_000)]
#[weight = 2_500_000_000]
fn submit_candidacy(origin, #[compact] slot: u32) {
let who = ensure_signed(origin)?;
@@ -585,12 +585,12 @@ decl_module! {
/// - O(voters) compute.
/// - One DB change.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(10_000_000_000)]
#[weight = 10_000_000_000]
fn present_winner(
origin,
candidate: <T::Lookup as StaticLookup>::Source,
#[compact] total: BalanceOf<T>,
#[compact] index: VoteIndex
#[compact] index: VoteIndex,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(
@@ -659,7 +659,7 @@ decl_module! {
/// Set the desired member count; if lower than the current count, then seats will not be up
/// election when they expire. If more, then a new vote will be started if one is not
/// already in progress.
#[weight = SimpleDispatchInfo::FixedOperational(MINIMUM_WEIGHT)]
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
fn set_desired_seats(origin, #[compact] count: u32) {
ensure_root(origin)?;
DesiredSeats::put(count);
@@ -669,7 +669,7 @@ decl_module! {
///
/// Note: A tally should happen instantly (if not already in a presentation
/// period) to fill the seat if removal means that the desired members are not met.
#[weight = SimpleDispatchInfo::FixedOperational(MINIMUM_WEIGHT)]
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
fn remove_member(origin, who: <T::Lookup as StaticLookup>::Source) {
ensure_root(origin)?;
let who = T::Lookup::lookup(who)?;
@@ -684,7 +684,7 @@ decl_module! {
/// Set the presentation duration. If there is currently a vote being presented for, will
/// invoke `finalize_vote`.
#[weight = SimpleDispatchInfo::FixedOperational(MINIMUM_WEIGHT)]
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
fn set_presentation_duration(origin, #[compact] count: T::BlockNumber) {
ensure_root(origin)?;
<PresentationDuration<T>>::put(count);
@@ -692,7 +692,7 @@ decl_module! {
/// Set the presentation duration. If there is current a vote being presented for, will
/// invoke `finalize_vote`.
#[weight = SimpleDispatchInfo::FixedOperational(MINIMUM_WEIGHT)]
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
fn set_term_duration(origin, #[compact] count: T::BlockNumber) {
ensure_root(origin)?;
<TermDuration<T>>::put(count);