Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dispatch call indices #1036

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion zrml/authorized/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Overwrites already provided outcomes for the same market and account.
#[frame_support::transactional]
#[pallet::call_index(0)]
#[pallet::weight(
T::WeightInfo::authorize_market_outcome_first_report(CacheSize::get()).max(
T::WeightInfo::authorize_market_outcome_existing_report(),
)
)]
#[frame_support::transactional]
pub fn authorize_market_outcome(
origin: OriginFor<T>,
market_id: MarketIdOf<T>,
Expand Down
3 changes: 3 additions & 0 deletions zrml/court/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
// MARK(non-transactional): `remove_juror_from_all_courts_of_all_markets` is infallible.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::exit_court())]
pub fn exit_court(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand All @@ -111,6 +112,7 @@ mod pallet {
}

// MARK(non-transactional): Once `reserve_named` is successful, `insert` won't fail.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::join_court())]
pub fn join_court(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand All @@ -128,6 +130,7 @@ mod pallet {
}

// MARK(non-transactional): No fallible storage operation is performed.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::vote())]
pub fn vote(
origin: OriginFor<T>,
Expand Down
17 changes: 11 additions & 6 deletions zrml/global-disputes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Forecasting Technologies LTD.
// Copyright 2022-2023 Forecasting Technologies LTD.
//
// This file is part of Zeitgeist.
//
Expand Down Expand Up @@ -209,8 +209,9 @@ mod pallet {
///
/// Complexity: `O(n)`, where `n` is the number of owner(s) of the winner outcome
/// in the case that this gets called for an already finished global dispute.
#[frame_support::transactional]
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::add_vote_outcome(T::MaxOwners::get()))]
#[frame_support::transactional]
pub fn add_vote_outcome(
origin: OriginFor<T>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -258,11 +259,12 @@ mod pallet {
///
/// Complexity: `O(n)`,
/// where `n` is the number of all existing outcomes for a global dispute.
#[frame_support::transactional]
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::purge_outcomes(
T::RemoveKeysLimit::get(),
T::MaxOwners::get(),
))]
#[frame_support::transactional]
pub fn purge_outcomes(
origin: OriginFor<T>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -314,12 +316,13 @@ mod pallet {
/// # Weight
///
/// Complexity: `O(n)`, where `n` is the number of owners for the winning outcome.
#[frame_support::transactional]
#[pallet::call_index(2)]
#[pallet::weight(
T::WeightInfo::reward_outcome_owner_no_funds(T::MaxOwners::get()).max(
T::WeightInfo::reward_outcome_owner_with_funds(T::MaxOwners::get()),
)
)]
#[frame_support::transactional]
pub fn reward_outcome_owner(
origin: OriginFor<T>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -396,11 +399,12 @@ mod pallet {
///
/// Complexity: `O(n + m)`, where `n` is the number of all current votes on global disputes,
/// and `m` is the number of owners for the specified outcome.
#[frame_support::transactional]
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::vote_on_outcome(
T::MaxOwners::get(),
T::MaxGlobalDisputeVotes::get(),
))]
#[frame_support::transactional]
pub fn vote_on_outcome(
origin: OriginFor<T>,
#[pallet::compact] market_id: MarketIdOf<T>,
Expand Down Expand Up @@ -482,7 +486,7 @@ mod pallet {
///
/// Complexity: `O(n + m)`, where `n` is the number of all current votes on global disputes,
/// and `m` is the number of owners for the winning outcome.
#[frame_support::transactional]
#[pallet::call_index(4)]
#[pallet::weight(
T::WeightInfo::unlock_vote_balance_set(
T::MaxGlobalDisputeVotes::get(),
Expand All @@ -493,6 +497,7 @@ mod pallet {
T::MaxOwners::get(),
))
)]
#[frame_support::transactional]
pub fn unlock_vote_balance(
origin: OriginFor<T>,
voter: AccountIdLookupOf<T>,
Expand Down
3 changes: 2 additions & 1 deletion zrml/liquidity-mining/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Forecasting Technologies LTD.
// Copyright 2022-2023 Forecasting Technologies LTD.
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
Expand Down Expand Up @@ -87,6 +87,7 @@ mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::set_per_block_distribution())]
// MARK(non-transactional): `set_per_block_distribution` is infallible.
pub fn set_per_block_distribution(
Expand Down
4 changes: 4 additions & 0 deletions zrml/orderbook-v1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2022-2023 Forecasting Technologies LTD.
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
Expand Down Expand Up @@ -67,6 +68,7 @@ mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(
T::WeightInfo::cancel_order_ask().max(T::WeightInfo::cancel_order_bid())
)]
Expand Down Expand Up @@ -112,6 +114,7 @@ mod pallet {
}
}

#[pallet::call_index(1)]
#[pallet::weight(
T::WeightInfo::fill_order_ask().max(T::WeightInfo::fill_order_bid())
)]
Expand Down Expand Up @@ -178,6 +181,7 @@ mod pallet {
}
}

#[pallet::call_index(2)]
#[pallet::weight(
T::WeightInfo::make_order_ask().max(T::WeightInfo::make_order_bid())
)]
Expand Down
17 changes: 17 additions & 0 deletions zrml/prediction-markets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ mod pallet {
///
/// Must be called by `DestroyOrigin`. Bonds (unless already returned) are slashed without
/// exception. Can currently only be used for destroying CPMM markets.
#[pallet::call_index(0)]
#[pallet::weight((
T::WeightInfo::admin_destroy_reported_market(
T::MaxCategories::get().into(),
Expand Down Expand Up @@ -419,6 +420,7 @@ mod pallet {
//
// Within the same block, operations that interact with the activeness of the same
// market will behave differently before and after this call.
#[pallet::call_index(1)]
#[pallet::weight((
T::WeightInfo::admin_move_market_to_closed(
CacheSize::get(), CacheSize::get()), Pays::No
Expand Down Expand Up @@ -452,6 +454,7 @@ mod pallet {
///
/// Complexity: `O(n + m)`, where `n` is the number of market ids
/// per dispute / report block, m is the number of disputes.
#[pallet::call_index(2)]
#[pallet::weight((
T::WeightInfo::admin_move_market_to_resolved_scalar_reported(CacheSize::get())
.max(
Expand Down Expand Up @@ -512,6 +515,7 @@ mod pallet {
/// # Weight
///
/// Complexity: `O(1)`
#[pallet::call_index(3)]
#[pallet::weight((T::WeightInfo::approve_market(), Pays::No))]
#[transactional]
pub fn approve_market(
Expand Down Expand Up @@ -564,6 +568,7 @@ mod pallet {
/// # Weight
///
/// Complexity: `O(edit_reason.len())`
#[pallet::call_index(4)]
#[pallet::weight((
T::WeightInfo::request_edit(edit_reason.len() as u32),
Pays::No,
Expand Down Expand Up @@ -609,6 +614,7 @@ mod pallet {
// The worst-case scenario is assumed
// and the correct weight is calculated at the end of this function.
// This also occurs in numerous other functions.
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::buy_complete_set(T::MaxCategories::get().into()))]
#[transactional]
pub fn buy_complete_set(
Expand All @@ -625,6 +631,7 @@ mod pallet {
/// # Weight
///
/// Complexity: `O(n)`, where `n` is the number of outstanding disputes.
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::dispute_authorized())]
#[transactional]
pub fn dispute(
Expand Down Expand Up @@ -701,6 +708,7 @@ mod pallet {
/// where `n` is the number of outcome assets for the categorical market
/// and `m` is the number of market ids,
/// which open at the same time as the specified market.
#[pallet::call_index(7)]
#[pallet::weight(
T::WeightInfo::create_market(CacheSize::get())
.saturating_add(T::WeightInfo::buy_complete_set(T::MaxCategories::get().into()))
Expand Down Expand Up @@ -763,6 +771,7 @@ mod pallet {
///
/// Complexity: `O(n)`, where `n` is the number of market ids,
/// which close at the same time as the specified market.
#[pallet::call_index(8)]
#[pallet::weight(T::WeightInfo::create_market(CacheSize::get()))]
#[transactional]
pub fn create_market(
Expand Down Expand Up @@ -851,6 +860,7 @@ mod pallet {
///
/// Complexity: `O(n)`, where `n` is the number of markets
/// which end at the same time as the market before the edit.
#[pallet::call_index(9)]
#[pallet::weight(T::WeightInfo::edit_market(CacheSize::get()))]
#[transactional]
pub fn edit_market(
Expand Down Expand Up @@ -927,6 +937,7 @@ mod pallet {
/// where `n` is the number of outcome assets for the categorical market,
/// and `m` is the number of market ids,
/// which open at the same time as the specified market.
#[pallet::call_index(10)]
#[pallet::weight(
T::WeightInfo::buy_complete_set(T::MaxCategories::get().into())
.saturating_add(
Expand Down Expand Up @@ -978,6 +989,7 @@ mod pallet {
/// where `n` is the number of outcome assets for the categorical market,
/// and `m` is the number of market ids,
/// which open at the same time as the specified market.
#[pallet::call_index(11)]
#[pallet::weight(
T::WeightInfo::deploy_swap_pool_for_market_open_pool(weights.len() as u32)
.max(
Expand Down Expand Up @@ -1085,6 +1097,7 @@ mod pallet {
/// # Weight
///
/// Complexity: `O(1)`
#[pallet::call_index(12)]
#[pallet::weight(T::WeightInfo::redeem_shares_categorical()
.max(T::WeightInfo::redeem_shares_scalar())
)]
Expand Down Expand Up @@ -1229,6 +1242,7 @@ mod pallet {
/// which open at the same time as the specified market,
/// and `m` is the number of market ids,
/// which close at the same time as the specified market.
#[pallet::call_index(13)]
#[pallet::weight((
T::WeightInfo::reject_market(
CacheSize::get(),
Expand Down Expand Up @@ -1266,6 +1280,7 @@ mod pallet {
///
/// Complexity: `O(n)`, where `n` is the number of market ids,
/// which reported at the same time as the specified market.
#[pallet::call_index(14)]
#[pallet::weight(T::WeightInfo::report(CacheSize::get()))]
#[transactional]
pub fn report(
Expand Down Expand Up @@ -1377,6 +1392,7 @@ mod pallet {
/// # Weight
///
/// Complexity: `O(n)`, where `n` is the number of assets for a categorical market.
#[pallet::call_index(15)]
#[pallet::weight(
T::WeightInfo::sell_complete_set(T::MaxCategories::get().into())
)]
Expand Down Expand Up @@ -1434,6 +1450,7 @@ mod pallet {
/// The outcomes of the disputes and the report outcome
/// are added to the global dispute voting outcomes.
/// The bond of each dispute is the initial vote amount.
#[pallet::call_index(16)]
#[pallet::weight(T::WeightInfo::start_global_dispute(CacheSize::get(), CacheSize::get()))]
#[transactional]
pub fn start_global_dispute(
Expand Down
1 change: 1 addition & 0 deletions zrml/rikiddo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2022-2023 Forecasting Technologies LTD.
Chralt98 marked this conversation as resolved.
Show resolved Hide resolved
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
Expand Down
3 changes: 3 additions & 0 deletions zrml/styx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2022-2023 Forecasting Technologies LTD.
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
Expand Down Expand Up @@ -85,6 +86,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
/// Burns ZTG(styx.burnAmount()) to cross, granting the ability to claim your zeitgeist avatar.
/// The signer can only cross once.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::cross())]
pub fn cross(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand Down Expand Up @@ -113,6 +115,7 @@ pub mod pallet {
/// # Arguments
///
/// * `amount`: The amount of the new burn price
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::set_burn_amount())]
pub fn set_burn_amount(
origin: OriginFor<T>,
Expand Down
Loading