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

Commit

Permalink
Use explicit call indices (#12891)
Browse files Browse the repository at this point in the history
* frame-system: explicit call index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use explicit call indices

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* pallet-template: explicit call index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* DNM: Temporarily require call_index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "DNM: Temporarily require call_index"

This reverts commit c4934e3.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez committed Dec 12, 2022
1 parent e5d5d88 commit b3d9f3c
Show file tree
Hide file tree
Showing 67 changed files with 403 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/node-template/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
/// An example dispatchable that takes a singles value as a parameter, writes the value to
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
#[pallet::call_index(0)]
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
// Check that the extrinsic was signed and get the signer.
Expand All @@ -81,6 +82,7 @@ pub mod pallet {
}

/// An example dispatchable that may throw a custom error.
#[pallet::call_index(1)]
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
pub fn cause_error(origin: OriginFor<T>) -> DispatchResult {
let _who = ensure_signed(origin)?;
Expand Down
18 changes: 18 additions & 0 deletions frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ pub mod pallet {
/// Add a new proposal to be voted on.
///
/// Must be called by a Fellow.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::propose_proposed(
*length_bound, // B
T::MaxFellows::get(), // M
Expand All @@ -524,6 +525,7 @@ pub mod pallet {
/// Add an aye or nay vote for the sender to the given proposal.
///
/// Must be called by a Fellow.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::vote(T::MaxFellows::get()))]
pub fn vote(
origin: OriginFor<T>,
Expand All @@ -541,6 +543,7 @@ pub mod pallet {
/// Close a vote that is either approved, disapproved, or whose voting period has ended.
///
/// Must be called by a Fellow.
#[pallet::call_index(2)]
#[pallet::weight({
let b = *length_bound;
let m = T::MaxFellows::get();
Expand Down Expand Up @@ -573,6 +576,7 @@ pub mod pallet {
/// The Alliance must be empty, and the call must provide some founding members.
///
/// Must be called by the Root origin.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::init_members(
fellows.len() as u32,
allies.len() as u32,
Expand Down Expand Up @@ -623,6 +627,7 @@ pub mod pallet {
/// Disband the Alliance, remove all active members and unreserve deposits.
///
/// Witness data must be set.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::disband(
witness.fellow_members,
witness.ally_members,
Expand Down Expand Up @@ -673,6 +678,7 @@ 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 @@ -684,6 +690,7 @@ 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 @@ -699,6 +706,7 @@ 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 @@ -716,6 +724,7 @@ 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 @@ -752,6 +761,7 @@ 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)?;
Expand All @@ -776,6 +786,7 @@ 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)?;
Expand All @@ -792,6 +803,7 @@ 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)?;
Expand All @@ -814,6 +826,7 @@ 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)?;
Expand All @@ -836,6 +849,7 @@ 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)?;
Expand All @@ -853,6 +867,7 @@ pub mod pallet {
}

/// Add accounts or websites to the list of unscrupulous items.
#[pallet::call_index(14)]
#[pallet::weight(T::WeightInfo::add_unscrupulous_items(items.len() as u32, T::MaxWebsiteUrlLength::get()))]
pub fn add_unscrupulous_items(
origin: OriginFor<T>,
Expand Down Expand Up @@ -882,6 +897,7 @@ pub mod pallet {
}

/// Deem some items no longer unscrupulous.
#[pallet::call_index(15)]
#[pallet::weight(<T as Config<I>>::WeightInfo::remove_unscrupulous_items(
items.len() as u32, T::MaxWebsiteUrlLength::get()
))]
Expand All @@ -907,6 +923,7 @@ pub mod pallet {
/// Close a vote that is either approved, disapproved, or whose voting period has ended.
///
/// Must be called by a Fellow.
#[pallet::call_index(16)]
#[pallet::weight({
let b = *length_bound;
let m = T::MaxFellows::get();
Expand Down Expand Up @@ -934,6 +951,7 @@ pub mod pallet {
/// Abdicate one's position as a voting member and just be an Ally. May be used by Fellows
/// 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)?;
Expand Down
28 changes: 28 additions & 0 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ pub mod pallet {
/// Emits `Created` event when successful.
///
/// Weight: `O(1)`
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::create())]
pub fn create(
origin: OriginFor<T>,
Expand Down Expand Up @@ -620,6 +621,7 @@ pub mod pallet {
/// Emits `ForceCreated` event when successful.
///
/// Weight: `O(1)`
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::force_create())]
pub fn force_create(
origin: OriginFor<T>,
Expand All @@ -645,6 +647,7 @@ pub mod pallet {
/// asset.
///
/// 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) {
Expand All @@ -667,6 +670,7 @@ pub mod pallet {
/// asset.
///
/// Each call emits the `Event::DestroyedAccounts` event.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::destroy_accounts(T::RemoveItemsLimit::get()))]
pub fn destroy_accounts(
origin: OriginFor<T>,
Expand All @@ -690,6 +694,7 @@ pub mod pallet {
/// asset.
///
/// Each call emits the `Event::DestroyedApprovals` event.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::destroy_approvals(T::RemoveItemsLimit::get()))]
pub fn destroy_approvals(
origin: OriginFor<T>,
Expand All @@ -711,6 +716,7 @@ pub mod pallet {
/// asset.
///
/// 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)?;
Expand All @@ -730,6 +736,7 @@ 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>,
Expand Down Expand Up @@ -759,6 +766,7 @@ 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>,
Expand Down Expand Up @@ -793,6 +801,7 @@ pub mod pallet {
/// Weight: `O(1)`
/// 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>,
Expand Down Expand Up @@ -826,6 +835,7 @@ pub mod pallet {
/// Weight: `O(1)`
/// 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>,
Expand Down Expand Up @@ -860,6 +870,7 @@ pub mod pallet {
/// Weight: `O(1)`
/// 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>,
Expand Down Expand Up @@ -887,6 +898,7 @@ pub mod pallet {
/// Emits `Frozen`.
///
/// Weight: `O(1)`
#[pallet::call_index(11)]
#[pallet::weight(T::WeightInfo::freeze())]
pub fn freeze(
origin: OriginFor<T>,
Expand Down Expand Up @@ -923,6 +935,7 @@ pub mod pallet {
/// Emits `Thawed`.
///
/// Weight: `O(1)`
#[pallet::call_index(12)]
#[pallet::weight(T::WeightInfo::thaw())]
pub fn thaw(
origin: OriginFor<T>,
Expand Down Expand Up @@ -958,6 +971,7 @@ pub mod pallet {
/// Emits `Frozen`.
///
/// 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)?;
Expand All @@ -984,6 +998,7 @@ pub mod pallet {
/// Emits `Thawed`.
///
/// 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)?;
Expand Down Expand Up @@ -1011,6 +1026,7 @@ pub mod pallet {
/// Emits `OwnerChanged`.
///
/// Weight: `O(1)`
#[pallet::call_index(15)]
#[pallet::weight(T::WeightInfo::transfer_ownership())]
pub fn transfer_ownership(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1054,6 +1070,7 @@ pub mod pallet {
/// Emits `TeamChanged`.
///
/// Weight: `O(1)`
#[pallet::call_index(16)]
#[pallet::weight(T::WeightInfo::set_team())]
pub fn set_team(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1098,6 +1115,7 @@ pub mod pallet {
/// Emits `MetadataSet`.
///
/// Weight: `O(1)`
#[pallet::call_index(17)]
#[pallet::weight(T::WeightInfo::set_metadata(name.len() as u32, symbol.len() as u32))]
pub fn set_metadata(
origin: OriginFor<T>,
Expand All @@ -1122,6 +1140,7 @@ pub mod pallet {
/// Emits `MetadataCleared`.
///
/// 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)?;
Expand Down Expand Up @@ -1153,6 +1172,7 @@ pub mod pallet {
/// Emits `MetadataSet`.
///
/// Weight: `O(N + S)` where N and S are the length of the name and symbol respectively.
#[pallet::call_index(19)]
#[pallet::weight(T::WeightInfo::force_set_metadata(name.len() as u32, symbol.len() as u32))]
pub fn force_set_metadata(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1204,6 +1224,7 @@ pub mod pallet {
/// Emits `MetadataCleared`.
///
/// Weight: `O(1)`
#[pallet::call_index(20)]
#[pallet::weight(T::WeightInfo::force_clear_metadata())]
pub fn force_clear_metadata(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1243,6 +1264,7 @@ pub mod pallet {
/// Emits `AssetStatusChanged` with the identity of the asset.
///
/// Weight: `O(1)`
#[pallet::call_index(21)]
#[pallet::weight(T::WeightInfo::force_asset_status())]
pub fn force_asset_status(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1299,6 +1321,7 @@ pub mod pallet {
/// Emits `ApprovedTransfer` on success.
///
/// Weight: `O(1)`
#[pallet::call_index(22)]
#[pallet::weight(T::WeightInfo::approve_transfer())]
pub fn approve_transfer(
origin: OriginFor<T>,
Expand All @@ -1325,6 +1348,7 @@ pub mod pallet {
/// Emits `ApprovalCancelled` on success.
///
/// Weight: `O(1)`
#[pallet::call_index(23)]
#[pallet::weight(T::WeightInfo::cancel_approval())]
pub fn cancel_approval(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1361,6 +1385,7 @@ pub mod pallet {
/// Emits `ApprovalCancelled` on success.
///
/// Weight: `O(1)`
#[pallet::call_index(24)]
#[pallet::weight(T::WeightInfo::force_cancel_approval())]
pub fn force_cancel_approval(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1410,6 +1435,7 @@ pub mod pallet {
/// Emits `TransferredApproved` on success.
///
/// Weight: `O(1)`
#[pallet::call_index(25)]
#[pallet::weight(T::WeightInfo::transfer_approved())]
pub fn transfer_approved(
origin: OriginFor<T>,
Expand All @@ -1434,6 +1460,7 @@ pub mod pallet {
/// - `id`: The identifier of the asset for the account to be created.
///
/// Emits `Touched` event when successful.
#[pallet::call_index(26)]
#[pallet::weight(T::WeightInfo::mint())]
pub fn touch(origin: OriginFor<T>, id: T::AssetIdParameter) -> DispatchResult {
let id: T::AssetId = id.into();
Expand All @@ -1448,6 +1475,7 @@ pub mod pallet {
/// - `allow_burn`: If `true` then assets may be destroyed in order to complete the refund.
///
/// Emits `Refunded` event when successful.
#[pallet::call_index(27)]
#[pallet::weight(T::WeightInfo::mint())]
pub fn refund(
origin: OriginFor<T>,
Expand Down
Loading

0 comments on commit b3d9f3c

Please sign in to comment.