Skip to content

Commit

Permalink
Add explicit call index see: paritytech/substrate#12891
Browse files Browse the repository at this point in the history
  • Loading branch information
hounsette committed Feb 3, 2023
1 parent 4cea6b4 commit 95988c7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pallets/allocations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub mod pallet {
/// Optimized allocation call, which will batch allocations of various amounts
/// and destinations and together. This allow us to be much more efficient and thus
/// increase our chain's capacity in handling these transactions.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::allocate(batch.len().try_into().unwrap_or_else(|_| T::MaxAllocs::get())).saturating_add(T::WeightInfo::checked_update_session_quota()))]
pub fn batch(
origin: OriginFor<T>,
Expand All @@ -227,7 +228,7 @@ pub mod pallet {
));
Ok(dispatch_info)
}

#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::set_curve_starting_block())]
pub fn set_curve_starting_block(
origin: OriginFor<T>,
Expand Down
4 changes: 4 additions & 0 deletions pallets/grants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Claim funds that have been vested so far
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::claim())]
pub fn claim(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Expand All @@ -159,6 +160,7 @@ pub mod pallet {
}

/// Wire funds to be vested by the receiver
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::add_vesting_schedule())]
pub fn add_vesting_schedule(
origin: OriginFor<T>,
Expand All @@ -177,6 +179,7 @@ pub mod pallet {
/// claimed they will be auto claimed for the given user. If `limit_to_free_balance`
/// is set to true we will not error if the free balance of `who` has less coins
/// than what was granted and is being revoked (useful if the state was corrupted).
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::cancel_all_vesting_schedules())]
pub fn cancel_all_vesting_schedules(
origin: OriginFor<T>,
Expand Down Expand Up @@ -211,6 +214,7 @@ pub mod pallet {

/// Allows the `CancelOrigin` to renounce to its privileges of being able to cancel
/// `who`'s vesting schedules.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::renounce())]
pub fn renounce(origin: OriginFor<T>, who: <T::Lookup as StaticLookup>::Source) -> DispatchResultWithPostInfo {
T::CancelOrigin::try_origin(origin).map(|_| ()).or_else(ensure_root)?;
Expand Down
1 change: 1 addition & 0 deletions pallets/mandate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Let the configured origin dispatch a call as root
#[pallet::call_index(0)]
#[pallet::weight({
let dispatch_info = call.get_dispatch_info();
(
Expand Down
3 changes: 3 additions & 0 deletions pallets/reserve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Spend `amount` funds from the reserve account to `to`.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::spend())]
pub fn spend(origin: OriginFor<T>, to: T::AccountId, amount: BalanceOf<T, I>) -> DispatchResultWithPostInfo {
T::ExternalOrigin::try_origin(origin).map(|_| ()).or_else(ensure_root)?;
Expand All @@ -85,6 +86,7 @@ pub mod pallet {
}

/// Deposit `amount` tokens in the treasure account
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::tip())]
pub fn tip(origin: OriginFor<T>, amount: BalanceOf<T, I>) -> DispatchResultWithPostInfo {
let tipper = ensure_signed(origin)?;
Expand All @@ -98,6 +100,7 @@ pub mod pallet {

#[allow(clippy::boxed_local)]
/// Dispatch a call as coming from the reserve account
#[pallet::call_index(2)]
#[pallet::weight({
let dispatch_info = call.get_dispatch_info();
(
Expand Down
17 changes: 17 additions & 0 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ pub mod pallet {
/// Set the validators who cannot be slashed (if any).
///
/// The dispatch origin must be Root.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::set_invulnerables(invulnerables.len() as u32))]
pub fn set_invulnerables(origin: OriginFor<T>, invulnerables: Vec<T::AccountId>) -> DispatchResultWithPostInfo {
T::CancelOrigin::try_origin(origin).map(|_| ()).or_else(ensure_root)?;
Expand All @@ -187,6 +188,7 @@ pub mod pallet {
}
/// Set the total number of validator selected per round
/// - changes are not applied until the start of the next round
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::set_total_validator_per_round(*new))]
pub fn set_total_validator_per_round(origin: OriginFor<T>, new: u32) -> DispatchResultWithPostInfo {
T::CancelOrigin::try_origin(origin).map(|_| ()).or_else(ensure_root)?;
Expand All @@ -196,6 +198,7 @@ pub mod pallet {
Self::deposit_event(Event::TotalSelectedSet(old, new));
Ok(().into())
}
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::set_staking_limits())]
pub fn set_staking_limits(
origin: OriginFor<T>,
Expand Down Expand Up @@ -249,6 +252,7 @@ pub mod pallet {
Ok(().into())
}
/// Join the set of validators pool
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::validator_join_pool())]
pub fn validator_join_pool(origin: OriginFor<T>, bond: BalanceOf<T>) -> DispatchResultWithPostInfo {
log::debug!("validator_join_pool:[{:#?}] - Entry!!!", line!(),);
Expand Down Expand Up @@ -311,6 +315,7 @@ pub mod pallet {
/// the account is immediately removed from the validator pool
/// to prevent selection as a validator, but unbonding
/// is executed with a delay of `BondedDuration` rounds.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::validator_exit_pool())]
pub fn validator_exit_pool(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let validator = ensure_signed(origin)?;
Expand Down Expand Up @@ -347,6 +352,7 @@ pub mod pallet {
Ok(().into())
}
/// Bond more for validator
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::validator_bond_more())]
pub fn validator_bond_more(origin: OriginFor<T>, more: BalanceOf<T>) -> DispatchResultWithPostInfo {
let validator = ensure_signed(origin)?;
Expand Down Expand Up @@ -391,6 +397,7 @@ pub mod pallet {
Ok(().into())
}
/// Bond less for validator
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::validator_bond_less())]
pub fn validator_bond_less(origin: OriginFor<T>, less: BalanceOf<T>) -> DispatchResultWithPostInfo {
let validator = ensure_signed(origin)?;
Expand Down Expand Up @@ -435,6 +442,7 @@ pub mod pallet {
}
/// If caller is not a nominator, then join the set of nominators
/// If caller is a nominator, then makes nomination to change their nomination state
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::nominator_nominate())]
pub fn nominator_nominate(
origin: OriginFor<T>,
Expand Down Expand Up @@ -540,6 +548,7 @@ pub mod pallet {
Ok(().into())
}
/// Revoke an existing nomination
#[pallet::call_index(8)]
#[pallet::weight(T::WeightInfo::nominator_denominate())]
pub fn nominator_denominate(origin: OriginFor<T>, validator: T::AccountId) -> DispatchResultWithPostInfo {
let acc = ensure_signed(origin)?;
Expand All @@ -552,6 +561,7 @@ pub mod pallet {
}

/// Quit the set of nominators and, by implication, revoke all ongoing nominations
#[pallet::call_index(9)]
#[pallet::weight(T::WeightInfo::nominator_denominate_all())]
pub fn nominator_denominate_all(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let acc = ensure_signed(origin)?;
Expand All @@ -565,6 +575,7 @@ pub mod pallet {
Ok(().into())
}
/// Bond more for nominators with respect to a specific validator
#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::nominator_bond_more())]
pub fn nominator_bond_more(
origin: OriginFor<T>,
Expand Down Expand Up @@ -623,6 +634,7 @@ pub mod pallet {
Ok(().into())
}
/// Bond less for nominators with respect to a specific nominated validator
#[pallet::call_index(11)]
#[pallet::weight(T::WeightInfo::nominator_bond_less())]
pub fn nominator_bond_less(
origin: OriginFor<T>,
Expand Down Expand Up @@ -676,6 +688,7 @@ pub mod pallet {
Ok(().into())
}

#[pallet::call_index(12)]
#[pallet::weight(T::WeightInfo::nominator_move_nomination())]
pub fn nominator_move_nomination(
origin: OriginFor<T>,
Expand Down Expand Up @@ -802,6 +815,7 @@ pub mod pallet {
Ok(().into())
}

#[pallet::call_index(13)]
#[pallet::weight(T::WeightInfo::unbond_frozen())]
pub fn unbond_frozen(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let nominator_acc = ensure_signed(origin)?;
Expand Down Expand Up @@ -842,6 +856,7 @@ pub mod pallet {
Ok(().into())
}

#[pallet::call_index(14)]
#[pallet::weight(T::WeightInfo::withdraw_unbonded())]
pub fn withdraw_unbonded(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let acc = ensure_signed(origin)?;
Expand Down Expand Up @@ -889,6 +904,7 @@ pub mod pallet {
Ok(().into())
}

#[pallet::call_index(15)]
#[pallet::weight(T::WeightInfo::withdraw_staking_rewards())]
pub fn withdraw_staking_rewards(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let acc = ensure_signed(origin)?;
Expand Down Expand Up @@ -924,6 +940,7 @@ pub mod pallet {
/// Can be called by the `T::SlashCancelOrigin`.
///
/// Parameters: session index and validator list of the slashes for that session to kill.
#[pallet::call_index(16)]
#[pallet::weight(T::WeightInfo::slash_cancel_deferred(*session_idx, controllers.len() as u32))]
pub fn slash_cancel_deferred(
origin: OriginFor<T>,
Expand Down

0 comments on commit 95988c7

Please sign in to comment.