mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
Enforce pub calls in pallets (#9085)
* make all extrinsics public so they are available from outside * Impl * fix * more fix * more pub * few more * merge fix * fix ui test * fix ui test Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
committed by
GitHub
parent
f21243e4e5
commit
d31e607bda
@@ -133,11 +133,11 @@ pub mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T>
|
||||
where T::AccountId: From<SomeType1> + From<SomeType3> + SomeAssociation1
|
||||
where T::AccountId: From<SomeType1> + From<SomeType3> + SomeAssociation1
|
||||
{
|
||||
/// Doc comment put in metadata
|
||||
#[pallet::weight(Weight::from(*_foo))]
|
||||
fn foo(
|
||||
pub fn foo(
|
||||
origin: OriginFor<T>,
|
||||
#[pallet::compact] _foo: u32,
|
||||
_bar: u32,
|
||||
@@ -152,7 +152,7 @@ pub mod pallet {
|
||||
/// Doc comment put in metadata
|
||||
#[pallet::weight(1)]
|
||||
#[frame_support::transactional]
|
||||
fn foo_transactional(
|
||||
pub fn foo_transactional(
|
||||
_origin: OriginFor<T>,
|
||||
#[pallet::compact] foo: u32,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
@@ -166,7 +166,7 @@ pub mod pallet {
|
||||
|
||||
// Test for DispatchResult return type
|
||||
#[pallet::weight(1)]
|
||||
fn foo_no_post_info(
|
||||
pub fn foo_no_post_info(
|
||||
_origin: OriginFor<T>,
|
||||
) -> DispatchResult {
|
||||
Ok(())
|
||||
|
||||
@@ -123,7 +123,7 @@ pub mod pallet {
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(<T::Balance as Into<Weight>>::into(new_value.clone()))]
|
||||
fn set_dummy(
|
||||
pub fn set_dummy(
|
||||
origin: OriginFor<T>,
|
||||
#[pallet::compact] new_value: T::Balance
|
||||
) -> DispatchResultWithPostInfo {
|
||||
|
||||
@@ -113,7 +113,7 @@ pub mod pallet {
|
||||
#[pallet::call]
|
||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
#[pallet::weight(<T::Balance as Into<Weight>>::into(new_value.clone()))]
|
||||
fn set_dummy(
|
||||
pub fn set_dummy(
|
||||
origin: OriginFor<T>,
|
||||
#[pallet::compact] new_value: T::Balance
|
||||
) -> DispatchResultWithPostInfo {
|
||||
|
||||
@@ -81,7 +81,7 @@ pub mod pallet {
|
||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
/// Doc comment put in metadata
|
||||
#[pallet::weight(Weight::from(*_foo))]
|
||||
fn foo(origin: OriginFor<T>, #[pallet::compact] _foo: u32) -> DispatchResultWithPostInfo {
|
||||
pub fn foo(origin: OriginFor<T>, #[pallet::compact] _foo: u32) -> DispatchResultWithPostInfo {
|
||||
let _ = origin;
|
||||
Self::deposit_event(Event::Something(3));
|
||||
Ok(().into())
|
||||
@@ -90,7 +90,7 @@ pub mod pallet {
|
||||
/// Doc comment put in metadata
|
||||
#[pallet::weight(1)]
|
||||
#[frame_support::transactional]
|
||||
fn foo_transactional(
|
||||
pub fn foo_transactional(
|
||||
origin: OriginFor<T>,
|
||||
#[pallet::compact] _foo: u32
|
||||
) -> DispatchResultWithPostInfo {
|
||||
|
||||
@@ -17,7 +17,7 @@ mod pallet {
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:37
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:41
|
||||
|
|
||||
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^
|
||||
|
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
@@ -10,18 +10,18 @@ help: consider further restricting this bound
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:37
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:41
|
||||
|
|
||||
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
||||
|
|
||||
= note: required by `clone`
|
||||
|
||||
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:37
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:41
|
||||
|
|
||||
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
||||
|
|
||||
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
|
||||
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&<T as pallet::Config>::Bar`
|
||||
|
||||
@@ -17,7 +17,7 @@ mod pallet {
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeDecode` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:37
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
|
|
||||
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `WrapperTypeDecode` is not implemented for `<T as pallet::Config>::Bar`
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `WrapperTypeDecode` is not implemented for `<T as pallet::Config>::Bar`
|
||||
|
|
||||
::: /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.1/src/codec.rs:277:18
|
||||
|
|
||||
@@ -12,10 +12,10 @@ error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeDecode` is
|
||||
= note: required because of the requirements on the impl of `Decode` for `<T as pallet::Config>::Bar`
|
||||
|
||||
error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeEncode` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:37
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
|
|
||||
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `WrapperTypeEncode` is not implemented for `<T as pallet::Config>::Bar`
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `WrapperTypeEncode` is not implemented for `<T as pallet::Config>::Bar`
|
||||
|
|
||||
::: /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.1/src/codec.rs:216:21
|
||||
|
|
||||
@@ -25,10 +25,10 @@ error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeEncode` is
|
||||
= note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `<T as pallet::Config>::Bar`
|
||||
|
||||
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:37
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
|
|
||||
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^
|
||||
|
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
@@ -36,18 +36,18 @@ help: consider further restricting this bound
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:37
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
|
|
||||
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
||||
|
|
||||
= note: required by `clone`
|
||||
|
||||
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:37
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
|
|
||||
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
||||
|
|
||||
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
|
||||
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&<T as pallet::Config>::Bar`
|
||||
|
||||
@@ -19,7 +19,7 @@ mod pallet {
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
pub fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
error[E0369]: binary operation `==` cannot be applied to type `&Bar`
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:37
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:41
|
||||
|
|
||||
22 | fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
| ^^^
|
||||
22 | pub fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
| ^^^
|
||||
|
|
||||
= note: an implementation of `std::cmp::PartialEq` might be missing for `&Bar`
|
||||
|
||||
error[E0277]: the trait bound `Bar: Clone` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:37
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:41
|
||||
|
|
||||
22 | fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
| ^^^ the trait `Clone` is not implemented for `Bar`
|
||||
22 | pub fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
| ^^^ the trait `Clone` is not implemented for `Bar`
|
||||
|
|
||||
= note: required by `clone`
|
||||
|
||||
error[E0277]: `Bar` doesn't implement `std::fmt::Debug`
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:37
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:41
|
||||
|
|
||||
22 | fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
| ^^^ `Bar` cannot be formatted using `{:?}`
|
||||
22 | pub fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
| ^^^ `Bar` cannot be formatted using `{:?}`
|
||||
|
|
||||
= help: the trait `std::fmt::Debug` is not implemented for `Bar`
|
||||
= note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
|
||||
|
||||
@@ -14,7 +14,7 @@ mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
fn foo(origin: u8) {}
|
||||
pub fn foo(origin: u8) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
error: Invalid type: expected `OriginFor<T>`
|
||||
--> $DIR/call_invalid_origin_type.rs:17:18
|
||||
--> $DIR/call_invalid_origin_type.rs:17:22
|
||||
|
|
||||
17 | fn foo(origin: u8) {}
|
||||
| ^^
|
||||
17 | pub fn foo(origin: u8) {}
|
||||
| ^^
|
||||
|
||||
error: expected `OriginFor`
|
||||
--> $DIR/call_invalid_origin_type.rs:17:18
|
||||
--> $DIR/call_invalid_origin_type.rs:17:22
|
||||
|
|
||||
17 | fn foo(origin: u8) {}
|
||||
| ^^
|
||||
17 | pub fn foo(origin: u8) {}
|
||||
| ^^
|
||||
|
||||
@@ -14,7 +14,7 @@ mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
fn foo(origin: OriginFor<T>) -> ::DispatchResult { todo!() }
|
||||
pub fn foo(origin: OriginFor<T>) -> ::DispatchResult { todo!() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: expected `DispatchResultWithPostInfo` or `DispatchResult`
|
||||
--> $DIR/call_invalid_return.rs:17:35
|
||||
--> $DIR/call_invalid_return.rs:17:39
|
||||
|
|
||||
17 | fn foo(origin: OriginFor<T>) -> ::DispatchResult { todo!() }
|
||||
| ^^
|
||||
17 | pub fn foo(origin: OriginFor<T>) -> ::DispatchResult { todo!() }
|
||||
| ^^
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
|
||||
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
type Bar: codec::Codec;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid pallet::call, dispatchable function must be public: `pub fn`
|
||||
--> $DIR/call_invalid_vis.rs:20:3
|
||||
|
|
||||
20 | fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
||||
| ^^
|
||||
@@ -0,0 +1,27 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
|
||||
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
type Bar: codec::Codec;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
pub(crate) fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid pallet::call, dispatchable function must be public: `pub fn`
|
||||
--> $DIR/call_invalid_vis_2.rs:20:3
|
||||
|
|
||||
20 | pub(crate) fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
||||
| ^^^
|
||||
@@ -14,7 +14,7 @@ mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: Invalid pallet::call, requires weight attribute i.e. `#[pallet::weight($expr)]`
|
||||
--> $DIR/call_missing_weight.rs:17:3
|
||||
--> $DIR/call_missing_weight.rs:17:7
|
||||
|
|
||||
17 | fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
| ^^
|
||||
17 | pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
|
||||
| ^^
|
||||
|
||||
@@ -14,7 +14,7 @@ mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
fn foo() {}
|
||||
pub fn foo() {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: Invalid pallet::call, must have at least origin arg
|
||||
--> $DIR/call_no_origin.rs:17:3
|
||||
--> $DIR/call_no_origin.rs:17:7
|
||||
|
|
||||
17 | fn foo() {}
|
||||
| ^^
|
||||
17 | pub fn foo() {}
|
||||
| ^^
|
||||
|
||||
@@ -14,7 +14,7 @@ mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
fn foo(origin: OriginFor<T>) {}
|
||||
pub fn foo(origin: OriginFor<T>) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: Invalid pallet::call, require return type DispatchResultWithPostInfo
|
||||
--> $DIR/call_no_return.rs:17:3
|
||||
--> $DIR/call_no_return.rs:17:7
|
||||
|
|
||||
17 | fn foo(origin: OriginFor<T>) {}
|
||||
| ^^
|
||||
17 | pub fn foo(origin: OriginFor<T>) {}
|
||||
| ^^
|
||||
|
||||
Reference in New Issue
Block a user