Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve FRAME storage docs #1714

Merged
merged 26 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7544664
Move macro docs from procedural to pallet_macros
wentelteefje Sep 25, 2023
3b1bcc7
Added Storage types docs, altered RA hint
wentelteefje Sep 26, 2023
53649ea
Tidy up RA hint for genesis macros
wentelteefje Sep 27, 2023
b9f3b65
Unify storage item naming in examples
wentelteefje Sep 27, 2023
9fce277
Fixed missing links, fmt
wentelteefje Sep 27, 2023
ad9df39
Fixed pallet::call example
wentelteefje Sep 27, 2023
d91c8a7
Added simple count example for CountedStorageMap
wentelteefje Sep 27, 2023
c4824bb
fmt
wentelteefje Sep 27, 2023
9f812c7
Added ValueQuery Draft
wentelteefje Sep 28, 2023
e2d36b9
Small changes to QueryKindTraits
wentelteefje Sep 28, 2023
5cd7a8a
Small corrections
wentelteefje Sep 28, 2023
a1ccd97
Added clarification on OnEmpty use with ValueQuery
wentelteefje Sep 28, 2023
23c996e
Add examples for append, decode_len, some general restructuring
wentelteefje Oct 16, 2023
ebdcc93
Move related macros to EOF for now
wentelteefje Oct 16, 2023
ee4d9d8
fmt
wentelteefje Oct 16, 2023
88620dc
Add double map partial iter example
wentelteefje Oct 17, 2023
181ac49
Add removal to double map example
wentelteefje Oct 17, 2023
9c08356
Small text fixes
wentelteefje Oct 17, 2023
0cefca2
Fix cmmts in syntax code
wentelteefje Oct 17, 2023
944b7a8
Merge branch 'master' into wentelteefje-improve-storage-docs
wentelteefje Oct 17, 2023
711ced9
Some storage macro rework +fmt
wentelteefje Oct 18, 2023
ed45000
Added prefixes examples, fixed headings
wentelteefje Oct 18, 2023
26633e6
Make prefix example adhere to actual prefix logic
wentelteefje Oct 18, 2023
126c412
Clean up storage macro page
wentelteefje Oct 20, 2023
198156b
update
kianenigma Nov 1, 2023
4dd8f40
Master.into()
kianenigma Nov 1, 2023
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
30 changes: 17 additions & 13 deletions substrate/frame/bags-list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,33 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
# parity
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.10.0", default-features = false, features = [
"derive",
] }

# primitives
sp-runtime = { path = "../../primitives/runtime", default-features = false}
sp-std = { path = "../../primitives/std", default-features = false}
sp-runtime = { path = "../../primitives/runtime", default-features = false }
sp-std = { path = "../../primitives/std", default-features = false }

# FRAME
frame-support = { path = "../support", default-features = false}
frame-system = { path = "../system", default-features = false}
frame-election-provider-support = { path = "../election-provider-support", default-features = false}
frame-support = { path = "../support", default-features = false }
frame-system = { path = "../system", default-features = false }
frame-election-provider-support = { path = "../election-provider-support", default-features = false }

# third party
log = { version = "0.4.17", default-features = false }
docify = "0.2.6"
aquamarine = { version = "0.3.2" }

# Optional imports for benchmarking
frame-benchmarking = { path = "../benchmarking", default-features = false , optional = true}
pallet-balances = { path = "../balances", default-features = false , optional = true}
sp-core = { path = "../../primitives/core", default-features = false , optional = true}
sp-io = { path = "../../primitives/io", default-features = false , optional = true}
sp-tracing = { path = "../../primitives/tracing", default-features = false , optional = true}
frame-benchmarking = { path = "../benchmarking", default-features = false, optional = true }
pallet-balances = { path = "../balances", default-features = false, optional = true }
sp-core = { path = "../../primitives/core", default-features = false, optional = true }
sp-io = { path = "../../primitives/io", default-features = false, optional = true }
sp-tracing = { path = "../../primitives/tracing", default-features = false, optional = true }

[dev-dependencies]
sp-core = { path = "../../primitives/core" }
Expand All @@ -46,7 +50,7 @@ frame-election-provider-support = { path = "../election-provider-support" }
frame-benchmarking = { path = "../benchmarking" }

[features]
default = [ "std" ]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
Expand Down
94 changes: 33 additions & 61 deletions substrate/frame/support/procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,21 +979,26 @@ pub fn config(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
}

/// The `#[pallet::constant]` attribute can be used to add an associated type trait bounded by `Get`
/// from [`pallet::config`](`macro@config`) into metadata, e.g.:
///
/// ```ignore
/// #[pallet::config]
/// pub trait Config: frame_system::Config {
/// #[pallet::constant]
/// type Foo: Get<u32>;
/// }
/// ```
/// ---
///
/// **Rust-Analyzer users**: See the documentation of the Rust item in
/// `frame_support::pallet_macros::constant`.
#[proc_macro_attribute]
pub fn constant(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
}

///
/// ---
///
/// **Rust-Analyzer users**: See the documentation of the Rust item in
/// `frame_support::pallet_macros::constant_name`.
#[proc_macro_attribute]
pub fn constant_name(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
}

/// To bypass the `frame_system::Config` supertrait check, use the attribute
/// `pallet::disable_frame_system_supertrait_check`, e.g.:
///
Expand Down Expand Up @@ -1099,6 +1104,16 @@ pub fn compact(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
}

///
/// ---
///
/// **Rust-Analyzer users**: See the documentation of the Rust item in
/// `frame_support::pallet_macros::call`.
#[proc_macro_attribute]
wentelteefje marked this conversation as resolved.
Show resolved Hide resolved
pub fn call(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
}

/// Each dispatchable may also be annotated with the `#[pallet::call_index($idx)]` attribute,
/// which explicitly defines the codec index for the dispatchable function in the `Call` enum.
///
Expand Down Expand Up @@ -1268,60 +1283,11 @@ pub fn generate_deposit(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
}

/// The `#[pallet::storage]` attribute lets you define some abstract storage inside of runtime
/// storage and also set its metadata. This attribute can be used multiple times.
///
/// Item should be defined as:
/// ---
///
/// ```ignore
/// #[pallet::storage]
/// #[pallet::getter(fn $getter_name)] // optional
/// $vis type $StorageName<$some_generic> $optional_where_clause
/// = $StorageType<$generic_name = $some_generics, $other_name = $some_other, ...>;
/// ```
///
/// or with unnamed generic:
///
/// ```ignore
/// #[pallet::storage]
/// #[pallet::getter(fn $getter_name)] // optional
/// $vis type $StorageName<$some_generic> $optional_where_clause
/// = $StorageType<_, $some_generics, ...>;
/// ```
///
/// I.e. it must be a type alias, with generics: `T` or `T: Config`. The aliased type must be
/// one of `StorageValue`, `StorageMap` or `StorageDoubleMap`. The generic arguments of the
/// storage type can be given in two manners: named and unnamed. For named generic arguments,
/// the name for each argument should match the name defined for it on the storage struct:
/// * `StorageValue` expects `Value` and optionally `QueryKind` and `OnEmpty`,
/// * `StorageMap` expects `Hasher`, `Key`, `Value` and optionally `QueryKind` and `OnEmpty`,
/// * `CountedStorageMap` expects `Hasher`, `Key`, `Value` and optionally `QueryKind` and `OnEmpty`,
/// * `StorageDoubleMap` expects `Hasher1`, `Key1`, `Hasher2`, `Key2`, `Value` and optionally
/// `QueryKind` and `OnEmpty`.
///
/// For unnamed generic arguments: Their first generic must be `_` as it is replaced by the
/// macro and other generic must declared as a normal generic type declaration.
///
/// The `Prefix` generic written by the macro is generated using
/// `PalletInfo::name::<Pallet<..>>()` and the name of the storage type. E.g. if runtime names
/// the pallet "MyExample" then the storage `type Foo<T> = ...` should use the prefix:
/// `Twox128(b"MyExample") ++ Twox128(b"Foo")`.
///
/// For the `CountedStorageMap` variant, the `Prefix` also implements
/// `CountedStorageMapInstance`. It also associates a `CounterPrefix`, which is implemented the
/// same as above, but the storage prefix is prepend with `"CounterFor"`. E.g. if runtime names
/// the pallet "MyExample" then the storage `type Foo<T> = CountedStorageaMap<...>` will store
/// its counter at the prefix: `Twox128(b"MyExample") ++ Twox128(b"CounterForFoo")`.
///
/// E.g:
///
/// ```ignore
/// #[pallet::storage]
/// pub(super) type MyStorage<T> = StorageMap<Hasher = Blake2_128Concat, Key = u32, Value = u32>;
/// ```
///
/// In this case the final prefix used by the map is `Twox128(b"MyExample") ++
/// Twox128(b"OtherName")`.
/// **Rust-Analyzer users**: See the documentation of the Rust item in
/// `frame_support::pallet_macros::storage`.
#[proc_macro_attribute]
pub fn storage(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
Expand Down Expand Up @@ -1424,13 +1390,19 @@ pub fn type_value(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
}

///
/// ---
///
/// **Rust-Analyzer users**: See the documentation of the Rust item in
/// `frame_support::pallet_macros::genesis_config`.
#[proc_macro_attribute]
pub fn genesis_config(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
}

///
/// ---
///
/// **Rust-Analyzer users**: See the documentation of the Rust item in
/// `frame_support::pallet_macros::genesis_build`.
#[proc_macro_attribute]
Expand Down
Loading
Loading