pallet macro: allow to declare individual unbounded storage for those who cannot go into PoV (#9670)

* allow unbounded individual storage

* better doc

* fix UI tests

* update doc

* Update frame/support/procedural/src/pallet/parse/storage.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Guillaume Thiolliere
2021-09-27 10:25:24 +02:00
committed by GitHub
parent d565382b50
commit 1ebcbe1c34
7 changed files with 106 additions and 44 deletions
@@ -329,6 +329,10 @@ pub mod pallet {
pub type SomeCountedStorageMap<T> =
CountedStorageMap<Hasher = Twox64Concat, Key = u8, Value = u32>;
#[pallet::storage]
#[pallet::unbounded]
pub type Unbounded<T> = StorageValue<Value = Vec<u8>>;
#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {
@@ -917,6 +921,10 @@ fn storage_expand() {
assert_eq!(unhashed::get::<u32>(&k), Some(2u32));
let k = [twox_128(b"Example"), twox_128(b"CounterForRenamedCountedMap")].concat();
assert_eq!(unhashed::get::<u32>(&k), Some(1u32));
pallet::Unbounded::<Runtime>::put(vec![1, 2]);
let k = [twox_128(b"Example"), twox_128(b"Unbounded")].concat();
assert_eq!(unhashed::get::<Vec<u8>>(&k), Some(vec![1, 2]));
})
}
@@ -1170,6 +1178,13 @@ fn metadata() {
default: vec![0, 0, 0, 0],
docs: vec!["Counter for the related counted storage map"],
},
StorageEntryMetadata {
name: "Unbounded",
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::Plain(meta_type::<Vec<u8>>()),
default: vec![0],
docs: vec![],
},
],
}),
calls: Some(meta_type::<pallet::Call<Runtime>>().into()),
@@ -1411,6 +1426,13 @@ fn test_storage_info() {
max_values: Some(1),
max_size: Some(4),
},
StorageInfo {
pallet_name: b"Example".to_vec(),
storage_name: b"Unbounded".to_vec(),
prefix: prefix(b"Example", b"Unbounded").to_vec(),
max_values: Some(1),
max_size: None,
},
],
);
@@ -1,4 +1,4 @@
error: expected `getter` or `storage_prefix`
error: expected one of: `getter`, `storage_prefix`, `unbounded`
--> $DIR/storage_invalid_attribute.rs:16:12
|
16 | #[pallet::generate_store(pub trait Store)]
@@ -1,4 +1,4 @@
error: Invalid pallet::storage, multiple argument pallet::getter found
error: Invalid attribute: Duplicate attribute
--> $DIR/storage_multiple_getters.rs:20:3
|
20 | #[pallet::getter(fn foo_error)]
@@ -1,4 +1,4 @@
error: Invalid pallet::storage, multiple argument pallet::storage_prefix found
error: Invalid attribute: Duplicate attribute
--> $DIR/storage_multiple_renames.rs:20:3
|
20 | #[pallet::storage_prefix = "Baz"]