Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9d98d15
initial impl
shawntabrizi Jun 12, 2021
989d02b
expose in pallet_prelude
shawntabrizi Jun 12, 2021
a6321b1
temp test
shawntabrizi Jun 12, 2021
9ce58da
Apply suggestions from code review
gui1117 Jun 14, 2021
899eea4
implement with macro help.
gui1117 Jun 14, 2021
b5b74a1
Merge remote-tracking branch 'origin/master' into shawntabrizi-counte…
gui1117 Jun 15, 2021
43e635f
test for macro generation
gui1117 Jun 15, 2021
9885891
add iterable functions, some test and fixes
gui1117 Jun 15, 2021
2406021
Merge remote-tracking branch 'origin/master' into shawntabrizi-counte…
gui1117 Jun 16, 2021
4f31878
fix merge
gui1117 Jun 16, 2021
c588233
doc
gui1117 Jun 16, 2021
9c362a6
Update frame/support/src/storage/types/counted_map.rs
gui1117 Jul 5, 2021
ed44b79
Merge remote-tracking branch 'origin/master' into gui-shawntabrizi-co…
gui1117 Aug 6, 2021
cdb3fa3
fix merge
gui1117 Aug 6, 2021
f7417cf
fmt
gui1117 Aug 6, 2021
61208a4
fix spelling
gui1117 Aug 6, 2021
30da101
improve on removal
gui1117 Aug 6, 2021
c546c2e
fix partial storage info
gui1117 Aug 6, 2021
1e11c16
fmt
gui1117 Aug 6, 2021
497bc69
add license
gui1117 Aug 7, 2021
cc249fb
suggested renames
gui1117 Aug 7, 2021
4d6de59
fix typo
gui1117 Aug 7, 2021
3313f73
Merge remote-tracking branch 'origin/master' into gui-shawntabrizi-co…
gui1117 Sep 15, 2021
a4c7f3f
fix test
gui1117 Sep 15, 2021
4841dbb
fmt
gui1117 Sep 15, 2021
b3d2111
fix ui tests
gui1117 Sep 16, 2021
4b62aab
clearer doc
gui1117 Sep 16, 2021
448937d
better doc
gui1117 Sep 16, 2021
cc13432
add metadata test
gui1117 Sep 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
doc
  • Loading branch information
gui1117 committed Jun 16, 2021
commit c588233c6b2dc6033dc9caca043dc7fd57726b27
23 changes: 20 additions & 3 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,23 +1626,37 @@ pub mod pallet_prelude {
/// * [`pallet_prelude::StorageValue`] expect `Value` and optionally `QueryKind` and `OnEmpty`,
/// * [`pallet_prelude::StorageMap`] expect `Hasher`, `Key`, `Value` and optionally `QueryKind` and
/// `OnEmpty`,
/// * [`pallet_prelude::CountedStorageMap`] expect `Hasher`, `Key`, `Value` and optionally
/// `QueryKind` and `OnEmpty`,
/// * [`pallet_prelude::StorageDoubleMap`] expect `Hasher1`, `Key1`, `Hasher2`, `Key2`, `Value` and
/// optionally `QueryKind` and `OnEmpty`.
///
/// For unnamed generic argument: Their first generic must be `_` as it is replaced by the macro
/// and other generic must declared as a normal declaration of type generic in rust.
///
/// The Prefix generic written by the macro is generated using `PalletInfo::name::<Pallet<..>>()`
/// and the name of the storage type.
/// The `Prefix` generic written by the macro. It implements `StorageInstance` using
/// `PalletInfo::name::<Pallet<..>>()` for the pallet prefix and the name of the storage type or
/// the rename as in `#[pallet::storage_prefix = "Bar"]` for storage prefix.
/// E.g. if runtime names the pallet "MyExample" then the storage `type Foo<T> = ...` use the
/// prefix: `Twox128(b"MyExample") ++ Twox128(b"Foo")`.
/// pallet prefix: "MyExample" and the storage prefix "Foo".
///
/// NOTE: Storages use those prefixes so that values are stored after the key
/// `Twox128(b"MyExample") ++ Twox128(b"Foo")`.
///
/// For the `CountedStorageMap` variant, the Prefix also implements `CountedStorageMapInstance`.
/// It associate a `CounterPrefix`, which is implemented same as above, but the storage prefix is
/// prepend with `"CounterFor"`.
///
/// The optional attribute `#[pallet::getter(fn $my_getter_fn_name)]` allow to define a
/// getter function on `Pallet`.
///
/// The optional attribute `#[pallet::storage_prefix = "SomeName"]` allow to define the storage
/// prefix to use, see how `Prefix` generic is implemented above.
///
/// E.g:
/// ```ignore
/// #[pallet::storage]
/// #[pallet::storage_prefix = "foo"]
/// #[pallet::getter(fn my_storage)]
/// pub(super) type MyStorage<T> = StorageMap<Hasher = Blake2_128Concat, Key = u32, Value = u32>;
/// ```
Expand Down Expand Up @@ -1679,6 +1693,8 @@ pub mod pallet_prelude {
/// `_GeneratedPrefixForStorage$NameOfStorage`, and implements
/// [`StorageInstance`](traits::StorageInstance) on it using the pallet and storage name. It then
/// uses it as the first generic of the aliased type.
/// For `CountedStorageMap`, `CountedStorageMapInstance` is implemented, and another similar struct
/// is generated.
///
/// For named generic, the macro will reorder the generics, and remove the names.
///
Expand Down Expand Up @@ -1966,6 +1982,7 @@ pub mod pallet_prelude {
///
/// // Another storage declaration
/// #[pallet::storage]
/// #[pallet::storage_prefix = "SomeName"]
/// #[pallet::getter(fn my_storage)]
/// pub(super) type MyStorage<T> =
/// StorageMap<Hasher = Blake2_128Concat, Key = u32, Value = u32>;
Expand Down
6 changes: 2 additions & 4 deletions frame/support/src/storage/types/counted_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use frame_metadata::{
};
use max_encoded_len::MaxEncodedLen;

/// A wrapper around a `StorageMap` and a `StorageValue<u32>` to keep track of how many items are in
/// a map, without needing to iterate all the values.
/// A wrapper around a `StorageMap` and a `StorageValue<Value=u32>` to keep track of how many items
/// are in a map, without needing to iterate all the values.
///
/// This storage item has additional storage read and write overhead when manipulating values
/// compared to a regular storage map.
Expand All @@ -29,8 +29,6 @@ use max_encoded_len::MaxEncodedLen;
///
/// Whenever the counter needs to be updated, an additional read and write occurs to update that
/// counter.
///
/// The storage prefix for the storage value is the given prefix concatenated with `"Counter"`.
pub struct CountedStorageMap<
Prefix, Hasher, Key, Value, QueryKind=OptionQuery, OnEmpty=GetDefault, MaxValues=GetDefault,
>(
Expand Down