Skip to content

Commit

Permalink
use explicit call index (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjj9219 authored Jan 4, 2023
1 parent dc39cfd commit f94894f
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub mod module {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::register_asset())]
pub fn register_asset(
origin: OriginFor<T>,
Expand All @@ -151,6 +152,7 @@ pub mod module {
Self::do_register_asset(metadata, asset_id)
}

#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::update_asset())]
pub fn update_asset(
origin: OriginFor<T>,
Expand Down
1 change: 1 addition & 0 deletions auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub mod module {
///
/// The dispatch origin for this call must be `Signed` by the
/// transactor.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::bid_collateral_auction())]
pub fn bid(origin: OriginFor<T>, id: T::AuctionId, #[pallet::compact] value: T::Balance) -> DispatchResult {
let from = ensure_signed(origin)?;
Expand Down
9 changes: 9 additions & 0 deletions authority/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub mod module {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Dispatch a dispatchable on behalf of other origin
#[pallet::call_index(0)]
#[pallet::weight({
let info = call.get_dispatch_info();
(T::WeightInfo::dispatch_as().saturating_add(info.weight), info.class)
Expand All @@ -324,6 +325,7 @@ pub mod module {

/// Schedule a dispatchable to be dispatched at later block.
/// This is the only way to dispatch a call with `DelayedOrigin`.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::schedule_dispatch_without_delay())]
pub fn schedule_dispatch(
origin: OriginFor<T>,
Expand Down Expand Up @@ -375,6 +377,7 @@ pub mod module {
}

/// Fast track a scheduled dispatchable.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::fast_track_scheduled_dispatch())]
pub fn fast_track_scheduled_dispatch(
origin: OriginFor<T>,
Expand Down Expand Up @@ -405,6 +408,7 @@ pub mod module {
}

/// Delay a scheduled dispatchable.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::delay_scheduled_dispatch())]
pub fn delay_scheduled_dispatch(
origin: OriginFor<T>,
Expand Down Expand Up @@ -432,6 +436,7 @@ pub mod module {
}

/// Cancel a scheduled dispatchable.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::cancel_scheduled_dispatch())]
pub fn cancel_scheduled_dispatch(
origin: OriginFor<T>,
Expand All @@ -448,6 +453,7 @@ pub mod module {
Ok(())
}

#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::authorize_call())]
pub fn authorize_call(
origin: OriginFor<T>,
Expand All @@ -461,6 +467,7 @@ pub mod module {
Ok(())
}

#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::remove_authorized_call())]
pub fn remove_authorized_call(origin: OriginFor<T>, hash: T::Hash) -> DispatchResult {
let root_or_signed =
Expand All @@ -481,6 +488,7 @@ pub mod module {
})
}

#[pallet::call_index(7)]
#[pallet::weight((
T::WeightInfo::trigger_call().saturating_add((*call_weight_bound).into()),
DispatchClass::Operational,
Expand Down Expand Up @@ -512,6 +520,7 @@ pub mod module {
})
}

#[pallet::call_index(8)]
#[pallet::weight((
T::WeightInfo::trigger_call().saturating_add(*call_weight_bound),
DispatchClass::Operational,
Expand Down
4 changes: 3 additions & 1 deletion bencher/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(0)]
#[orml_weight_meter::start(ModuleWeights::<T>::set_value())]
pub fn set_value(origin: OriginFor<T>, n: u32) -> DispatchResultWithPostInfo {
Expand All @@ -49,6 +50,7 @@ pub mod pallet {
Ok(Some(orml_weight_meter::used_weight()).into())
}

#[pallet::call_index(1)]
#[pallet::weight(0)]
pub fn dummy(origin: OriginFor<T>, _n: u32) -> DispatchResult {
let _sender = frame_system::ensure_none(origin)?;
Expand Down Expand Up @@ -85,4 +87,4 @@ pub mod pallet {
_ = Bar::<T>::clear(10, None);
}
}
}
}
2 changes: 2 additions & 0 deletions benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ pub mod test {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(0)]
pub fn set_value(origin: OriginFor<T>, n: u32) -> DispatchResult {
let _sender = frame_system::ensure_signed(origin)?;
Value::<T>::put(n);
Ok(())
}

#[pallet::call_index(1)]
#[pallet::weight(0)]
pub fn dummy(origin: OriginFor<T>, _n: u32) -> DispatchResult {
let _sender = frame_system::ensure_none(origin)?;
Expand Down
3 changes: 3 additions & 0 deletions currencies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub mod module {
///
/// The dispatch origin for this call must be `Signed` by the
/// transactor.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::transfer_non_native_currency())]
pub fn transfer(
origin: OriginFor<T>,
Expand All @@ -142,6 +143,7 @@ pub mod module {
///
/// The dispatch origin for this call must be `Signed` by the
/// transactor.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::transfer_native_currency())]
pub fn transfer_native_currency(
origin: OriginFor<T>,
Expand All @@ -156,6 +158,7 @@ pub mod module {
/// update amount of account `who` under `currency_id`.
///
/// The dispatch origin of this call must be _Root_.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::update_balance_non_native_currency())]
pub fn update_balance(
origin: OriginFor<T>,
Expand Down
2 changes: 2 additions & 0 deletions gradually-update/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub mod module {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Add gradually_update to adjust numeric parameter.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::gradually_update())]
pub fn gradually_update(origin: OriginFor<T>, update: GraduallyUpdateOf<T>) -> DispatchResult {
T::DispatchOrigin::try_origin(origin).map(|_| ()).or_else(ensure_root)?;
Expand Down Expand Up @@ -202,6 +203,7 @@ pub mod module {
}

/// Cancel gradually_update to adjust numeric parameter.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::cancel_gradually_update())]
pub fn cancel_gradually_update(origin: OriginFor<T>, key: StorageKeyBytes<T>) -> DispatchResult {
T::DispatchOrigin::try_origin(origin).map(|_| ()).or_else(ensure_root)?;
Expand Down
1 change: 1 addition & 0 deletions oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub mod module {
/// Feed the external value.
///
/// Require authorized operator.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::feed_values(values.len() as u32))]
pub fn feed_values(
origin: OriginFor<T>,
Expand Down
8 changes: 8 additions & 0 deletions payments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ pub mod pallet {
/// the option to add a remark, this remark can then be used to run
/// custom logic and trigger alternate payment flows. the specified
/// amount.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::pay(T::MaxRemarkLength::get()))]
pub fn pay(
origin: OriginFor<T>,
Expand Down Expand Up @@ -314,6 +315,7 @@ pub mod pallet {

/// Release any created payment, this will transfer the reserved amount
/// from the creator of the payment to the assigned recipient
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::release())]
pub fn release(origin: OriginFor<T>, to: T::AccountId) -> DispatchResultWithPostInfo {
let from = ensure_signed(origin)?;
Expand All @@ -332,6 +334,7 @@ pub mod pallet {
/// Cancel a payment in created state, this will release the reserved
/// back to creator of the payment. This extrinsic can only be called by
/// the recipient of the payment
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::cancel())]
pub fn cancel(origin: OriginFor<T>, creator: T::AccountId) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Expand All @@ -354,6 +357,7 @@ pub mod pallet {
/// recipient of the payment.
/// This extrinsic allows the assigned judge to
/// cancel/release/partial_release the payment.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::resolve_payment())]
pub fn resolve_payment(
origin: OriginFor<T>,
Expand Down Expand Up @@ -389,6 +393,7 @@ pub mod pallet {
/// Allow the creator of a payment to initiate a refund that will return
/// the funds after a configured amount of time that the reveiver has to
/// react and opose the request
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::request_refund())]
pub fn request_refund(origin: OriginFor<T>, recipient: T::AccountId) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Expand Down Expand Up @@ -436,6 +441,7 @@ pub mod pallet {
/// payment creator This does not cancel the request, instead sends the
/// payment to a NeedsReview state The assigned resolver account can
/// then change the state of the payment after review.
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::dispute_refund())]
pub fn dispute_refund(origin: OriginFor<T>, creator: T::AccountId) -> DispatchResultWithPostInfo {
use PaymentState::*;
Expand Down Expand Up @@ -482,6 +488,7 @@ pub mod pallet {
// using the `accept_and_pay` extrinsic. The payment will be in
// PaymentRequested State and can only be modified by the `accept_and_pay`
// extrinsic.
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::request_payment())]
pub fn request_payment(
origin: OriginFor<T>,
Expand Down Expand Up @@ -510,6 +517,7 @@ pub mod pallet {
// This extrinsic allows the sender to fulfill a payment request created by a
// recipient. The amount will be transferred to the recipient and payment
// removed from storage
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::accept_and_pay())]
pub fn accept_and_pay(origin: OriginFor<T>, to: T::AccountId) -> DispatchResultWithPostInfo {
let from = ensure_signed(origin)?;
Expand Down
5 changes: 5 additions & 0 deletions tokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ pub mod module {
/// - `dest`: The recipient of the transfer.
/// - `currency_id`: currency type.
/// - `amount`: free balance amount to tranfer.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::transfer())]
pub fn transfer(
origin: OriginFor<T>,
Expand Down Expand Up @@ -493,6 +494,7 @@ pub mod module {
/// the sender account to be killed (false), or transfer everything
/// except at least the existential deposit, which will guarantee to
/// keep the sender account alive (true).
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::transfer_all())]
pub fn transfer_all(
origin: OriginFor<T>,
Expand All @@ -519,6 +521,7 @@ pub mod module {
/// - `dest`: The recipient of the transfer.
/// - `currency_id`: currency type.
/// - `amount`: free balance amount to tranfer.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::transfer_keep_alive())]
pub fn transfer_keep_alive(
origin: OriginFor<T>,
Expand All @@ -541,6 +544,7 @@ pub mod module {
/// - `dest`: The recipient of the transfer.
/// - `currency_id`: currency type.
/// - `amount`: free balance amount to tranfer.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::force_transfer())]
pub fn force_transfer(
origin: OriginFor<T>,
Expand All @@ -563,6 +567,7 @@ pub mod module {
/// existential deposit, it will reap the `AccountInfo`.
///
/// The dispatch origin for this call is `root`.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::set_balance())]
pub fn set_balance(
origin: OriginFor<T>,
Expand Down
4 changes: 4 additions & 0 deletions vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ pub mod module {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::claim((<T as Config>::MaxVestingSchedules::get() / 2) as u32))]
pub fn claim(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand All @@ -256,6 +257,7 @@ pub mod module {
Ok(())
}

#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::vested_transfer())]
pub fn vested_transfer(
origin: OriginFor<T>,
Expand All @@ -282,6 +284,7 @@ pub mod module {
Ok(())
}

#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::update_vesting_schedules(vesting_schedules.len() as u32))]
pub fn update_vesting_schedules(
origin: OriginFor<T>,
Expand All @@ -297,6 +300,7 @@ pub mod module {
Ok(())
}

#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::claim((<T as Config>::MaxVestingSchedules::get() / 2) as u32))]
pub fn claim_for(origin: OriginFor<T>, dest: <T::Lookup as StaticLookup>::Source) -> DispatchResult {
let _ = ensure_signed(origin)?;
Expand Down
6 changes: 6 additions & 0 deletions weight-meter/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod test_module {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(50_000)]
#[orml_weight_meter::start]
pub fn expect_100(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Expand All @@ -29,6 +30,7 @@ pub mod test_module {
Ok(Some(orml_weight_meter::used_weight()).into())
}

#[pallet::call_index(1)]
#[pallet::weight(50_000)]
#[orml_weight_meter::start]
pub fn expect_500(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Expand All @@ -43,6 +45,7 @@ pub mod test_module {
Ok(Some(orml_weight_meter::used_weight()).into())
}

#[pallet::call_index(2)]
#[pallet::weight(50_000)]
#[orml_weight_meter::start]
pub fn expect_max_weight(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Expand All @@ -54,6 +57,7 @@ pub mod test_module {
Ok(Some(orml_weight_meter::used_weight()).into())
}

#[pallet::call_index(3)]
#[pallet::weight(50_000)]
#[orml_weight_meter::start]
pub fn expect_100_or_200(origin: OriginFor<T>, branch: bool) -> DispatchResultWithPostInfo {
Expand All @@ -68,6 +72,7 @@ pub mod test_module {
Ok(Some(orml_weight_meter::used_weight()).into())
}

#[pallet::call_index(4)]
#[pallet::weight(50_000)]
#[orml_weight_meter::start]
pub fn nested_inner_methods(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Expand All @@ -78,6 +83,7 @@ pub mod test_module {
Ok(Some(orml_weight_meter::used_weight()).into())
}

#[pallet::call_index(5)]
#[pallet::weight(50_000)]
#[orml_weight_meter::start]
pub fn nested_extrinsic(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Expand Down
1 change: 1 addition & 0 deletions xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub mod module {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Send an XCM message as parachain sovereign.
#[pallet::call_index(0)]
#[pallet::weight(100_000_000)]
pub fn send_as_sovereign(
origin: OriginFor<T>,
Expand Down
Loading

0 comments on commit f94894f

Please sign in to comment.