mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 20:07:56 +00:00
Society v2 (#11324)
* New Society * More logic drafting * More work * Building * Some tests * Fixes * Improvements to the voting process * More tests * Test number 20 * Tests * 30 tests * Another test] * All tests enabled * Minor stuff * generate_storage_alias: Rewrite as proc macro attribute This rewrites the `generate_storage_alias!` declarative macro as proc-macro attribute. While doing this the name is changed to `storage_alias`. The prefix can now also be the name of a pallet. This makes storage aliases work in migrations for all kind of chains and not just for the ones that use predefined prefixes. * Maintenance operations don't pay fee * Fix compilation and FMT * Moare fixes * Migrations * Fix tests and add migration testing * Introduce lazy-cleanup and avoid unbounded prefix removal * Fixes * Fixes * [WIP][Society] Adding benchmarking to the v2. (#11776) * [Society] Adding benchmarking to the v2. * [Society] Code review. * [Society] Better code. * Using clear() + clear_prefix() and adding more tests. * Benchmarking again... * Fix Cargo * Fixes * Fixes * Spelling * Fix benchmarks * Another fix * Remove println --------- Co-authored-by: Bastian Köcher <info@kchr.de> Co-authored-by: Artur Gontijo <arturgontijo@users.noreply.github.com>
This commit is contained in:
@@ -1158,6 +1158,52 @@ pub mod key_types {
|
||||
pub const DUMMY: KeyTypeId = KeyTypeId(*b"dumy");
|
||||
}
|
||||
|
||||
/// Create random values of `Self` given a stream of entropy.
|
||||
pub trait FromEntropy: Sized {
|
||||
/// Create a random value of `Self` given a stream of random bytes on `input`. May only fail if
|
||||
/// `input` has an error.
|
||||
fn from_entropy(input: &mut impl codec::Input) -> Result<Self, codec::Error>;
|
||||
}
|
||||
|
||||
impl FromEntropy for bool {
|
||||
fn from_entropy(input: &mut impl codec::Input) -> Result<Self, codec::Error> {
|
||||
Ok(input.read_byte()? % 2 == 1)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_from_entropy {
|
||||
($type:ty , $( $others:tt )*) => {
|
||||
impl_from_entropy!($type);
|
||||
impl_from_entropy!($( $others )*);
|
||||
};
|
||||
($type:ty) => {
|
||||
impl FromEntropy for $type {
|
||||
fn from_entropy(input: &mut impl codec::Input) -> Result<Self, codec::Error> {
|
||||
<Self as codec::Decode>::decode(input)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_from_entropy_base {
|
||||
($type:ty , $( $others:tt )*) => {
|
||||
impl_from_entropy_base!($type);
|
||||
impl_from_entropy_base!($( $others )*);
|
||||
};
|
||||
($type:ty) => {
|
||||
impl_from_entropy!($type,
|
||||
[$type; 1], [$type; 2], [$type; 3], [$type; 4], [$type; 5], [$type; 6], [$type; 7], [$type; 8],
|
||||
[$type; 9], [$type; 10], [$type; 11], [$type; 12], [$type; 13], [$type; 14], [$type; 15], [$type; 16],
|
||||
[$type; 17], [$type; 18], [$type; 19], [$type; 20], [$type; 21], [$type; 22], [$type; 23], [$type; 24],
|
||||
[$type; 25], [$type; 26], [$type; 27], [$type; 28], [$type; 29], [$type; 30], [$type; 31], [$type; 32],
|
||||
[$type; 36], [$type; 40], [$type; 44], [$type; 48], [$type; 56], [$type; 64], [$type; 72], [$type; 80],
|
||||
[$type; 96], [$type; 112], [$type; 128], [$type; 160], [$type; 192], [$type; 224], [$type; 256]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl_from_entropy_base!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user