mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 00:17:56 +00:00
Ranked Collective pallet (#11548)
* Ranked Collective pallet * Fixes * benchmarks * Weights * Allow class voting in rank Use bare ayes for calculating support. Allow only promotion/demotion by one rank only. Allow removal of member with rank zero only. Use new Tally API * Index by rank, still O(1). * Custom vote weights * Formatting * Update frame/ranked-collective/src/lib.rs * Broken :( * origin guard; cleanup uses new API * Formatting * Promote/demote by rank * Formatting * Use new API * Remove code in another PR * Remove code in another PR * Formatting * Remove code in another PR * Docs * Docs * Bump * Fixes * Formatting * Fixes
This commit is contained in:
@@ -2748,6 +2748,9 @@ mod tests {
|
||||
fn signed(_by: <TraitImpl as system::Config>::AccountId) -> Self {
|
||||
unimplemented!("Not required in tests!")
|
||||
}
|
||||
fn as_signed(self) -> Option<Self::AccountId> {
|
||||
unimplemented!("Not required in tests!")
|
||||
}
|
||||
}
|
||||
|
||||
impl system::Config for TraitImpl {
|
||||
|
||||
@@ -286,6 +286,12 @@ impl<T, S: Get<u32>> BoundedVec<T, S> {
|
||||
Self::with_bounded_capacity(Self::bound())
|
||||
}
|
||||
|
||||
/// Consume and truncate the vector `v` in order to create a new instance of `Self` from it.
|
||||
pub fn truncate_from(mut v: Vec<T>) -> Self {
|
||||
v.truncate(Self::bound());
|
||||
Self::unchecked_from(v)
|
||||
}
|
||||
|
||||
/// Get the bound of the type in `usize`.
|
||||
pub fn bound() -> usize {
|
||||
S::get() as usize
|
||||
|
||||
@@ -27,7 +27,7 @@ use crate::{
|
||||
use codec::{Decode, Encode, EncodeLike, FullCodec, FullEncode};
|
||||
use sp_core::storage::ChildInfo;
|
||||
use sp_runtime::generic::{Digest, DigestItem};
|
||||
use sp_std::prelude::*;
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
|
||||
pub use self::{
|
||||
transactional::{
|
||||
@@ -51,6 +51,10 @@ pub mod types;
|
||||
pub mod unhashed;
|
||||
pub mod weak_bounded_vec;
|
||||
|
||||
/// Utility type for converting a storage map into a `Get<u32>` impl which returns the maximum
|
||||
/// key size.
|
||||
pub struct KeyLenOf<M>(PhantomData<M>);
|
||||
|
||||
/// A trait for working with macro-generated storage values under the substrate storage API.
|
||||
///
|
||||
/// Details on implementation can be found at [`generator::StorageValue`].
|
||||
|
||||
@@ -22,7 +22,7 @@ use crate::{
|
||||
metadata::{StorageEntryMetadata, StorageEntryType},
|
||||
storage::{
|
||||
types::{OptionQuery, QueryKindTrait, StorageEntryMetadataBuilder},
|
||||
StorageAppend, StorageDecodeLength, StoragePrefixedMap, StorageTryAppend,
|
||||
KeyLenOf, StorageAppend, StorageDecodeLength, StoragePrefixedMap, StorageTryAppend,
|
||||
},
|
||||
traits::{Get, GetDefault, StorageInfo, StorageInstance},
|
||||
};
|
||||
@@ -70,6 +70,35 @@ pub struct StorageDoubleMap<
|
||||
)>,
|
||||
);
|
||||
|
||||
impl<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty, MaxValues> Get<u32>
|
||||
for KeyLenOf<
|
||||
StorageDoubleMap<
|
||||
Prefix,
|
||||
Hasher1,
|
||||
Key1,
|
||||
Hasher2,
|
||||
Key2,
|
||||
Value,
|
||||
QueryKind,
|
||||
OnEmpty,
|
||||
MaxValues,
|
||||
>,
|
||||
> where
|
||||
Prefix: StorageInstance,
|
||||
Hasher1: crate::hash::StorageHasher,
|
||||
Hasher2: crate::hash::StorageHasher,
|
||||
Key1: MaxEncodedLen,
|
||||
Key2: MaxEncodedLen,
|
||||
{
|
||||
fn get() -> u32 {
|
||||
let z = Hasher1::max_len::<Key1>() +
|
||||
Hasher2::max_len::<Key2>() +
|
||||
Prefix::pallet_prefix().len() +
|
||||
Prefix::STORAGE_PREFIX.len();
|
||||
z as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty, MaxValues>
|
||||
crate::storage::generator::StorageDoubleMap<Key1, Key2, Value>
|
||||
for StorageDoubleMap<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty, MaxValues>
|
||||
|
||||
@@ -22,7 +22,7 @@ use crate::{
|
||||
metadata::{StorageEntryMetadata, StorageEntryType},
|
||||
storage::{
|
||||
types::{OptionQuery, QueryKindTrait, StorageEntryMetadataBuilder},
|
||||
StorageAppend, StorageDecodeLength, StoragePrefixedMap, StorageTryAppend,
|
||||
KeyLenOf, StorageAppend, StorageDecodeLength, StoragePrefixedMap, StorageTryAppend,
|
||||
},
|
||||
traits::{Get, GetDefault, StorageInfo, StorageInstance},
|
||||
};
|
||||
@@ -53,6 +53,20 @@ pub struct StorageMap<
|
||||
MaxValues = GetDefault,
|
||||
>(core::marker::PhantomData<(Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues)>);
|
||||
|
||||
impl<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues> Get<u32>
|
||||
for KeyLenOf<StorageMap<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues>>
|
||||
where
|
||||
Prefix: StorageInstance,
|
||||
Hasher: crate::hash::StorageHasher,
|
||||
Key: FullCodec + MaxEncodedLen,
|
||||
{
|
||||
fn get() -> u32 {
|
||||
let z =
|
||||
Hasher::max_len::<Key>() + Prefix::pallet_prefix().len() + Prefix::STORAGE_PREFIX.len();
|
||||
z as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues>
|
||||
crate::storage::generator::StorageMap<Key, Value>
|
||||
for StorageMap<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues>
|
||||
|
||||
@@ -97,7 +97,8 @@ mod dispatch;
|
||||
pub use dispatch::EnsureOneOf;
|
||||
pub use dispatch::{
|
||||
AsEnsureOriginWithArg, DispatchableWithStorageLayer, EitherOf, EitherOfDiverse, EnsureOrigin,
|
||||
EnsureOriginWithArg, NeverEnsureOrigin, OriginTrait, UnfilteredDispatchable,
|
||||
EnsureOriginWithArg, MapSuccess, NeverEnsureOrigin, OriginTrait, ReduceBy, TryMapSuccess,
|
||||
UnfilteredDispatchable,
|
||||
};
|
||||
|
||||
mod voting;
|
||||
|
||||
@@ -319,6 +319,9 @@ pub trait OriginTrait: Sized {
|
||||
|
||||
/// Create with system signed origin and `frame_system::Config::BaseCallFilter`.
|
||||
fn signed(by: Self::AccountId) -> Self;
|
||||
|
||||
/// Extract the signer from the message if it is a `Signed` origin.
|
||||
fn as_signed(self) -> Option<Self::AccountId>;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
//! votes.
|
||||
|
||||
use crate::dispatch::{DispatchError, Parameter};
|
||||
use codec::HasCompact;
|
||||
use codec::{HasCompact, MaxEncodedLen};
|
||||
use sp_arithmetic::{
|
||||
traits::{SaturatedConversion, UniqueSaturatedFrom, UniqueSaturatedInto},
|
||||
Perbill,
|
||||
@@ -123,9 +123,9 @@ impl<Tally, Moment, Class> PollStatus<Tally, Moment, Class> {
|
||||
}
|
||||
|
||||
pub trait Polling<Tally> {
|
||||
type Index: Parameter + Member + Ord + PartialOrd + Copy + HasCompact;
|
||||
type Votes: Parameter + Member + Ord + PartialOrd + Copy + HasCompact;
|
||||
type Class: Parameter + Member + Ord + PartialOrd;
|
||||
type Index: Parameter + Member + Ord + PartialOrd + Copy + HasCompact + MaxEncodedLen;
|
||||
type Votes: Parameter + Member + Ord + PartialOrd + Copy + HasCompact + MaxEncodedLen;
|
||||
type Class: Parameter + Member + Ord + PartialOrd + MaxEncodedLen;
|
||||
type Moment;
|
||||
|
||||
/// Provides a vec of values that `T` may take.
|
||||
|
||||
Reference in New Issue
Block a user