mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 04:41:03 +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:
@@ -368,12 +368,10 @@ mod list {
|
||||
assert_eq!(crate::ListNodes::<Runtime>::count(), 4);
|
||||
// we do some wacky stuff here to get access to the counter, since it is (reasonably)
|
||||
// not exposed as mutable in any sense.
|
||||
frame_support::generate_storage_alias!(
|
||||
BagsList,
|
||||
CounterForListNodes
|
||||
=> Value<u32, frame_support::pallet_prelude::ValueQuery>
|
||||
);
|
||||
CounterForListNodes::mutate(|counter| *counter += 1);
|
||||
#[frame_support::storage_alias]
|
||||
type CounterForListNodes<T: Config> =
|
||||
StorageValue<crate::Pallet<T>, u32, frame_support::pallet_prelude::ValueQuery>;
|
||||
CounterForListNodes::<Runtime>::mutate(|counter| *counter += 1);
|
||||
assert_eq!(crate::ListNodes::<Runtime>::count(), 5);
|
||||
|
||||
assert_eq!(List::<Runtime>::sanity_check(), Err("iter_count != stored_count"));
|
||||
|
||||
@@ -30,11 +30,12 @@ impl<T: crate::Config> OnRuntimeUpgrade for CheckCounterPrefix<T> {
|
||||
fn pre_upgrade() -> Result<(), &'static str> {
|
||||
use frame_support::ensure;
|
||||
// The old explicit storage item.
|
||||
frame_support::generate_storage_alias!(BagsList, CounterForListNodes => Value<u32>);
|
||||
#[frame_support::storage_alias]
|
||||
type CounterForListNodes<T: crate::Config> = StorageValue<crate::Pallet<T>, u32>;
|
||||
|
||||
// ensure that a value exists in the counter struct.
|
||||
ensure!(
|
||||
crate::ListNodes::<T>::count() == CounterForListNodes::get().unwrap(),
|
||||
crate::ListNodes::<T>::count() == CounterForListNodes::<T>::get().unwrap(),
|
||||
"wrong list node counter"
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user