MEL: Origin, Referenda, ConvictionVoting (#11631)

* Referenda & CV pallets ready

* Fix build

* Add mel_bound for Voting and Casting types

* Add mel_bound on Tally

* Add mel_bound on another Tally

* Add mel_bound for pallet_collective::RawOrigin

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Gavin Wood
2022-06-16 17:13:17 +01:00
committed by GitHub
parent 849a6c35fd
commit c47431118b
22 changed files with 106 additions and 39 deletions
@@ -200,7 +200,7 @@ pub fn expand_outer_origin(
#[derive(
Clone, PartialEq, Eq, #scrate::RuntimeDebug, #scrate::codec::Encode,
#scrate::codec::Decode, #scrate::scale_info::TypeInfo,
#scrate::codec::Decode, #scrate::scale_info::TypeInfo, #scrate::codec::MaxEncodedLen,
)]
#[allow(non_camel_case_types)]
pub enum OriginCaller {
+7 -3
View File
@@ -19,7 +19,9 @@
//! generating values representing lazy module function calls.
pub use crate::{
codec::{Codec, Decode, Encode, EncodeAsRef, EncodeLike, HasCompact, Input, Output},
codec::{
Codec, Decode, Encode, EncodeAsRef, EncodeLike, HasCompact, Input, MaxEncodedLen, Output,
},
scale_info::TypeInfo,
sp_std::{
fmt, marker,
@@ -63,7 +65,7 @@ pub trait Callable<T> {
pub type CallableCallFor<A, R> = <A as Callable<R>>::Call;
/// Origin for the System pallet.
#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo)]
#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub enum RawOrigin<AccountId> {
/// The system itself ordained this dispatch to happen: this is the highest privilege level.
Root,
@@ -2698,7 +2700,9 @@ mod tests {
}
}
#[derive(TypeInfo, crate::RuntimeDebug, Eq, PartialEq, Clone, Encode, Decode)]
#[derive(
TypeInfo, crate::RuntimeDebug, Eq, PartialEq, Clone, Encode, Decode, MaxEncodedLen,
)]
pub struct OuterOrigin;
impl From<RawOrigin<<TraitImpl as system::Config>::AccountId>> for OuterOrigin {
+2 -1
View File
@@ -103,5 +103,6 @@ pub use dispatch::{
mod voting;
pub use voting::{
CurrencyToVote, PollStatus, Polling, SaturatingCurrencyToVote, U128CurrencyToVote, VoteTally,
ClassCountOf, CurrencyToVote, PollStatus, Polling, SaturatingCurrencyToVote,
U128CurrencyToVote, VoteTally,
};
@@ -18,6 +18,7 @@
//! Traits for dealing with dispatching calls and the origin from which they are dispatched.
use crate::dispatch::{DispatchResultWithPostInfo, Parameter, RawOrigin};
use codec::MaxEncodedLen;
use sp_runtime::{
traits::{BadOrigin, Member, Morph, TryMorph},
Either,
@@ -258,7 +259,11 @@ pub trait OriginTrait: Sized {
type Call;
/// The caller origin, overarching type of all pallets origins.
type PalletsOrigin: Parameter + Member + Into<Self> + From<RawOrigin<Self::AccountId>>;
type PalletsOrigin: Parameter
+ Member
+ Into<Self>
+ From<RawOrigin<Self::AccountId>>
+ MaxEncodedLen;
/// The AccountId used across the system.
type AccountId;
@@ -134,7 +134,7 @@ pub mod v1 {
/// A type that can be used as a scheduler.
pub trait Anon<BlockNumber, Call, Origin> {
/// An address which can be used for removing a scheduled task.
type Address: Codec + Clone + Eq + EncodeLike + Debug + TypeInfo;
type Address: Codec + Clone + Eq + EncodeLike + Debug + TypeInfo + MaxEncodedLen;
/// Schedule a dispatch to happen at the beginning of some block in the future.
///
@@ -179,7 +179,7 @@ pub mod v1 {
/// A type that can be used as a scheduler.
pub trait Named<BlockNumber, Call, Origin> {
/// An address which can be used for removing a scheduled task.
type Address: Codec + Clone + Eq + EncodeLike + sp_std::fmt::Debug;
type Address: Codec + Clone + Eq + EncodeLike + sp_std::fmt::Debug + MaxEncodedLen;
/// Schedule a dispatch to happen at the beginning of some block in the future.
///
@@ -289,7 +289,7 @@ pub mod v2 {
/// A type that can be used as a scheduler.
pub trait Anon<BlockNumber, Call, Origin> {
/// An address which can be used for removing a scheduled task.
type Address: Codec + Clone + Eq + EncodeLike + Debug + TypeInfo;
type Address: Codec + Clone + Eq + EncodeLike + Debug + TypeInfo + MaxEncodedLen;
/// A means of expressing a call by the hash of its encoded data.
type Hash;
@@ -336,7 +336,7 @@ pub mod v2 {
/// A type that can be used as a scheduler.
pub trait Named<BlockNumber, Call, Origin> {
/// An address which can be used for removing a scheduled task.
type Address: Codec + Clone + Eq + EncodeLike + sp_std::fmt::Debug;
type Address: Codec + Clone + Eq + EncodeLike + sp_std::fmt::Debug + MaxEncodedLen;
/// A means of expressing a call by the hash of its encoded data.
type Hash;
@@ -122,6 +122,13 @@ impl<Tally, Moment, Class> PollStatus<Tally, Moment, Class> {
}
}
pub struct ClassCountOf<P, T>(sp_std::marker::PhantomData<(P, T)>);
impl<T, P: Polling<T>> sp_runtime::traits::Get<u32> for ClassCountOf<P, T> {
fn get() -> u32 {
P::classes().len() as u32
}
}
pub trait Polling<Tally> {
type Index: Parameter + Member + Ord + PartialOrd + Copy + HasCompact + MaxEncodedLen;
type Votes: Parameter + Member + Ord + PartialOrd + Copy + HasCompact + MaxEncodedLen;
@@ -21,6 +21,7 @@
#![recursion_limit = "128"]
use codec::MaxEncodedLen;
use frame_support::traits::{CrateVersion, PalletInfo as _};
use scale_info::TypeInfo;
use sp_core::{sr25519, H256};
@@ -55,7 +56,9 @@ mod module1 {
}
}
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Origin<T, I: Instance = DefaultInstance>(pub core::marker::PhantomData<(T, I)>);
frame_support::decl_event! {
@@ -97,7 +100,9 @@ mod module2 {
}
}
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Origin;
frame_support::decl_event! {
@@ -140,7 +145,9 @@ mod nested {
}
}
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Origin;
frame_support::decl_event! {
@@ -196,7 +203,9 @@ pub mod module3 {
}
}
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Origin<T>(pub core::marker::PhantomData<T>);
frame_support::decl_event! {
@@ -17,7 +17,7 @@
#![recursion_limit = "128"]
use codec::{Codec, Decode, Encode, EncodeLike};
use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen};
use frame_support::{
inherent::{InherentData, InherentIdentifier, MakeFatalError, ProvideInherent},
metadata::{
@@ -108,7 +108,9 @@ mod module1 {
}
}
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode, TypeInfo)]
#[derive(
PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen,
)]
pub enum Origin<T: Config<I>, I>
where
T::BlockNumber: From<u32>,
@@ -181,7 +183,9 @@ mod module2 {
}
}
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode, TypeInfo)]
#[derive(
PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen,
)]
pub enum Origin<T: Config<I>, I = DefaultInstance> {
Members(u32),
_Phantom(std::marker::PhantomData<(T, I)>),
+8 -2
View File
@@ -19,6 +19,7 @@
#![recursion_limit = "128"]
use codec::MaxEncodedLen;
use frame_support::traits::{Contains, OriginTrait};
use scale_info::TypeInfo;
use sp_core::{sr25519, H256};
@@ -30,6 +31,7 @@ mod nested {
use super::*;
pub mod module {
use super::*;
pub trait Config: system::Config {}
@@ -45,7 +47,9 @@ mod nested {
}
}
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Origin;
frame_support::decl_event! {
@@ -101,7 +105,9 @@ pub mod module {
}
}
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Origin<T>(pub core::marker::PhantomData<T>);
frame_support::decl_event! {
+8 -1
View File
@@ -359,7 +359,14 @@ pub mod pallet {
#[pallet::origin]
#[derive(
EqNoBound, RuntimeDebugNoBound, CloneNoBound, PartialEqNoBound, Encode, Decode, TypeInfo,
EqNoBound,
RuntimeDebugNoBound,
CloneNoBound,
PartialEqNoBound,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
)]
pub struct Origin<T>(PhantomData<T>);
@@ -30,6 +30,7 @@ use sp_runtime::{DispatchError, ModuleError};
#[frame_support::pallet]
pub mod pallet {
use codec::MaxEncodedLen;
use frame_support::{pallet_prelude::*, scale_info};
use frame_system::pallet_prelude::*;
use sp_std::any::TypeId;
@@ -164,6 +165,7 @@ pub mod pallet {
Encode,
Decode,
scale_info::TypeInfo,
MaxEncodedLen,
)]
#[scale_info(skip_type_params(T, I))]
pub struct Origin<T, I = ()>(PhantomData<(T, I)>);