[][src]Macro srml_support_procedural::decl_storage

decl_storage!() { /* proc-macro */ }

Declares strongly-typed wrappers around codec-compatible types in storage.


decl_storage! {
	trait Store for Module<T: Trait> as Example {
		Foo get(foo) config(): u32=12;
		Bar: map u32 => u32;
		pub Zed build(|config| vec![(0, 0)]): linked_map u32 => u32;

Declaration is set with the header (pub) trait Store for Module<T: Trait> as Example, with Store a (pub) trait generated associating each storage item to the Module and as Example setting the prefix used for storage items of this module. Example must be unique: another module with the same name and the same inner storage item name will conflict.

Basic storage consists of a name and a type; supported types are:

Basic storage can be extended as such:

#vis #name get(#getter) config(#field_name) build(#closure): #type = #default;

Storage items are accessible in multiple ways:


An optional GenesisConfig struct for storage initialization can be defined, either when at least one storage field requires default initialization (both get and config or build), or specifically as in:

decl_storage! {
	trait Store for Module<T: Trait> as Example {

		// Your storage items
	add_extra_genesis {
		config(genesis_field): GenesisFieldType;
		config(genesis_field2): GenesisFieldType;
		build(|_: &mut StorageOverlay, _: &mut ChildrenStorageOverlay, _: &GenesisConfig<T>| {
			// Modification of storage

This struct can be exposed as Config by the decl_runtime! macro.

Module with Instances

The decl_storage! macro supports building modules with instances with the following syntax (DefaultInstance type is optional):

trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Example {}

Then the genesis config is generated with two generic parameters (i.e. GenesisConfig<T, I>) and storage items are accessible using two generic parameters, e.g.: <Dummy<T, I>>::get() or Dummy::<T, I>::get().