#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::{decl_module, decl_storage, decl_event, decl_error};
use frame_support::traits::Currency;
use frame_system::{self as system, ensure_signed};
use codec::{Encode, Decode};
use sp_std::prelude::Vec;
mod benchmarking;
pub type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
pub trait Trait: system::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
type Currency: Currency<Self::AccountId>;
}
decl_storage! {
trait Store for Module<T: Trait> as Benchmark {
MyMemberList: Vec<T::AccountId>;
MyMemberMap: map hasher(blake2_128_concat) T::AccountId => bool;
MyValue: u32;
MyMap: map hasher(twox_64_concat) u32 => u32;
MyDoubleMap: double_map hasher(twox_64_concat) u32, hasher(identity) u32 => u32;
}
}
decl_event!(
pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {
Dummy(u32, AccountId),
}
);
decl_error! {
pub enum Error for Module<T: Trait> {
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
#[weight = 0]
pub fn do_nothing(_origin, input: u32) {
if input > 0 {
return Ok(());
}
}
#[weight = 0]
pub fn read_value(_origin, repeat: u32) {
for _ in 0..repeat {
MyValue::get();
}
}
#[weight = 0]
pub fn put_value(_origin, repeat: u32) {
for r in 0..repeat {
MyValue::put(r);
}
}
#[weight = 0]
pub fn exists_value(_origin, repeat: u32) {
for _ in 0..repeat {
MyValue::exists();
}
}
#[weight = 0]
pub fn remove_value(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::remove(r);
}
}
#[weight = 0]
pub fn read_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::get(r);
}
}
#[weight = 0]
pub fn insert_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::insert(r, r);
}
}
#[weight = 0]
pub fn contains_key_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::contains_key(r);
}
}
#[weight = 0]
pub fn remove_prefix(_origin, repeat: u32) {
for r in 0..repeat {
MyDoubleMap::remove_prefix(r);
}
}
#[weight = 0]
pub fn add_member_list(origin) {
let who = ensure_signed(origin)?;
MyMemberList::<T>::mutate(|x| x.push(who));
}
#[weight = 0]
pub fn append_member_list(origin) {
let who = ensure_signed(origin)?;
MyMemberList::<T>::append(who);
}
#[weight = 0]
pub fn encode_accounts(_origin, accounts: Vec<T::AccountId>) {
let bytes = accounts.encode();
if bytes.is_empty() {
frame_support::print("You are encoding zero accounts.");
}
}
#[weight = 0]
pub fn decode_accounts(_origin, bytes: Vec<u8>) {
let accounts: Vec<T::AccountId> = Decode::decode(&mut bytes.as_slice()).map_err(|_| "Could not decode")?;
if accounts.is_empty() {
frame_support::print("You are decoding zero bytes.");
}
}
}
}