mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Mandate weight annotation (#5357)
* Disallow default weight * Fix build and test * Fix tests * Fix another beloved ui test. * fix beloved trybuild tests * fix treasury? * Final test fix * Fix build * Fix another one * Fix * More doctest fix
This commit is contained in:
@@ -75,6 +75,7 @@ decl_module! {
|
||||
/// Just a dummy entry point.
|
||||
/// function that can be called by the external world as an extrinsics call
|
||||
/// takes a parameter of the type `AccountId`, stores it, and emits an event
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn do_something(origin, something: u32) -> dispatch::DispatchResult {
|
||||
// Check it was signed and get the signer. See also: ensure_root and ensure_none
|
||||
let who = ensure_signed(origin)?;
|
||||
@@ -90,6 +91,7 @@ decl_module! {
|
||||
|
||||
/// Another dummy entry point.
|
||||
/// takes no parameters, attempts to increment storage value, and possibly throws an error
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn cause_error(origin) -> dispatch::DispatchResult {
|
||||
// Check it was signed and get the signer. See also: ensure_root and ensure_none
|
||||
let _who = ensure_signed(origin)?;
|
||||
|
||||
@@ -938,7 +938,6 @@ impl_runtime_apis! {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use frame_system::offchain::{SignAndSubmitTransaction, SubmitSignedTransaction};
|
||||
use frame_support::traits::OnInitialize;
|
||||
|
||||
#[test]
|
||||
fn validate_transaction_submitter_bounds() {
|
||||
|
||||
@@ -157,6 +157,7 @@ decl_module! {
|
||||
/// Issue a new class of fungible assets. There are, and will only ever be, `total`
|
||||
/// such assets and they'll all belong to the `origin` initially. It will have an
|
||||
/// identifier `AssetId` instance: this will be specified in the `Issued` event.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn issue(origin, #[compact] total: T::Balance) {
|
||||
let origin = ensure_signed(origin)?;
|
||||
|
||||
@@ -170,6 +171,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Move some assets from one holder to another.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn transfer(origin,
|
||||
#[compact] id: T::AssetId,
|
||||
target: <T::Lookup as StaticLookup>::Source,
|
||||
@@ -188,6 +190,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Destroy any assets of `id` owned by `origin`.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn destroy(origin, #[compact] id: T::AssetId) {
|
||||
let origin = ensure_signed(origin)?;
|
||||
let balance = <Balances<T>>::take((id, &origin));
|
||||
|
||||
@@ -71,6 +71,7 @@ decl_module! {
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Do nothing.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn do_nothing(_origin, input: u32) {
|
||||
if input > 0 {
|
||||
return Ok(());
|
||||
@@ -82,6 +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 = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn read_value(_origin, repeat: u32) {
|
||||
for _ in 0..repeat {
|
||||
MyValue::get();
|
||||
@@ -89,6 +91,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Put a value into a storage value.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn put_value(_origin, repeat: u32) {
|
||||
for r in 0..repeat {
|
||||
MyValue::put(r);
|
||||
@@ -100,6 +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 = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn exists_value(_origin, repeat: u32) {
|
||||
for _ in 0..repeat {
|
||||
MyValue::exists();
|
||||
@@ -107,6 +111,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Remove a value from storage `repeat` number of times.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn remove_value(_origin, repeat: u32) {
|
||||
for r in 0..repeat {
|
||||
MyMap::remove(r);
|
||||
@@ -114,6 +119,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Read a value from storage map `repeat` number of times.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn read_map(_origin, repeat: u32) {
|
||||
for r in 0..repeat {
|
||||
MyMap::get(r);
|
||||
@@ -121,6 +127,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Insert a value into a map.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn insert_map(_origin, repeat: u32) {
|
||||
for r in 0..repeat {
|
||||
MyMap::insert(r, r);
|
||||
@@ -128,6 +135,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Check is a map contains a value `repeat` number of times.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn contains_key_map(_origin, repeat: u32) {
|
||||
for r in 0..repeat {
|
||||
MyMap::contains_key(r);
|
||||
@@ -135,25 +143,29 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Read a value from storage `repeat` number of times.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn remove_prefix(_origin, repeat: u32) {
|
||||
for r in 0..repeat {
|
||||
MyDoubleMap::remove_prefix(r);
|
||||
}
|
||||
}
|
||||
|
||||
// Add user to the list.
|
||||
/// Add user to the list.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn add_member_list(origin) {
|
||||
let who = ensure_signed(origin)?;
|
||||
MyMemberList::<T>::mutate(|x| x.push(who));
|
||||
}
|
||||
|
||||
// Append user to the list.
|
||||
/// Append user to the list.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn append_member_list(origin) {
|
||||
let who = ensure_signed(origin)?;
|
||||
MyMemberList::<T>::append(&[who])?;
|
||||
}
|
||||
|
||||
// Encode a vector of accounts to bytes.
|
||||
/// Encode a vector of accounts to bytes.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn encode_accounts(_origin, accounts: Vec<T::AccountId>) {
|
||||
let bytes = accounts.encode();
|
||||
|
||||
@@ -164,7 +176,8 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
// Decode bytes into a vector of accounts.
|
||||
/// Decode bytes into a vector of accounts.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn decode_accounts(_origin, bytes: Vec<u8>) {
|
||||
let accounts: Vec<T::AccountId> = Decode::decode(&mut bytes.as_slice()).map_err(|_| "Could not decode")?;
|
||||
|
||||
|
||||
@@ -27,11 +27,13 @@ use frame_system::{RawOrigin, ensure_signed, ensure_none};
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn dummy(origin, _n: u32) -> DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn other_dummy(origin, _n: u32) -> DispatchResult {
|
||||
let _sender = ensure_none(origin)?;
|
||||
Ok(())
|
||||
|
||||
@@ -548,6 +548,7 @@ decl_module! {
|
||||
/// Updates the schedule for metering contracts.
|
||||
///
|
||||
/// The schedule must have a greater version than the stored schedule.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn update_schedule(origin, schedule: Schedule) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
if <Module<T>>::current_schedule().version >= schedule.version {
|
||||
@@ -562,6 +563,7 @@ decl_module! {
|
||||
|
||||
/// Stores the given binary Wasm code into the chain's storage and returns its `codehash`.
|
||||
/// You can instantiate contracts only with stored code.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn put_code(
|
||||
origin,
|
||||
#[compact] gas_limit: Gas,
|
||||
@@ -589,6 +591,7 @@ decl_module! {
|
||||
/// * If the account is a regular account, any value will be transferred.
|
||||
/// * If no account exists and the call value is not less than `existential_deposit`,
|
||||
/// a regular account will be created and any value will be transferred.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn call(
|
||||
origin,
|
||||
dest: <T::Lookup as StaticLookup>::Source,
|
||||
@@ -614,6 +617,7 @@ decl_module! {
|
||||
/// after the execution is saved as the `code` of the account. That code will be invoked
|
||||
/// upon any call received by this account.
|
||||
/// - The contract is initialized.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn instantiate(
|
||||
origin,
|
||||
#[compact] endowment: BalanceOf<T>,
|
||||
@@ -636,6 +640,7 @@ decl_module! {
|
||||
///
|
||||
/// If contract is not evicted as a result of this call, no actions are taken and
|
||||
/// the sender is not eligible for the reward.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn claim_surcharge(origin, dest: T::AccountId, aux_sender: Option<T::AccountId>) {
|
||||
let origin = origin.into();
|
||||
let (signed, rewarded) = match (origin, aux_sender) {
|
||||
|
||||
@@ -76,6 +76,7 @@ decl_module! {
|
||||
|
||||
/// Hint that the author of this block thinks the best finalized
|
||||
/// block is the given number.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn final_hint(origin, #[compact] hint: T::BlockNumber) {
|
||||
ensure_none(origin)?;
|
||||
ensure!(!<Self as Store>::Update::exists(), Error::<T>::AlreadyUpdated);
|
||||
|
||||
@@ -360,12 +360,14 @@ decl_module! {
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Create a new kind of asset.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn create(origin, options: AssetOptions<T::Balance, T::AccountId>) -> DispatchResult {
|
||||
let origin = ensure_signed(origin)?;
|
||||
Self::create_asset(None, Some(origin), options)
|
||||
}
|
||||
|
||||
/// Transfer some liquid free balance to another account.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn transfer(origin, #[compact] asset_id: T::AssetId, to: T::AccountId, #[compact] amount: T::Balance) {
|
||||
let origin = ensure_signed(origin)?;
|
||||
ensure!(!amount.is_zero(), Error::<T>::ZeroAmount);
|
||||
@@ -375,6 +377,7 @@ decl_module! {
|
||||
/// Updates permission for a given `asset_id` and an account.
|
||||
///
|
||||
/// The `origin` must have `update` permission.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn update_permission(
|
||||
origin,
|
||||
#[compact] asset_id: T::AssetId,
|
||||
@@ -397,6 +400,7 @@ decl_module! {
|
||||
|
||||
/// Mints an asset, increases its total issuance.
|
||||
/// The origin must have `mint` permissions.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn mint(origin, #[compact] asset_id: T::AssetId, to: T::AccountId, amount: T::Balance) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::mint_free(&asset_id, &who, &to, &amount)?;
|
||||
@@ -406,6 +410,7 @@ decl_module! {
|
||||
|
||||
/// Burns an asset, decreases its total issuance.
|
||||
/// The `origin` must have `burn` permissions.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn burn(origin, #[compact] asset_id: T::AssetId, to: T::AccountId, amount: T::Balance) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::burn_free(&asset_id, &who, &to, &amount)?;
|
||||
@@ -415,6 +420,7 @@ decl_module! {
|
||||
|
||||
/// Can be used to create reserved tokens.
|
||||
/// Requires Root call.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn create_reserved(
|
||||
origin,
|
||||
asset_id: T::AssetId,
|
||||
|
||||
@@ -184,6 +184,7 @@ decl_module! {
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Report some misbehavior.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn report_misbehavior(origin, _report: Vec<u8>) {
|
||||
ensure_signed(origin)?;
|
||||
// FIXME: https://github.com/paritytech/substrate/issues/1112
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
//! #[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
//! pub fn is_online(origin, authority_index: u32) -> dispatch::DispatchResult {
|
||||
//! let _sender = ensure_signed(origin)?;
|
||||
//! let _is_online = <im_online::Module<T>>::is_online(authority_index);
|
||||
@@ -309,6 +310,7 @@ decl_module! {
|
||||
|
||||
fn deposit_event() = default;
|
||||
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn heartbeat(
|
||||
origin,
|
||||
heartbeat: Heartbeat<T::BlockNumber>,
|
||||
|
||||
@@ -121,6 +121,7 @@ decl_module! {
|
||||
/// - One reserve operation.
|
||||
/// - One event.
|
||||
/// # </weight>
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn claim(origin, index: T::AccountIndex) {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
@@ -148,6 +149,7 @@ decl_module! {
|
||||
/// - One transfer operation.
|
||||
/// - One event.
|
||||
/// # </weight>
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn transfer(origin, new: T::AccountId, index: T::AccountIndex) {
|
||||
let who = ensure_signed(origin)?;
|
||||
ensure!(who != new, Error::<T>::NotTransfer);
|
||||
@@ -178,6 +180,7 @@ decl_module! {
|
||||
/// - One reserve operation.
|
||||
/// - One event.
|
||||
/// # </weight>
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn free(origin, index: T::AccountIndex) {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
@@ -206,6 +209,7 @@ decl_module! {
|
||||
/// - Up to one reserve operation.
|
||||
/// - One event.
|
||||
/// # </weight>
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn force_transfer(origin, new: T::AccountId, index: T::AccountIndex) {
|
||||
ensure_root(origin)?;
|
||||
|
||||
|
||||
@@ -171,6 +171,7 @@ decl_module! {
|
||||
/// - One storage read/write.
|
||||
/// - One event.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(70_000)]
|
||||
fn clear_name(origin) {
|
||||
let sender = ensure_signed(origin)?;
|
||||
|
||||
|
||||
@@ -35,12 +35,13 @@
|
||||
//! ### Example - Get random seed for the current block
|
||||
//!
|
||||
//! ```
|
||||
//! use frame_support::{decl_module, dispatch, traits::Randomness};
|
||||
//! use frame_support::{decl_module, dispatch, traits::Randomness, weights::SimpleDispatchInfo};
|
||||
//!
|
||||
//! pub trait Trait: frame_system::Trait {}
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
//! #[weight = SimpleDispatchInfo::default()]
|
||||
//! pub fn random_module_example(origin) -> dispatch::DispatchResult {
|
||||
//! let _random_seed = <pallet_randomness_collective_flip::Module<T>>::random_seed();
|
||||
//! Ok(())
|
||||
|
||||
@@ -645,6 +645,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - One storage mutation to check account is recovered by `who`. O(1)
|
||||
/// # </weight>
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn cancel_recovered(origin, account: T::AccountId) {
|
||||
let who = ensure_signed(origin)?;
|
||||
// Check `who` is allowed to make a call on behalf of `account`
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
//! #[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
//! pub fn candidate(origin) -> dispatch::DispatchResult {
|
||||
//! let who = ensure_signed(origin)?;
|
||||
//!
|
||||
@@ -265,6 +266,7 @@ decl_module! {
|
||||
///
|
||||
/// The `index` parameter of this function must be set to
|
||||
/// the index of the transactor in the `Pool`.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn submit_candidacy(origin) {
|
||||
let who = ensure_signed(origin)?;
|
||||
ensure!(!<CandidateExists<T, I>>::contains_key(&who), Error::<T, I>::AlreadyInPool);
|
||||
@@ -294,6 +296,7 @@ decl_module! {
|
||||
///
|
||||
/// The `index` parameter of this function must be set to
|
||||
/// the index of the transactor in the `Pool`.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn withdraw_candidacy(
|
||||
origin,
|
||||
index: u32
|
||||
@@ -313,6 +316,7 @@ decl_module! {
|
||||
///
|
||||
/// The `index` parameter of this function must be set to
|
||||
/// the index of `dest` in the `Pool`.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn kick(
|
||||
origin,
|
||||
dest: <T::Lookup as StaticLookup>::Source,
|
||||
@@ -337,6 +341,7 @@ decl_module! {
|
||||
///
|
||||
/// The `index` parameter of this function must be set to
|
||||
/// the index of the `dest` in the `Pool`.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn score(
|
||||
origin,
|
||||
dest: <T::Lookup as StaticLookup>::Source,
|
||||
@@ -377,6 +382,7 @@ decl_module! {
|
||||
/// (this happens each `Period`).
|
||||
///
|
||||
/// May only be called from root.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn change_member_count(origin, count: u32) {
|
||||
ensure_root(origin)?;
|
||||
<MemberCount<I>>::put(&count);
|
||||
|
||||
@@ -157,6 +157,7 @@
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
//! /// Reward a validator.
|
||||
//! #[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
//! pub fn reward_myself(origin) -> dispatch::DispatchResult {
|
||||
//! let reported = ensure_signed(origin)?;
|
||||
//! <staking::Module<T>>::reward_by_ids(vec![(reported, 10)]);
|
||||
@@ -1476,6 +1477,7 @@ decl_module! {
|
||||
/// This can be called from any origin.
|
||||
///
|
||||
/// - `stash`: The stash account to reap. Its balance must be zero.
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn reap_stash(_origin, stash: T::AccountId) {
|
||||
ensure!(T::Currency::total_balance(&stash).is_zero(), Error::<T>::FundedTarget);
|
||||
Self::kill_stash(&stash)?;
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
//! #[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
//! pub fn privileged_function(origin) -> dispatch::DispatchResult {
|
||||
//! ensure_root(origin)?;
|
||||
//!
|
||||
@@ -120,7 +121,7 @@ decl_module! {
|
||||
/// - Weight of derivative `call` execution + 10,000.
|
||||
/// # </weight>
|
||||
#[weight = FunctionOf(
|
||||
|args: (&Box<<T as Trait>::Call>,)| args.0.get_dispatch_info().weight + 10_000,
|
||||
|args: (&Box<<T as Trait>::Call>,)| args.0.get_dispatch_info().weight + 10_000,
|
||||
|args: (&Box<<T as Trait>::Call>,)| args.0.get_dispatch_info().class,
|
||||
true
|
||||
)]
|
||||
@@ -150,6 +151,7 @@ decl_module! {
|
||||
/// - Limited storage reads.
|
||||
/// - One DB change.
|
||||
/// # </weight>
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn set_key(origin, new: <T::Lookup as StaticLookup>::Source) {
|
||||
// This is a public call, so we ensure that the origin is some signed account.
|
||||
let sender = ensure_signed(origin)?;
|
||||
@@ -174,7 +176,7 @@ decl_module! {
|
||||
#[weight = FunctionOf(
|
||||
|args: (&<T::Lookup as StaticLookup>::Source, &Box<<T as Trait>::Call>,)| {
|
||||
args.1.get_dispatch_info().weight + 10_000
|
||||
},
|
||||
},
|
||||
|args: (&<T::Lookup as StaticLookup>::Source, &Box<<T as Trait>::Call>,)| {
|
||||
args.1.get_dispatch_info().class
|
||||
},
|
||||
|
||||
@@ -57,12 +57,14 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_support::weights::SimpleDispatchInfo;
|
||||
/// # use frame_system::{self as system, Trait, ensure_signed};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
///
|
||||
/// // Private functions are dispatchable, but not available to other
|
||||
/// // FRAME pallets.
|
||||
/// #[weight = SimpleDispatchInfo::default()]
|
||||
/// fn my_function(origin, var: u64) -> dispatch::DispatchResult {
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
@@ -70,6 +72,7 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
///
|
||||
/// // Public functions are both dispatchable and available to other
|
||||
/// // FRAME pallets.
|
||||
/// #[weight = SimpleDispatchInfo::default()]
|
||||
/// pub fn my_public_function(origin) -> dispatch::DispatchResult {
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
@@ -97,15 +100,17 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_support::weights::SimpleDispatchInfo;
|
||||
/// # use frame_system::{self as system, Trait, ensure_signed};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
///
|
||||
/// #[weight = SimpleDispatchInfo::default()]
|
||||
/// fn my_long_function(origin) -> dispatch::DispatchResult {
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// #[weight = SimpleDispatchInfo::default()]
|
||||
/// fn my_short_function(origin) {
|
||||
/// // Your implementation
|
||||
/// }
|
||||
@@ -122,9 +127,11 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_support::weights::SimpleDispatchInfo;
|
||||
/// # use frame_system::{self as system, Trait, ensure_signed, ensure_root};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
/// #[weight = SimpleDispatchInfo::default()]
|
||||
/// fn my_privileged_function(origin) -> dispatch::DispatchResult {
|
||||
/// ensure_root(origin)?;
|
||||
/// // Your implementation
|
||||
@@ -807,27 +814,10 @@ macro_rules! decl_module {
|
||||
) $( -> $result:ty )* { $( $impl:tt )* }
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
$crate::decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<
|
||||
$trait_instance: $trait_name$(<I>, $instance: $instantiable $(= $module_default_instance)?)?
|
||||
>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{ $( $other_where_bounds )* }
|
||||
{ $( $deposit_event )* }
|
||||
{ $( $on_initialize )* }
|
||||
{ $( $on_runtime_upgrade )* }
|
||||
{ $( $on_finalize )* }
|
||||
{ $( $offchain )* }
|
||||
{ $( $constants )* }
|
||||
{ $( $error_type )* }
|
||||
[ $( $dispatchables )* ]
|
||||
$(#[doc = $doc_attr])*
|
||||
#[weight = $crate::dispatch::SimpleDispatchInfo::default()]
|
||||
$fn_vis fn $fn_name(
|
||||
$from $(, $(#[$codec_attr])* $param_name : $param )*
|
||||
) $( -> $result )* { $( $impl )* }
|
||||
$($rest)*
|
||||
compile_error!(concat!(
|
||||
"Missing weight for ", stringify!($ident),
|
||||
". Every dispatchable must have a #[weight] attribute."
|
||||
)
|
||||
);
|
||||
};
|
||||
// Ignore any ident which is not `origin` with type `T::Origin`.
|
||||
@@ -1444,9 +1434,9 @@ macro_rules! decl_module {
|
||||
&$weight,
|
||||
($( $param_name, )*)
|
||||
);
|
||||
$crate::dispatch::DispatchInfo {
|
||||
weight,
|
||||
class,
|
||||
$crate::dispatch::DispatchInfo {
|
||||
weight,
|
||||
class,
|
||||
pays_fee,
|
||||
}
|
||||
},
|
||||
@@ -2063,21 +2053,31 @@ mod tests {
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin, T::AccountId: From<u32> {
|
||||
/// Hi, this is a comment.
|
||||
#[weight = SimpleDispatchInfo::default()]
|
||||
fn aux_0(_origin) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = SimpleDispatchInfo::default()]
|
||||
fn aux_1(_origin, #[compact] _data: u32,) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = SimpleDispatchInfo::default()]
|
||||
fn aux_2(_origin, _data: i32, _data2: String) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(3)]
|
||||
fn aux_3(_origin) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = SimpleDispatchInfo::default()]
|
||||
fn aux_4(_origin, _data: i32) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = SimpleDispatchInfo::default()]
|
||||
fn aux_5(_origin, _data: i32, #[compact] _data2: u32,) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = SimpleDispatchInfo::FixedOperational(5)]
|
||||
fn operational(_origin) { unreachable!() }
|
||||
|
||||
fn on_initialize(n: T::BlockNumber,) -> Weight { if n.into() == 42 { panic!("on_initialize") } 7 }
|
||||
fn on_finalize(n: T::BlockNumber,) { if n.into() == 42 { panic!("on_finalize") } }
|
||||
fn on_runtime_upgrade() -> Weight { 10 }
|
||||
fn offchain_worker() {}
|
||||
|
||||
#[weight = SimpleDispatchInfo::FixedOperational(5)]
|
||||
fn operational(_origin,) { unreachable!() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ pub use frame_metadata::{ModuleErrorMetadata, ErrorMetadata, DecodeDifferent};
|
||||
///
|
||||
/// ```
|
||||
/// # use frame_support::{decl_error, decl_module};
|
||||
/// # use frame_support::weights::SimpleDispatchInfo;
|
||||
/// decl_error! {
|
||||
/// /// Errors that can occur in my module.
|
||||
/// pub enum MyError for Module<T: Trait> {
|
||||
@@ -54,6 +55,7 @@ pub use frame_metadata::{ModuleErrorMetadata, ErrorMetadata, DecodeDifferent};
|
||||
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
/// type Error = MyError<T>;
|
||||
///
|
||||
/// #[weight = SimpleDispatchInfo::default()]
|
||||
/// fn do_something(origin) -> frame_support::dispatch::DispatchResult {
|
||||
/// Err(MyError::<T>::YouAreNotCoolEnough.into())
|
||||
/// }
|
||||
|
||||
@@ -336,6 +336,7 @@ mod tests {
|
||||
|
||||
mod event_module {
|
||||
use crate::dispatch::DispatchResult;
|
||||
use crate::weights::SimpleDispatchInfo;
|
||||
|
||||
pub trait Trait: super::system::Trait {
|
||||
type Balance;
|
||||
@@ -353,6 +354,7 @@ mod tests {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
type Error = Error<T>;
|
||||
|
||||
#[weight = SimpleDispatchInfo::default()]
|
||||
fn aux_0(_origin) -> DispatchResult { unreachable!() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ mod module1 {
|
||||
pub struct Module<T: Trait<I>, I: Instance = DefaultInstance> for enum Call
|
||||
where origin: <T as system::Trait>::Origin
|
||||
{
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
|
||||
Err(Error::<T, I>::Something.into())
|
||||
}
|
||||
@@ -58,6 +59,7 @@ mod module2 {
|
||||
pub struct Module<T: Trait> for enum Call
|
||||
where origin: <T as system::Trait>::Origin
|
||||
{
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
|
||||
Err(Error::<T>::Something.into())
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ mod module1 {
|
||||
|
||||
fn deposit_event() = default;
|
||||
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn one(origin) {
|
||||
system::ensure_root(origin)?;
|
||||
Self::deposit_event(RawEvent::AnotherVariant(3));
|
||||
|
||||
@@ -19,6 +19,7 @@ macro_rules! reserved {
|
||||
|
||||
frame_support::decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
fn $reserved(_origin) -> dispatch::DispatchResult { unreachable!() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
error: Invalid call fn name: `on_finalize`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
--> $DIR/on_initialize.rs:31:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: Invalid call fn name: `on_initialize`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
--> $DIR/on_initialize.rs:31:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: Invalid call fn name: `on_runtime_upgrade`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
--> $DIR/on_initialize.rs:31:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: Invalid call fn name: `offchain_worker`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
--> $DIR/on_initialize.rs:31:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: `deposit_event` function is reserved and must follow the syntax: `$vis:vis fn deposit_event() = default;`
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
error: Invalid call fn name: `deposit_event`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
|
||||
--> $DIR/on_initialize.rs:31:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
@@ -68,13 +68,14 @@
|
||||
//! ### Example - Get extrinsic count and parent hash for the current block
|
||||
//!
|
||||
//! ```
|
||||
//! use frame_support::{decl_module, dispatch};
|
||||
//! use frame_support::{decl_module, dispatch, weights::SimpleDispatchInfo};
|
||||
//! use frame_system::{self as system, ensure_signed};
|
||||
//!
|
||||
//! pub trait Trait: system::Trait {}
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
//! #[weight = SimpleDispatchInfo::default()]
|
||||
//! pub fn system_module_example(origin) -> dispatch::DispatchResult {
|
||||
//! let _sender = ensure_signed(origin)?;
|
||||
//! let _extrinsic_count = <system::Module<T>>::extrinsic_count();
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
//!
|
||||
//! decl_module! {
|
||||
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
//! #[weight = frame_support::weights::SimpleDispatchInfo::default()]
|
||||
//! pub fn get_time(origin) -> dispatch::DispatchResult {
|
||||
//! let _sender = ensure_signed(origin)?;
|
||||
//! let _now = <timestamp::Module<T>>::get();
|
||||
|
||||
@@ -195,6 +195,7 @@ decl_module! {
|
||||
/// - One storage read (codec `O(1)`) and up to one removal.
|
||||
/// - One event.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::default()]
|
||||
fn vest(origin) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::update_lock(who)
|
||||
@@ -216,6 +217,7 @@ decl_module! {
|
||||
/// - One storage read (codec `O(1)`) and up to one removal.
|
||||
/// - One event.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::default()]
|
||||
fn vest_other(origin, target: <T::Lookup as StaticLookup>::Source) -> DispatchResult {
|
||||
ensure_signed(origin)?;
|
||||
Self::update_lock(T::Lookup::lookup(target)?)
|
||||
|
||||
Reference in New Issue
Block a user