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
+13 -13
View File
@@ -260,7 +260,7 @@ use sp_runtime::{Percent, ModuleId, RuntimeDebug,
}
};
use frame_support::{decl_error, decl_module, decl_storage, decl_event, ensure, dispatch::DispatchResult};
use frame_support::weights::{SimpleDispatchInfo, Weight, MINIMUM_WEIGHT};
use frame_support::weights::{Weight, MINIMUM_WEIGHT};
use frame_support::traits::{
Currency, ReservableCurrency, Randomness, Get, ChangeMembers, BalanceStatus,
ExistenceRequirement::AllowDeath, EnsureOrigin
@@ -527,7 +527,7 @@ decl_module! {
///
/// Total Complexity: O(M + B + C + logM + logB + X)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(50_000_000)]
#[weight = 50_000_000]
pub fn bid(origin, value: BalanceOf<T, I>) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(!<SuspendedCandidates<T, I>>::contains_key(&who), Error::<T, I>::Suspended);
@@ -566,7 +566,7 @@ decl_module! {
///
/// Total Complexity: O(B + X)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(20_000_000)]
#[weight = 20_000_000]
pub fn unbid(origin, pos: u32) -> DispatchResult {
let who = ensure_signed(origin)?;
@@ -636,7 +636,7 @@ decl_module! {
///
/// Total Complexity: O(M + B + C + logM + logB + X)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(50_000_000)]
#[weight = 50_000_000]
pub fn vouch(origin, who: T::AccountId, value: BalanceOf<T, I>, tip: BalanceOf<T, I>) -> DispatchResult {
let voucher = ensure_signed(origin)?;
// Check user is not suspended.
@@ -677,7 +677,7 @@ decl_module! {
///
/// Total Complexity: O(B)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(20_000_000)]
#[weight = 20_000_000]
pub fn unvouch(origin, pos: u32) -> DispatchResult {
let voucher = ensure_signed(origin)?;
ensure!(Self::vouching(&voucher) == Some(VouchingStatus::Vouching), Error::<T, I>::NotVouching);
@@ -715,7 +715,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + C)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(30_000_000)]
#[weight = 30_000_000]
pub fn vote(origin, candidate: <T::Lookup as StaticLookup>::Source, approve: bool) {
let voter = ensure_signed(origin)?;
let candidate = T::Lookup::lookup(candidate)?;
@@ -746,7 +746,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(20_000_000)]
#[weight = 20_000_000]
pub fn defender_vote(origin, approve: bool) {
let voter = ensure_signed(origin)?;
let members = <Members<T, I>>::get();
@@ -778,7 +778,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + P + X)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(30_000_000)]
#[weight = 30_000_000]
pub fn payout(origin) {
let who = ensure_signed(origin)?;
@@ -820,7 +820,7 @@ decl_module! {
///
/// Total Complexity: O(1)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
fn found(origin, founder: T::AccountId, max_members: u32, rules: Vec<u8>) {
T::FounderSetOrigin::ensure_origin(origin)?;
ensure!(!<Head<T, I>>::exists(), Error::<T, I>::AlreadyFounded);
@@ -847,7 +847,7 @@ decl_module! {
///
/// Total Complexity: O(1)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(20_000_000)]
#[weight = 20_000_000]
fn unfound(origin) {
let founder = ensure_signed(origin)?;
ensure!(Founder::<T, I>::get() == Some(founder.clone()), Error::<T, I>::NotFounder);
@@ -889,7 +889,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + B)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(30_000_000)]
#[weight = 30_000_000]
fn judge_suspended_member(origin, who: T::AccountId, forgive: bool) {
T::SuspensionJudgementOrigin::ensure_origin(origin)?;
ensure!(<SuspendedMembers<T, I>>::contains_key(&who), Error::<T, I>::NotSuspended);
@@ -960,7 +960,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + B + X)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(50_000_000)]
#[weight = 50_000_000]
fn judge_suspended_candidate(origin, who: T::AccountId, judgement: Judgement) {
T::SuspensionJudgementOrigin::ensure_origin(origin)?;
if let Some((value, kind)) = <SuspendedCandidates<T, I>>::get(&who) {
@@ -1020,7 +1020,7 @@ decl_module! {
///
/// Total Complexity: O(1)
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
fn set_max_members(origin, max: u32) {
ensure_root(origin)?;
ensure!(max > 1, Error::<T, I>::MaxMembers);