mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 09:17:58 +00:00
Use proper bounded vector type for nominations (#10601)
* Use proper bounded vector type for nominations * add docs and tweak chill_other for cleanup purposes * Fix the build * remove TODO * add a bit more doc * even more docs gushc * Update frame/staking/src/pallet/mod.rs Co-authored-by: Zeke Mostov <z.mostov@gmail.com> * Update frame/staking/src/pallet/mod.rs Co-authored-by: Zeke Mostov <z.mostov@gmail.com> * Fix the nasty bug * also bound the Snapshot type * fix doc test * document bounded_vec * self-review * remove unused * Fix build * frame-support: repetition overload for bounded_vec Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fix * remove the need to allocate into unbounded voters etc etc * Don't expect * unbreal the build again * handle macro a bit better Co-authored-by: Zeke Mostov <z.mostov@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -114,6 +114,29 @@ impl TypeId for PalletId {
|
||||
const TYPE_ID: [u8; 4] = *b"modl";
|
||||
}
|
||||
|
||||
/// Build a bounded vec from the given literals.
|
||||
///
|
||||
/// The type of the outcome must be known.
|
||||
///
|
||||
/// Will not handle any errors and just panic if the given literals cannot fit in the corresponding
|
||||
/// bounded vec type. Thus, this is only suitable for testing and non-consensus code.
|
||||
#[macro_export]
|
||||
#[cfg(feature = "std")]
|
||||
macro_rules! bounded_vec {
|
||||
($ ($values:expr),* ) => {
|
||||
{
|
||||
use $crate::sp_std::convert::TryInto as _;
|
||||
$crate::sp_std::vec![$($values),*].try_into().unwrap()
|
||||
}
|
||||
};
|
||||
( $value:expr ; $repetition:expr ) => {
|
||||
{
|
||||
use $crate::sp_std::convert::TryInto as _;
|
||||
$crate::sp_std::vec![$value ; $repetition].try_into().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a new type alias for [`storage::types::StorageValue`],
|
||||
/// [`storage::types::StorageMap`], [`storage::types::StorageDoubleMap`]
|
||||
/// and [`storage::types::StorageNMap`].
|
||||
|
||||
@@ -664,6 +664,19 @@ pub mod test {
|
||||
assert_eq!(*bounded, vec![1, 0, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constructor_macro_works() {
|
||||
use frame_support::bounded_vec;
|
||||
|
||||
// With values. Use some brackets to make sure the macro doesn't expand.
|
||||
let bv: BoundedVec<(u32, u32), ConstU32<3>> = bounded_vec![(1, 2), (1, 2), (1, 2)];
|
||||
assert_eq!(bv, vec![(1, 2), (1, 2), (1, 2)]);
|
||||
|
||||
// With repetition.
|
||||
let bv: BoundedVec<(u32, u32), ConstU32<3>> = bounded_vec![(1, 2); 3];
|
||||
assert_eq!(bv, vec![(1, 2), (1, 2), (1, 2)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "insertion index (is 9) should be <= len (is 3)")]
|
||||
fn try_inert_panics_if_oob() {
|
||||
|
||||
@@ -401,6 +401,13 @@ where
|
||||
) -> crate::storage::PrefixIterator<(Key, Value), OnRemovalCounterUpdate<Prefix>> {
|
||||
<Self as MapWrapper>::Map::iter_from(starting_raw_key).convert_on_removal()
|
||||
}
|
||||
|
||||
/// Enumerate all keys in the counted map.
|
||||
///
|
||||
/// If you alter the map while doing this, you'll get undefined results.
|
||||
pub fn iter_keys() -> crate::storage::KeyPrefixIterator<Key> {
|
||||
<Self as MapWrapper>::Map::iter_keys()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues> StorageEntryMetadataBuilder
|
||||
|
||||
Reference in New Issue
Block a user