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:
Bastian Köcher
2022-05-18 00:45:56 +02:00
committed by GitHub
parent 27f08fec3a
commit 74428fa8ac
21 changed files with 884 additions and 379 deletions
@@ -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);