Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

FRAME: inherited call weight syntax #13932

Merged
merged 19 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ pub mod pallet {
pub type UnscrupulousWebsites<T: Config<I>, I: 'static = ()> =
StorageValue<_, BoundedVec<UrlOf<T, I>, T::MaxUnscrupulousItems>, ValueQuery>;

#[pallet::call]
#[pallet::call(weight(<T as Config<I>>::WeightInfo))]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Add a new proposal to be voted on.
///
Expand Down Expand Up @@ -649,7 +649,6 @@ pub mod pallet {

/// Set a new IPFS CID to the alliance rule.
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::set_rule())]
pub fn set_rule(origin: OriginFor<T>, rule: Cid) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;

Expand All @@ -661,7 +660,6 @@ pub mod pallet {

/// Make an announcement of a new IPFS CID about alliance issues.
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::announce())]
pub fn announce(origin: OriginFor<T>, announcement: Cid) -> DispatchResult {
T::AnnouncementOrigin::ensure_origin(origin)?;

Expand All @@ -677,7 +675,6 @@ pub mod pallet {

/// Remove an announcement.
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::remove_announcement())]
pub fn remove_announcement(origin: OriginFor<T>, announcement: Cid) -> DispatchResult {
T::AnnouncementOrigin::ensure_origin(origin)?;

Expand All @@ -695,7 +692,6 @@ pub mod pallet {

/// Submit oneself for candidacy. A fixed deposit is reserved.
#[pallet::call_index(8)]
#[pallet::weight(T::WeightInfo::join_alliance())]
pub fn join_alliance(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;

Expand Down Expand Up @@ -732,7 +728,6 @@ pub mod pallet {
/// A Fellow can nominate someone to join the alliance as an Ally. There is no deposit
/// required from the nominator or nominee.
#[pallet::call_index(9)]
#[pallet::weight(T::WeightInfo::nominate_ally())]
pub fn nominate_ally(origin: OriginFor<T>, who: AccountIdLookupOf<T>) -> DispatchResult {
let nominator = ensure_signed(origin)?;
ensure!(Self::has_voting_rights(&nominator), Error::<T, I>::NoVotingRights);
Expand All @@ -757,7 +752,6 @@ pub mod pallet {

/// Elevate an Ally to Fellow.
#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::elevate_ally())]
pub fn elevate_ally(origin: OriginFor<T>, ally: AccountIdLookupOf<T>) -> DispatchResult {
T::MembershipManager::ensure_origin(origin)?;
let ally = T::Lookup::lookup(ally)?;
Expand All @@ -774,7 +768,6 @@ pub mod pallet {
/// As a member, give a retirement notice and start a retirement period required to pass in
/// order to retire.
#[pallet::call_index(11)]
#[pallet::weight(T::WeightInfo::give_retirement_notice())]
pub fn give_retirement_notice(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let role = Self::member_role_of(&who).ok_or(Error::<T, I>::NotMember)?;
Expand All @@ -797,7 +790,6 @@ pub mod pallet {
/// This can only be done once you have called `give_retirement_notice` and the
/// `RetirementPeriod` has passed.
#[pallet::call_index(12)]
#[pallet::weight(T::WeightInfo::retire())]
pub fn retire(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let retirement_period_end = RetiringMembers::<T, I>::get(&who)
Expand All @@ -820,7 +812,6 @@ pub mod pallet {

/// Kick a member from the Alliance and slash its deposit.
#[pallet::call_index(13)]
#[pallet::weight(T::WeightInfo::kick_member())]
pub fn kick_member(origin: OriginFor<T>, who: AccountIdLookupOf<T>) -> DispatchResult {
T::MembershipManager::ensure_origin(origin)?;
let member = T::Lookup::lookup(who)?;
Expand Down Expand Up @@ -922,7 +913,6 @@ pub mod pallet {
/// who do not want to leave the Alliance but do not have the capacity to participate
/// operationally for some time.
#[pallet::call_index(17)]
#[pallet::weight(T::WeightInfo::abdicate_fellow_status())]
pub fn abdicate_fellow_status(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let role = Self::member_role_of(&who).ok_or(Error::<T, I>::NotMember)?;
Expand Down
25 changes: 1 addition & 24 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ pub mod pallet {
CallbackFailed,
}

#[pallet::call]
#[pallet::call(weight(<T as Config<I>>::WeightInfo))]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Issue a new class of fungible assets from a public origin.
///
Expand All @@ -590,7 +590,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::create())]
pub fn create(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -654,7 +653,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::force_create())]
pub fn force_create(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand All @@ -680,7 +678,6 @@ pub mod pallet {
///
/// The asset class must be frozen before calling `start_destroy`.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::start_destroy())]
pub fn start_destroy(origin: OriginFor<T>, id: T::AssetIdParameter) -> DispatchResult {
let maybe_check_owner = match T::ForceOrigin::try_origin(origin) {
Ok(_) => None,
Expand Down Expand Up @@ -749,7 +746,6 @@ pub mod pallet {
///
/// Each successful call emits the `Event::Destroyed` event.
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::finish_destroy())]
pub fn finish_destroy(origin: OriginFor<T>, id: T::AssetIdParameter) -> DispatchResult {
let _ = ensure_signed(origin)?;
let id: T::AssetId = id.into();
Expand All @@ -769,7 +765,6 @@ pub mod pallet {
/// Weight: `O(1)`
/// Modes: Pre-existing balance of `beneficiary`; Account pre-existence of `beneficiary`.
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::mint())]
pub fn mint(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -799,7 +794,6 @@ pub mod pallet {
/// Weight: `O(1)`
/// Modes: Post-existence of `who`; Pre & post Zombie-status of `who`.
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::burn())]
pub fn burn(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -834,7 +828,6 @@ pub mod pallet {
/// Modes: Pre-existence of `target`; Post-existence of sender; Account pre-existence of
/// `target`.
#[pallet::call_index(8)]
#[pallet::weight(T::WeightInfo::transfer())]
pub fn transfer(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -868,7 +861,6 @@ pub mod pallet {
/// Modes: Pre-existence of `target`; Post-existence of sender; Account pre-existence of
/// `target`.
#[pallet::call_index(9)]
#[pallet::weight(T::WeightInfo::transfer_keep_alive())]
pub fn transfer_keep_alive(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -903,7 +895,6 @@ pub mod pallet {
/// Modes: Pre-existence of `dest`; Post-existence of `source`; Account pre-existence of
/// `dest`.
#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::force_transfer())]
pub fn force_transfer(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -931,7 +922,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(11)]
#[pallet::weight(T::WeightInfo::freeze())]
pub fn freeze(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -968,7 +958,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(12)]
#[pallet::weight(T::WeightInfo::thaw())]
pub fn thaw(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -1004,7 +993,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(13)]
#[pallet::weight(T::WeightInfo::freeze_asset())]
pub fn freeze_asset(origin: OriginFor<T>, id: T::AssetIdParameter) -> DispatchResult {
let origin = ensure_signed(origin)?;
let id: T::AssetId = id.into();
Expand All @@ -1031,7 +1019,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(14)]
#[pallet::weight(T::WeightInfo::thaw_asset())]
pub fn thaw_asset(origin: OriginFor<T>, id: T::AssetIdParameter) -> DispatchResult {
let origin = ensure_signed(origin)?;
let id: T::AssetId = id.into();
Expand Down Expand Up @@ -1059,7 +1046,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(15)]
#[pallet::weight(T::WeightInfo::transfer_ownership())]
pub fn transfer_ownership(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -1103,7 +1089,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(16)]
#[pallet::weight(T::WeightInfo::set_team())]
pub fn set_team(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -1173,7 +1158,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(18)]
#[pallet::weight(T::WeightInfo::clear_metadata())]
pub fn clear_metadata(origin: OriginFor<T>, id: T::AssetIdParameter) -> DispatchResult {
let origin = ensure_signed(origin)?;
let id: T::AssetId = id.into();
Expand Down Expand Up @@ -1257,7 +1241,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(20)]
#[pallet::weight(T::WeightInfo::force_clear_metadata())]
pub fn force_clear_metadata(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -1297,7 +1280,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(21)]
#[pallet::weight(T::WeightInfo::force_asset_status())]
pub fn force_asset_status(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -1354,7 +1336,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(22)]
#[pallet::weight(T::WeightInfo::approve_transfer())]
pub fn approve_transfer(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand All @@ -1381,7 +1362,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(23)]
#[pallet::weight(T::WeightInfo::cancel_approval())]
pub fn cancel_approval(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -1418,7 +1398,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(24)]
#[pallet::weight(T::WeightInfo::force_cancel_approval())]
pub fn force_cancel_approval(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -1468,7 +1447,6 @@ pub mod pallet {
///
/// Weight: `O(1)`
#[pallet::call_index(25)]
#[pallet::weight(T::WeightInfo::transfer_approved())]
pub fn transfer_approved(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down Expand Up @@ -1531,7 +1509,6 @@ pub mod pallet {
///
/// Emits `AssetMinBalanceChanged` event when successful.
#[pallet::call_index(28)]
#[pallet::weight(T::WeightInfo::set_min_balance())]
pub fn set_min_balance(
origin: OriginFor<T>,
id: T::AssetIdParameter,
Expand Down
7 changes: 1 addition & 6 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ pub mod pallet {
}
}

#[pallet::call]
#[pallet::call(weight(<T as Config<I>>::WeightInfo))]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Transfer some liquid free balance to another account.
///
Expand All @@ -529,7 +529,6 @@ pub mod pallet {
///
/// The dispatch origin for this call must be `Signed` by the transactor.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::transfer_allow_death())]
pub fn transfer_allow_death(
origin: OriginFor<T>,
dest: AccountIdLookupOf<T>,
Expand Down Expand Up @@ -591,7 +590,6 @@ pub mod pallet {
/// Exactly as `transfer_allow_death`, except the origin must be root and the source account
/// may be specified.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::force_transfer())]
pub fn force_transfer(
origin: OriginFor<T>,
source: AccountIdLookupOf<T>,
Expand All @@ -612,7 +610,6 @@ pub mod pallet {
///
/// [`transfer_allow_death`]: struct.Pallet.html#method.transfer
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::transfer_keep_alive())]
pub fn transfer_keep_alive(
origin: OriginFor<T>,
dest: AccountIdLookupOf<T>,
Expand Down Expand Up @@ -640,7 +637,6 @@ pub mod pallet {
/// transfer everything except at least the existential deposit, which will guarantee to
/// keep the sender account alive (true).
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::transfer_all())]
pub fn transfer_all(
origin: OriginFor<T>,
dest: AccountIdLookupOf<T>,
Expand All @@ -667,7 +663,6 @@ pub mod pallet {
///
/// Can only be called by ROOT.
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::force_unreserve())]
pub fn force_unreserve(
origin: OriginFor<T>,
who: AccountIdLookupOf<T>,
Expand Down
5 changes: 1 addition & 4 deletions frame/examples/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ pub mod pallet {
// against them as the first thing you do in your function. There are three convenience calls
// in system that do the matching for you and return a convenient result: `ensure_signed`,
// `ensure_root` and `ensure_none`.
#[pallet::call]
#[pallet::call(weight(<T as Config>::WeightInfo))]
impl<T: Config> Pallet<T> {
/// This is your public interface. Be extremely careful.
/// This is just a simple example of how to interact with the pallet from the external
Expand Down Expand Up @@ -497,9 +497,6 @@ pub mod pallet {
// The weight for this extrinsic we rely on the auto-generated `WeightInfo` from the
// benchmark toolchain.
#[pallet::call_index(0)]
#[pallet::weight(
<T as pallet::Config>::WeightInfo::accumulate_dummy()
)]
pub fn accumulate_dummy(origin: OriginFor<T>, increase_by: T::Balance) -> DispatchResult {
// This is a public call, so we ensure that the origin is some signed account.
let _sender = ensure_signed(origin)?;
Expand Down
1 change: 1 addition & 0 deletions frame/examples/basic/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ fn weights_work() {
// aka. `let info = <Call<Test> as GetDispatchInfo>::get_dispatch_info(&default_call);`
// TODO: account for proof size weight
assert!(info1.weight.ref_time() > 0);
assert_eq!(info1.weight, <Test as Config>::WeightInfo::accumulate_dummy());

// `set_dummy` is simpler than `accumulate_dummy`, and the weight
// should be less.
Expand Down
Loading