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
@@ -17,6 +17,7 @@
use frame_support::{
dispatch::{Parameter, UnfilteredDispatchable},
pallet_prelude::ValueQuery,
storage::unhashed,
traits::{
ConstU32, GetCallName, GetStorageVersion, OnFinalize, OnGenesis, OnInitialize,
@@ -1631,3 +1632,17 @@ fn assert_type_all_pallets_without_system_reversed_is_correct() {
_a(t)
}
}
#[test]
fn test_storage_alias() {
#[frame_support::storage_alias]
type Value<T: pallet::Config>
where
<T as frame_system::Config>::AccountId: From<SomeType1> + SomeAssociation1,
= StorageValue<pallet::Pallet<T>, u32, ValueQuery>;
TestExternalities::default().execute_with(|| {
pallet::Value::<Runtime>::put(10);
assert_eq!(10, Value::<Runtime>::get());
})
}