Macro frame_support::generate_storage_alias[][src]

macro_rules! generate_storage_alias {
    ($pallet:ident, $name:ident => Map<($key:ty, $hasher:ty), $value:ty>) => { ... };
    ($pallet:ident, $name:ident => DoubleMap<($key1:ty, $hasher1:ty), ($key2:ty, $hasher2:ty), $value:ty>) => { ... };
    ($pallet:ident, $name:ident => NMap<Key<$(($key:ty, $hasher:ty)),+>, $value:ty>) => { ... };
    ($pallet:ident, $name:ident => Value<$value:ty>) => { ... };
    ($pallet:ident, $name:ident<$t:ident : $bounds:tt> => Map<($key:ty, $hasher:ty), $value:ty>) => { ... };
    (
		$pallet:ident,
		$name:ident<$t:ident : $bounds:tt>
		=> DoubleMap<($key1:ty, $hasher1:ty), ($key2:ty, $hasher2:ty), $value:ty>) => { ... };
    (
		$pallet:ident,
		$name:ident<$t:ident : $bounds:tt> => NMap<$(($key:ty, $hasher:ty),)+ $value:ty>
	) => { ... };
    ($pallet:ident, $name:ident<$t:ident : $bounds:tt> => Value<$value:ty>) => { ... };
    (@GENERATE_INSTANCE_STRUCT $pallet:ident, $name:ident) => { ... };
}
Expand description

Generate a new type alias for storage::types::StorageValue, storage::types::StorageMap, storage::types::StorageDoubleMap and storage::types::StorageNMap.

Useful for creating a storage-like struct for test and migrations.

use frame_support::codec;
use frame_support::Twox64Concat;
// generate a storage value with type u32.
generate_storage_alias!(Prefix, StorageName => Value<u32>);

// generate a double map from `(u32, u32)` (with hashers `Twox64Concat` for each key)
// to `Vec<u8>`
generate_storage_alias!(
	OtherPrefix, OtherStorageName => DoubleMap<
		(u32, Twox64Concat),
		(u32, Twox64Concat),
		Vec<u8>
	>
);

// generate a map from `Config::AccountId` (with hasher `Twox64Concat`) to `Vec<u8>`
trait Config { type AccountId: codec::FullCodec; }
generate_storage_alias!(
	Prefix, GenericStorage<T: Config> => Map<(T::AccountId, Twox64Concat), Vec<u8>>
);