Skip to content

Commit

Permalink
Use call_index attribute to fix warning and CI step build-all-benchma…
Browse files Browse the repository at this point in the history
…rks-packages (#3557)

- use `#[pallet::call_index(0)]` for each callable function in pallet
- it is by recommendation:

```
 Please ensure that all calls have the `pallet::call_index` attribute or that the
                     `dev-mode` of the pallet is enabled. For more info see:
                     <paritytech/substrate#12891> and
                     <paritytech/substrate#11381>.
```
- it will fix CI step build-all-benchmarks-packages
  • Loading branch information
RustNinja committed May 4, 2023
1 parent 3303bd1 commit 9f426fd
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 1 deletion.
10 changes: 10 additions & 0 deletions code/parachain/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub mod pallet {
/// - If the account has insufficient free balance to make the transfer, or if `keep_alive`
/// cannot be respected.
/// - If the `dest` cannot be looked up.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::transfer())]
pub fn transfer(
origin: OriginFor<T>,
Expand All @@ -175,6 +176,7 @@ pub mod pallet {
/// - If the account has insufficient free balance to make the transfer, or if `keep_alive`
/// cannot be respected.
/// - If the `dest` cannot be looked up.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::transfer_native())]
pub fn transfer_native(
origin: OriginFor<T>,
Expand All @@ -195,6 +197,7 @@ pub mod pallet {
/// - If the account has insufficient free balance to make the transfer, or if `keep_alive`
/// cannot be respected.
/// - If the `dest` cannot be looked up.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::force_transfer())]
pub fn force_transfer(
origin: OriginFor<T>,
Expand All @@ -219,6 +222,7 @@ pub mod pallet {
/// cannot be respected.
/// - If the `dest` cannot be looked up.
#[pallet::weight(T::WeightInfo::force_transfer_native())]
#[pallet::call_index(3)]
pub fn force_transfer_native(
origin: OriginFor<T>,
source: <T::Lookup as StaticLookup>::Source,
Expand All @@ -239,6 +243,7 @@ pub mod pallet {
/// - When `origin` is not signed.
/// - If the `dest` cannot be looked up.
#[pallet::weight(T::WeightInfo::transfer_all())]
#[pallet::call_index(4)]
pub fn transfer_all(
origin: OriginFor<T>,
asset: T::AssetId,
Expand All @@ -265,6 +270,7 @@ pub mod pallet {
/// - When `origin` is not signed.
/// - If the `dest` cannot be looked up.
#[pallet::weight(T::WeightInfo::transfer_all_native())]
#[pallet::call_index(5)]
pub fn transfer_all_native(
origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source,
Expand All @@ -286,6 +292,7 @@ pub mod pallet {
/// Creates a new asset, minting `amount` of funds into the `dest` account. Intended to be
/// used for creating wrapped assets, not associated with any project.
#[pallet::weight(T::WeightInfo::mint_initialize())]
#[pallet::call_index(6)]
pub fn mint_initialize(
origin: OriginFor<T>,
#[pallet::compact] amount: T::Balance,
Expand All @@ -302,6 +309,7 @@ pub mod pallet {
/// account can use the democracy pallet to mint further assets, or if the governance_origin
/// is set to an owned account, using signed transactions. In general the
/// `governance_origin` should be generated from the pallet id.
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::mint_initialize())]
pub fn mint_initialize_with_governance(
origin: OriginFor<T>,
Expand All @@ -319,6 +327,7 @@ pub mod pallet {
}

/// Mints `amount` of `asset_id` into the `dest` account.
#[pallet::call_index(8)]
#[pallet::weight(T::WeightInfo::mint_into())]
pub fn mint_into(
origin: OriginFor<T>,
Expand All @@ -333,6 +342,7 @@ pub mod pallet {
}

/// Burns `amount` of `asset_id` into the `dest` account.
#[pallet::call_index(9)]
#[pallet::weight(T::WeightInfo::burn_from())]
pub fn burn_from(
origin: OriginFor<T>,
Expand Down
3 changes: 3 additions & 0 deletions code/parachain/frame/bonded-finance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub mod pallet {
/// parameter.
///
/// Emits a `NewOffer`.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::offer())]
pub fn offer(
origin: OriginFor<T>,
Expand Down Expand Up @@ -231,6 +232,7 @@ pub mod pallet {
///
/// Emits a `NewBond`.
/// Possibly Emits a `OfferCompleted`.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::bond())]
pub fn bond(
origin: OriginFor<T>,
Expand All @@ -251,6 +253,7 @@ pub mod pallet {
/// The dispatch origin for this call must be _Signed_ and the sender must be `AdminOrigin`
///
/// Emits a `OfferCancelled`.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::cancel())]
#[transactional]
pub fn cancel(origin: OriginFor<T>, offer_id: T::BondOfferId) -> DispatchResult {
Expand Down
7 changes: 7 additions & 0 deletions code/parachain/frame/crowdloan-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Initialize the pallet at the current timestamp.
#[pallet::call_index(0)]
#[pallet::weight(<T as Config>::WeightInfo::initialize(TotalContributors::<T>::get()))]
pub fn initialize(origin: OriginFor<T>) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
Expand All @@ -275,6 +276,7 @@ pub mod pallet {
}

/// Initialize the pallet at the given timestamp.
#[pallet::call_index(1)]
#[pallet::weight(<T as Config>::WeightInfo::initialize(TotalContributors::<T>::get()))]
pub fn initialize_at(origin: OriginFor<T>, at: MomentOf<T>) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
Expand All @@ -290,6 +292,7 @@ pub mod pallet {
/// already has a reward, it will be replaced by the new reward value.
///
/// Can only be called before `initialize`.
#[pallet::call_index(2)]
#[pallet::weight(<T as Config>::WeightInfo::populate(rewards.len() as _))]
pub fn populate(
origin: OriginFor<T>,
Expand All @@ -308,6 +311,7 @@ pub mod pallet {
/// ```haskell
/// proof = sign (concat prefix (hex reward_account))
/// ```
#[pallet::call_index(3)]
#[pallet::weight(<T as Config>::WeightInfo::associate(TotalContributors::<T>::get()))]
pub fn associate(
origin: OriginFor<T>,
Expand All @@ -321,6 +325,7 @@ pub mod pallet {
/// Claim a reward from the associated reward account.
/// A previous call to `associate` should have been made.
/// If logic gate pass, no fees are applied.
#[pallet::call_index(4)]
#[pallet::weight(<T as Config>::WeightInfo::claim(TotalContributors::<T>::get()))]
pub fn claim(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let reward_account = ensure_signed(origin)?;
Expand All @@ -331,6 +336,7 @@ pub mod pallet {
Ok(Pays::No.into())
}

#[pallet::call_index(5)]
#[pallet::weight(<T as Config>::WeightInfo::unlock_rewards_for(reward_accounts.len() as _))]
pub fn unlock_rewards_for(
origin: OriginFor<T>,
Expand All @@ -343,6 +349,7 @@ pub mod pallet {

/// Adds all accounts in the `additions` vector. Add may be called even if the pallet has
/// been initialized.
#[pallet::call_index(6)]
#[pallet::weight(<T as Config>::WeightInfo::populate(additions.len() as _))]
pub fn add(
origin: OriginFor<T>,
Expand Down
2 changes: 2 additions & 0 deletions code/parachain/frame/currency-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::add_range())]
pub fn add_range(origin: OriginFor<T>, length: u64) -> DispatchResultWithPostInfo {
T::AddOrigin::ensure_origin(origin)?;
Expand All @@ -149,6 +150,7 @@ pub mod pallet {
}

/// Sets metadata
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::set_metadata())]
pub fn set_metadata(
origin: OriginFor<T>,
Expand Down
3 changes: 3 additions & 0 deletions code/parachain/frame/governance-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Sets the value of an `asset_id` to the signed account id. Only callable by root.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::set())]
pub fn set(
origin: OriginFor<T>,
Expand All @@ -87,6 +88,7 @@ pub mod pallet {
}

/// Sets the value of an `asset_id` to root. Only callable by root.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::grant_root())]
pub fn grant_root(
origin: OriginFor<T>,
Expand All @@ -99,6 +101,7 @@ pub mod pallet {
}

/// Removes mapping of an `asset_id`. Only callable by root.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::remove())]
pub fn remove(origin: OriginFor<T>, asset_id: T::AssetId) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
Expand Down
6 changes: 6 additions & 0 deletions code/parachain/frame/pablo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ pub mod pallet {
/// assets already exists in the runtime.
///
/// Emits `PoolCreated` event when successful.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::create())]
pub fn create(origin: OriginFor<T>, pool: PoolInitConfigurationOf<T>) -> DispatchResult {
T::PoolCreationOrigin::ensure_origin(origin)?;
Expand All @@ -356,6 +357,7 @@ pub mod pallet {
/// Execute a buy order on pool.
///
/// Emits `Swapped` event when successful.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::buy())]
pub fn buy(
origin: OriginFor<T>,
Expand All @@ -374,6 +376,7 @@ pub mod pallet {
/// The `quote_amount` is always the quote asset amount (A/B => B), (B/A => A).
///
/// Emits `Swapped` event when successful.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::swap())]
pub fn swap(
origin: OriginFor<T>,
Expand All @@ -390,6 +393,7 @@ pub mod pallet {
/// Add liquidity to the given pool.
///
/// Emits `LiquidityAdded` event when successful.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::add_liquidity())]
pub fn add_liquidity(
origin: OriginFor<T>,
Expand All @@ -406,6 +410,7 @@ pub mod pallet {
/// Remove liquidity from the given pool.
///
/// Emits `LiquidityRemoved` event when successful.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::remove_liquidity())]
pub fn remove_liquidity(
origin: OriginFor<T>,
Expand All @@ -418,6 +423,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(5)]
#[pallet::weight(10_000)]
#[transactional]
pub fn enable_twap(origin: OriginFor<T>, pool_id: T::PoolId) -> DispatchResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub mod pallet {
///
/// If `asset_id` is `None`, then native asset is used.
/// Else new asset is configured and ED is on hold.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::set_payment_asset())]
pub fn set_payment_asset(
origin: OriginFor<T>,
Expand Down
10 changes: 9 additions & 1 deletion code/parachain/frame/vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ pub mod pallet {
/// - When the origin is not signed.
/// - When `deposit < CreationDeposit`.
/// - Origin has insufficient funds to lock the deposit.
#[pallet::call_index(0)]
#[transactional]
#[pallet::weight(<T as Config>::WeightInfo::create())]
pub fn create(
Expand Down Expand Up @@ -422,6 +423,7 @@ pub mod pallet {
///
/// A tombstoned vault still allows for withdrawals but blocks deposits, and requests all
/// strategies to return their funds.
#[pallet::call_index(1)]
#[pallet::weight(<T as Config>::WeightInfo::claim_surcharge())]
pub fn claim_surcharge(
origin: OriginFor<T>,
Expand Down Expand Up @@ -469,7 +471,7 @@ pub mod pallet {
}
})
}

#[pallet::call_index(2)]
#[pallet::weight(<T as Config>::WeightInfo::add_surcharge())]
pub fn add_surcharge(
origin: OriginFor<T>,
Expand All @@ -495,6 +497,7 @@ pub mod pallet {
})
}

#[pallet::call_index(3)]
#[pallet::weight(<T as Config>::WeightInfo::delete_tombstoned())]
pub fn delete_tombstoned(
origin: OriginFor<T>,
Expand Down Expand Up @@ -542,6 +545,7 @@ pub mod pallet {
/// # Errors
/// - When the origin is not signed.
/// - When `deposit < MinimumDeposit`.
#[pallet::call_index(4)]
#[pallet::weight(<T as Config>::WeightInfo::deposit())]
pub fn deposit(
origin: OriginFor<T>,
Expand All @@ -563,6 +567,7 @@ pub mod pallet {
/// - When the origin is not signed.
/// - When `lp_amount < MinimumWithdrawal`.
/// - When the vault has insufficient amounts reserved.
#[pallet::call_index(5)]
#[pallet::weight(<T as Config>::WeightInfo::withdraw())]
pub fn withdraw(
origin: OriginFor<T>,
Expand All @@ -583,6 +588,7 @@ pub mod pallet {
/// # Errors
/// - When the origin is not root.
/// - When `vault` does not exist.
#[pallet::call_index(6)]
#[pallet::weight(<T as Config>::WeightInfo::emergency_shutdown())]
pub fn emergency_shutdown(
origin: OriginFor<T>,
Expand All @@ -602,6 +608,7 @@ pub mod pallet {
/// # Errors
/// - When the origin is not root.
/// - When `vault` does not exist.
#[pallet::call_index(7)]
#[pallet::weight(<T as Config>::WeightInfo::start_())]
pub fn start(origin: OriginFor<T>, vault: T::VaultId) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
Expand All @@ -618,6 +625,7 @@ pub mod pallet {
///
/// # Emits
/// - Event::LiquidateStrategy
#[pallet::call_index(8)]
#[pallet::weight(10_000)]
pub fn liquidate_strategy(
origin: OriginFor<T>,
Expand Down
3 changes: 3 additions & 0 deletions code/parachain/frame/vault/src/mocks/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Mints new tokens and sends them to self, mocking the generating of revenue through DeFi.
#[pallet::call_index(0)]
#[pallet::weight(10_000)]
pub fn generate_revenue(
origin: OriginFor<T>,
Expand All @@ -81,6 +82,7 @@ pub mod pallet {
}

/// Reports the current balance to the vault.
#[pallet::call_index(1)]
#[pallet::weight(10_000)]
pub fn report(origin: OriginFor<T>, vault: VaultIdOf<T>) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
Expand All @@ -92,6 +94,7 @@ pub mod pallet {
}

/// Queries the vault for the current re-balance strategy and executes it.
#[pallet::call_index(2)]
#[pallet::weight(10_000)]
pub fn rebalance(origin: OriginFor<T>, vault: VaultIdOf<T>) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
Expand Down

0 comments on commit 9f426fd

Please sign in to comment.