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
+14 -14
View File
@@ -21,7 +21,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::{decl_module, decl_storage, decl_event, decl_error};
use frame_support::weights::{SimpleDispatchInfo, MINIMUM_WEIGHT};
use frame_support::weights::MINIMUM_WEIGHT;
use frame_support::traits::Currency;
use frame_system::{self as system, ensure_signed};
use codec::{Encode, Decode};
@@ -71,7 +71,7 @@ decl_module! {
fn deposit_event() = default;
/// Do nothing.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn do_nothing(_origin, input: u32) {
if input > 0 {
return Ok(());
@@ -83,7 +83,7 @@ decl_module! {
/// storage database, however, the `repeat` calls will all pull from the
/// storage overlay cache. You must consider this when analyzing the
/// results of the benchmark.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn read_value(_origin, repeat: u32) {
for _ in 0..repeat {
MyValue::get();
@@ -91,7 +91,7 @@ decl_module! {
}
/// Put a value into a storage value.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn put_value(_origin, repeat: u32) {
for r in 0..repeat {
MyValue::put(r);
@@ -103,7 +103,7 @@ decl_module! {
/// storage database, however, the `repeat` calls will all pull from the
/// storage overlay cache. You must consider this when analyzing the
/// results of the benchmark.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn exists_value(_origin, repeat: u32) {
for _ in 0..repeat {
MyValue::exists();
@@ -111,7 +111,7 @@ decl_module! {
}
/// Remove a value from storage `repeat` number of times.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn remove_value(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::remove(r);
@@ -119,7 +119,7 @@ decl_module! {
}
/// Read a value from storage map `repeat` number of times.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn read_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::get(r);
@@ -127,7 +127,7 @@ decl_module! {
}
/// Insert a value into a map.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn insert_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::insert(r, r);
@@ -135,7 +135,7 @@ decl_module! {
}
/// Check is a map contains a value `repeat` number of times.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn contains_key_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::contains_key(r);
@@ -143,7 +143,7 @@ decl_module! {
}
/// Read a value from storage `repeat` number of times.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn remove_prefix(_origin, repeat: u32) {
for r in 0..repeat {
MyDoubleMap::remove_prefix(r);
@@ -151,21 +151,21 @@ decl_module! {
}
/// Add user to the list.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn add_member_list(origin) {
let who = ensure_signed(origin)?;
MyMemberList::<T>::mutate(|x| x.push(who));
}
/// Append user to the list.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn append_member_list(origin) {
let who = ensure_signed(origin)?;
MyMemberList::<T>::append(&[who])?;
}
/// Encode a vector of accounts to bytes.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn encode_accounts(_origin, accounts: Vec<T::AccountId>) {
let bytes = accounts.encode();
@@ -177,7 +177,7 @@ decl_module! {
}
/// Decode bytes into a vector of accounts.
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
#[weight = MINIMUM_WEIGHT]
pub fn decode_accounts(_origin, bytes: Vec<u8>) {
let accounts: Vec<T::AccountId> = Decode::decode(&mut bytes.as_slice()).map_err(|_| "Could not decode")?;