mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 11:38:01 +00:00
Allow renaming storage item prefixes (#9016)
* Implement parsing for #[pallet::storage_name] on storage items * Rename storage prefix when a #[pallet::storage_name] is supplied * Fix test_storage_info * Rename storage_name to storage_prefix * Check for duplicates when renaming storage prefixes * Allow only string literals for storage_prefix renames * Use proper spans for attribute errors * Check for valid identifiers when parsing storage prefix renames
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::StorageValue;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(trait Store)]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::storage]
|
||||
type Foo<T> = StorageValue<_, u8>;
|
||||
|
||||
#[pallet::storage]
|
||||
#[pallet::storage_prefix = "Foo"]
|
||||
type NotFoo<T> = StorageValue<_, u16>;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
error: Duplicate storage prefixes found for `Foo`
|
||||
--> $DIR/duplicate_storage_prefix.rs:16:32
|
||||
|
|
||||
16 | #[pallet::storage_prefix = "Foo"]
|
||||
| ^^^^^
|
||||
|
||||
error[E0412]: cannot find type `_GeneratedPrefixForStorageFoo` in this scope
|
||||
--> $DIR/duplicate_storage_prefix.rs:13:7
|
||||
|
|
||||
13 | type Foo<T> = StorageValue<_, u8>;
|
||||
| ^^^ not found in this scope
|
||||
|
||||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
|
||||
--> $DIR/duplicate_storage_prefix.rs:17:35
|
||||
|
|
||||
17 | type NotFoo<T> = StorageValue<_, u16>;
|
||||
| ^ not allowed in type signatures
|
||||
@@ -0,0 +1,21 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::Hooks;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
|
||||
#[pallet::storage]
|
||||
#[pallet::generate_store(pub trait Store)]
|
||||
type Foo<T> = StorageValue<u8, u8>;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: expected `getter` or `storage_prefix`
|
||||
--> $DIR/storage_invalid_attribute.rs:16:12
|
||||
|
|
||||
16 | #[pallet::generate_store(pub trait Store)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
@@ -0,0 +1,18 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::Hooks;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::storage]
|
||||
#[pallet::storage_prefix = "pub"]
|
||||
type Foo<T> = StorageValue<_, u8>;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: `pub` is not a valid identifier
|
||||
--> $DIR/storage_invalid_rename_value.rs:13:29
|
||||
|
|
||||
13 | #[pallet::storage_prefix = "pub"]
|
||||
| ^^^^^
|
||||
@@ -0,0 +1,25 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::Hooks;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn get_foo)]
|
||||
#[pallet::getter(fn foo_error)]
|
||||
type Foo<T> = StorageValue<_, u8>;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid pallet::storage, multiple argument pallet::getter found
|
||||
--> $DIR/storage_multiple_getters.rs:20:3
|
||||
|
|
||||
20 | #[pallet::getter(fn foo_error)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -0,0 +1,25 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::Hooks;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
|
||||
#[pallet::storage]
|
||||
#[pallet::storage_prefix = "Bar"]
|
||||
#[pallet::storage_prefix = "Baz"]
|
||||
type Foo<T> = StorageValue<_, u8>;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid pallet::storage, multiple argument pallet::storage_prefix found
|
||||
--> $DIR/storage_multiple_renames.rs:20:3
|
||||
|
|
||||
20 | #[pallet::storage_prefix = "Baz"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Reference in New Issue
Block a user