BoundedVec + Shims for Append/DecodeLength (#8556)

* prototype for shawn

* Clean and document it

* Add more docs

* Move imports

* Some changes for easier compat.

* revert exmaple pallet

* rename

* BoundedVec for AccountLocks (#8580)

* Example with balances

* Fix tests

* Make it indexable

* fix

* Fix tests

* fix test

* Fix collective as well

* Fix test

* Update frame/support/src/storage/mod.rs

Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>

* Repot and add for value

* Add for map and double map

* Final touches.

* Update frame/support/src/storage/bounded_vec.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Add a few more tests

* Add import

Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Kian Paimani
2021-04-16 08:06:05 +02:00
committed by GitHub
parent 6c9c687a31
commit 6bcf5f21c4
8 changed files with 597 additions and 30 deletions
+10 -10
View File
@@ -75,7 +75,8 @@ pub use self::hash::{
};
pub use self::storage::{
StorageValue, StorageMap, StorageDoubleMap, StoragePrefixedMap, IterableStorageMap,
IterableStorageDoubleMap, migration
IterableStorageDoubleMap, migration,
bounded_vec::{self, BoundedVec},
};
pub use self::dispatch::{Parameter, Callable};
pub use sp_runtime::{self, ConsensusEngineId, print, traits::Printable};
@@ -112,20 +113,20 @@ impl TypeId for PalletId {
///
/// // generate a double map from `(u32, u32)` (with hasher `Twox64Concat`) to `Vec<u8>`
/// generate_storage_alias!(
/// OtherPrefix, OtherStorageName => DoubleMap<
/// OtherPrefix, OtherStorageName => DoubleMap<
/// (u32, u32),
/// (u32, u32),
/// Vec<u8>
/// >
/// >
/// );
///
/// // generate a map from `Config::AccountId` (with hasher `Twox64Concat`) to `Vec<u8>`
/// trait Config { type AccountId: codec::FullCodec; }
/// generate_storage_alias!(
/// Prefix, GenericStorage<T: Config> => Map<(Twox64Concat, T::AccountId), Vec<u8>>
/// Prefix, GenericStorage<T: Config> => Map<(Twox64Concat, T::AccountId), Vec<u8>>
/// );
/// # fn main() {}
///```
/// ```
#[macro_export]
macro_rules! generate_storage_alias {
// without generic for $name.
@@ -143,7 +144,7 @@ macro_rules! generate_storage_alias {
($pallet:ident, $name:ident => DoubleMap<($key1:ty, $hasher1:ty), ($key2:ty, $hasher2:ty), $value:ty>) => {
$crate::paste::paste! {
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
type $name = $crate::storage::types::StorageMap<
type $name = $crate::storage::types::StorageDoubleMap<
[<$name Instance>],
$hasher1,
$key1,
@@ -178,12 +179,11 @@ macro_rules! generate_storage_alias {
(
$pallet:ident,
$name:ident<$t:ident : $bounds:tt>
=> DoubleMap<($key1:ty, $hasher1:ty), ($key2:ty, $hasher2:ty), $value:ty>)
=> {
=> DoubleMap<($key1:ty, $hasher1:ty), ($key2:ty, $hasher2:ty), $value:ty>) => {
$crate::paste::paste! {
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
#[allow(type_alias_bounds)]
type $name<$t : $bounds> = $crate::storage::types::StorageMap<
type $name<$t : $bounds> = $crate::storage::types::StorageDoubleMap<
[<$name Instance>],
$key1,
$hasher1,
@@ -213,7 +213,7 @@ macro_rules! generate_storage_alias {
const STORAGE_PREFIX: &'static str = stringify!($name);
}
}
}
};
}
/// Create new implementations of the [`Get`](crate::traits::Get) trait.