mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
generate_storage_alias: Rewrite as proc macro attribute (#11387)
* 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.
* Fix compilation and FMT
* Moare fixes
* 🤦
* ......
* Rework the syntax and support instancing
* FMT
* Prefix variants with `Storage`
* Make it compile
* Fix where clause on rust stable
This commit is contained in:
@@ -348,12 +348,15 @@ pub mod test {
|
||||
use frame_support::traits::ConstU32;
|
||||
use sp_io::TestExternalities;
|
||||
|
||||
crate::generate_storage_alias! { Prefix, Foo => Value<BoundedBTreeMap<u32, (), ConstU32<7>>> }
|
||||
crate::generate_storage_alias! { Prefix, FooMap => Map<(Twox128, u32), BoundedBTreeMap<u32, (), ConstU32<7>>> }
|
||||
crate::generate_storage_alias! {
|
||||
Prefix,
|
||||
FooDoubleMap => DoubleMap<(Twox128, u32), (Twox128, u32), BoundedBTreeMap<u32, (), ConstU32<7>>>
|
||||
}
|
||||
#[crate::storage_alias]
|
||||
type Foo = StorageValue<Prefix, BoundedBTreeMap<u32, (), ConstU32<7>>>;
|
||||
|
||||
#[crate::storage_alias]
|
||||
type FooMap = StorageMap<Prefix, Twox128, u32, BoundedBTreeMap<u32, (), ConstU32<7>>>;
|
||||
|
||||
#[crate::storage_alias]
|
||||
type FooDoubleMap =
|
||||
StorageDoubleMap<Prefix, Twox128, u32, Twox128, u32, BoundedBTreeMap<u32, (), ConstU32<7>>>;
|
||||
|
||||
fn map_from_keys<K>(keys: &[K]) -> BTreeMap<K, ()>
|
||||
where
|
||||
|
||||
@@ -322,12 +322,15 @@ pub mod test {
|
||||
use frame_support::traits::ConstU32;
|
||||
use sp_io::TestExternalities;
|
||||
|
||||
crate::generate_storage_alias! { Prefix, Foo => Value<BoundedBTreeSet<u32, ConstU32<7>>> }
|
||||
crate::generate_storage_alias! { Prefix, FooMap => Map<(Twox128, u32), BoundedBTreeSet<u32, ConstU32<7>>> }
|
||||
crate::generate_storage_alias! {
|
||||
Prefix,
|
||||
FooDoubleMap => DoubleMap<(Twox128, u32), (Twox128, u32), BoundedBTreeSet<u32, ConstU32<7>>>
|
||||
}
|
||||
#[crate::storage_alias]
|
||||
type Foo = StorageValue<Prefix, BoundedBTreeSet<u32, ConstU32<7>>>;
|
||||
|
||||
#[crate::storage_alias]
|
||||
type FooMap = StorageMap<Prefix, Twox128, u32, BoundedBTreeSet<u32, ConstU32<7>>>;
|
||||
|
||||
#[crate::storage_alias]
|
||||
type FooDoubleMap =
|
||||
StorageDoubleMap<Prefix, Twox128, u32, Twox128, u32, BoundedBTreeSet<u32, ConstU32<7>>>;
|
||||
|
||||
fn set_from_keys<T>(keys: &[T]) -> BTreeSet<T>
|
||||
where
|
||||
|
||||
@@ -672,12 +672,15 @@ pub mod test {
|
||||
use crate::{bounded_vec, traits::ConstU32, Twox128};
|
||||
use sp_io::TestExternalities;
|
||||
|
||||
crate::generate_storage_alias! { Prefix, Foo => Value<BoundedVec<u32, ConstU32<7>>> }
|
||||
crate::generate_storage_alias! { Prefix, FooMap => Map<(Twox128, u32), BoundedVec<u32, ConstU32<7>>> }
|
||||
crate::generate_storage_alias! {
|
||||
Prefix,
|
||||
FooDoubleMap => DoubleMap<(Twox128, u32), (Twox128, u32), BoundedVec<u32, ConstU32<7>>>
|
||||
}
|
||||
#[crate::storage_alias]
|
||||
type Foo = StorageValue<Prefix, BoundedVec<u32, ConstU32<7>>>;
|
||||
|
||||
#[crate::storage_alias]
|
||||
type FooMap = StorageMap<Prefix, Twox128, u32, BoundedVec<u32, ConstU32<7>>>;
|
||||
|
||||
#[crate::storage_alias]
|
||||
type FooDoubleMap =
|
||||
StorageDoubleMap<Prefix, Twox128, u32, Twox128, u32, BoundedVec<u32, ConstU32<7>>>;
|
||||
|
||||
#[test]
|
||||
fn slide_works() {
|
||||
|
||||
@@ -525,10 +525,8 @@ mod test_iterators {
|
||||
fn double_map_iter_from() {
|
||||
sp_io::TestExternalities::default().execute_with(|| {
|
||||
use crate::hash::Identity;
|
||||
crate::generate_storage_alias!(
|
||||
MyModule,
|
||||
MyDoubleMap => DoubleMap<(Identity, u64), (Identity, u64), u64>
|
||||
);
|
||||
#[crate::storage_alias]
|
||||
type MyDoubleMap = StorageDoubleMap<MyModule, Identity, u64, Identity, u64, u64>;
|
||||
|
||||
MyDoubleMap::insert(1, 10, 100);
|
||||
MyDoubleMap::insert(1, 21, 201);
|
||||
|
||||
@@ -384,7 +384,8 @@ mod test_iterators {
|
||||
fn map_iter_from() {
|
||||
sp_io::TestExternalities::default().execute_with(|| {
|
||||
use crate::hash::Identity;
|
||||
crate::generate_storage_alias!(MyModule, MyMap => Map<(Identity, u64), u64>);
|
||||
#[crate::storage_alias]
|
||||
type MyMap = StorageMap<MyModule, Identity, u64, u64>;
|
||||
|
||||
MyMap::insert(1, 10);
|
||||
MyMap::insert(2, 20);
|
||||
|
||||
@@ -475,10 +475,12 @@ mod test_iterators {
|
||||
fn n_map_iter_from() {
|
||||
sp_io::TestExternalities::default().execute_with(|| {
|
||||
use crate::{hash::Identity, storage::Key as NMapKey};
|
||||
crate::generate_storage_alias!(
|
||||
#[crate::storage_alias]
|
||||
type MyNMap = StorageNMap<
|
||||
MyModule,
|
||||
MyNMap => NMap<Key<(Identity, u64), (Identity, u64), (Identity, u64)>, u64>
|
||||
);
|
||||
(NMapKey<Identity, u64>, NMapKey<Identity, u64>, NMapKey<Identity, u64>),
|
||||
u64,
|
||||
>;
|
||||
|
||||
MyNMap::insert((1, 1, 1), 11);
|
||||
MyNMap::insert((1, 1, 2), 21);
|
||||
@@ -518,11 +520,15 @@ mod test_iterators {
|
||||
let key_hash = NMap::hashed_key_for((1, 2));
|
||||
|
||||
{
|
||||
crate::generate_storage_alias!(Test, NMap => DoubleMap<
|
||||
(crate::Blake2_128Concat, u16),
|
||||
(crate::Twox64Concat, u32),
|
||||
u64
|
||||
>);
|
||||
#[crate::storage_alias]
|
||||
type NMap = StorageDoubleMap<
|
||||
Test,
|
||||
crate::Blake2_128Concat,
|
||||
u16,
|
||||
crate::Twox64Concat,
|
||||
u32,
|
||||
u64,
|
||||
>;
|
||||
|
||||
let value = NMap::get(1, 2).unwrap();
|
||||
assert_eq!(value, 50);
|
||||
|
||||
@@ -1545,10 +1545,8 @@ mod test {
|
||||
fn prefix_iterator_pagination_works() {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
use crate::{hash::Identity, storage::generator::map::StorageMap};
|
||||
crate::generate_storage_alias! {
|
||||
MyModule,
|
||||
MyStorageMap => Map<(Identity, u64), u64>
|
||||
}
|
||||
#[crate::storage_alias]
|
||||
type MyStorageMap = StorageMap<MyModule, Identity, u64, u64>;
|
||||
|
||||
MyStorageMap::insert(1, 10);
|
||||
MyStorageMap::insert(2, 20);
|
||||
@@ -1663,12 +1661,13 @@ mod test {
|
||||
});
|
||||
}
|
||||
|
||||
crate::generate_storage_alias! { Prefix, Foo => Value<WeakBoundedVec<u32, ConstU32<7>>> }
|
||||
crate::generate_storage_alias! { Prefix, FooMap => Map<(Twox128, u32), BoundedVec<u32, ConstU32<7>>> }
|
||||
crate::generate_storage_alias! {
|
||||
Prefix,
|
||||
FooDoubleMap => DoubleMap<(Twox128, u32), (Twox128, u32), BoundedVec<u32, ConstU32<7>>>
|
||||
}
|
||||
#[crate::storage_alias]
|
||||
type Foo = StorageValue<Prefix, WeakBoundedVec<u32, ConstU32<7>>>;
|
||||
#[crate::storage_alias]
|
||||
type FooMap = StorageMap<Prefix, Twox128, u32, BoundedVec<u32, ConstU32<7>>>;
|
||||
#[crate::storage_alias]
|
||||
type FooDoubleMap =
|
||||
StorageDoubleMap<Prefix, Twox128, u32, Twox128, u32, BoundedVec<u32, ConstU32<7>>>;
|
||||
|
||||
#[test]
|
||||
fn try_append_works() {
|
||||
|
||||
@@ -544,7 +544,7 @@ mod test {
|
||||
use crate::{
|
||||
hash::{StorageHasher as _, *},
|
||||
metadata::{StorageEntryModifier, StorageHasher},
|
||||
storage::types::{Key, ValueQuery},
|
||||
storage::types::{Key, Key as NMapKey, ValueQuery},
|
||||
};
|
||||
use sp_io::{hashing::twox_128, TestExternalities};
|
||||
|
||||
@@ -589,10 +589,8 @@ mod test {
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::get((3,)), 10);
|
||||
|
||||
{
|
||||
crate::generate_storage_alias!(test, Foo => NMap<
|
||||
Key<(Blake2_128Concat, u16)>,
|
||||
u32
|
||||
>);
|
||||
#[crate::storage_alias]
|
||||
type Foo = StorageNMap<test, (NMapKey<Blake2_128Concat, u16>), u32>;
|
||||
|
||||
assert_eq!(Foo::contains_key((3,)), true);
|
||||
assert_eq!(Foo::get((3,)), Some(10));
|
||||
|
||||
@@ -321,12 +321,13 @@ pub mod test {
|
||||
use frame_support::traits::ConstU32;
|
||||
use sp_io::TestExternalities;
|
||||
|
||||
crate::generate_storage_alias! { Prefix, Foo => Value<WeakBoundedVec<u32, ConstU32<7>>> }
|
||||
crate::generate_storage_alias! { Prefix, FooMap => Map<(Twox128, u32), WeakBoundedVec<u32, ConstU32<7>>> }
|
||||
crate::generate_storage_alias! {
|
||||
Prefix,
|
||||
FooDoubleMap => DoubleMap<(Twox128, u32), (Twox128, u32), WeakBoundedVec<u32, ConstU32<7>>>
|
||||
}
|
||||
#[crate::storage_alias]
|
||||
type Foo = StorageValue<Prefix, WeakBoundedVec<u32, ConstU32<7>>>;
|
||||
#[crate::storage_alias]
|
||||
type FooMap = StorageMap<Prefix, Twox128, u32, WeakBoundedVec<u32, ConstU32<7>>>;
|
||||
#[crate::storage_alias]
|
||||
type FooDoubleMap =
|
||||
StorageDoubleMap<Prefix, Twox128, u32, Twox128, u32, WeakBoundedVec<u32, ConstU32<7>>>;
|
||||
|
||||
#[test]
|
||||
fn bound_returns_correct_value() {
|
||||
|
||||
Reference in New Issue
Block a user