mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
Introduce #[pallet::call_index] attribute to dispatchables (#11381)
* Introduce #[pallet::call_index] attribute to dispatchables * cargo fmt * Add more docs and prevent duplicates of call indices * Add UI test for conflicting call indices * cargo fmt Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::DispatchResultWithPostInfo;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
#[pallet::call_index(10)]
|
||||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
|
||||
#[pallet::weight(0)]
|
||||
#[pallet::call_index(10)]
|
||||
pub fn bar(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
error: Call indices are conflicting: Both functions foo and bar are at index 10
|
||||
--> tests/pallet_ui/call_conflicting_indices.rs:15:10
|
||||
|
|
||||
15 | pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
| ^^^
|
||||
|
||||
error: Call indices are conflicting: Both functions foo and bar are at index 10
|
||||
--> tests/pallet_ui/call_conflicting_indices.rs:19:10
|
||||
|
|
||||
19 | pub fn bar(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
| ^^^
|
||||
@@ -0,0 +1,20 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::DispatchResultWithPostInfo;
|
||||
use frame_system::pallet_prelude::OriginFor;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weird_attr]
|
||||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: expected `weight` or `call_index`
|
||||
--> tests/pallet_ui/call_invalid_attr.rs:14:13
|
||||
|
|
||||
14 | #[pallet::weird_attr]
|
||||
| ^^^^^^^^^^
|
||||
@@ -0,0 +1,21 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::DispatchResultWithPostInfo;
|
||||
use frame_system::pallet_prelude::OriginFor;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
#[pallet::call_index(256)]
|
||||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: number too large to fit in target type
|
||||
--> tests/pallet_ui/call_invalid_index.rs:15:24
|
||||
|
|
||||
15 | #[pallet::call_index(256)]
|
||||
| ^^^
|
||||
@@ -0,0 +1,22 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::DispatchResultWithPostInfo;
|
||||
use frame_system::pallet_prelude::OriginFor;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::call_index(2)]
|
||||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid pallet::call, too many call_index attributes given
|
||||
--> tests/pallet_ui/call_multiple_call_index.rs:17:7
|
||||
|
|
||||
17 | pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
| ^^
|
||||
Reference in New Issue
Block a user