mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 07:11:06 +00:00
Modify doublemap syntax (#4576)
* modify doublemap syntax * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -165,7 +165,7 @@ decl_storage! {
|
||||
trait Store for Module<T: Trait> as Example {
|
||||
Accounts get(fn accounts) config(): map H160 => Account;
|
||||
AccountCodes: map H160 => Vec<u8>;
|
||||
AccountStorages: double_map H160, blake2_256(H256) => H256;
|
||||
AccountStorages: double_map H160, H256 => H256;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -492,10 +492,10 @@ decl_storage! {
|
||||
}): map T::AssetId => T::Balance;
|
||||
|
||||
/// The free balance of a given asset under an account.
|
||||
pub FreeBalance: double_map T::AssetId, twox_128(T::AccountId) => T::Balance;
|
||||
pub FreeBalance: double_map T::AssetId, hasher(twox_128) T::AccountId => T::Balance;
|
||||
|
||||
/// The reserved balance of a given asset under an account.
|
||||
pub ReservedBalance: double_map T::AssetId, twox_128(T::AccountId) => T::Balance;
|
||||
pub ReservedBalance: double_map T::AssetId, hasher(twox_128) T::AccountId => T::Balance;
|
||||
|
||||
/// Next available ID for user-created asset.
|
||||
pub NextAssetId get(fn next_asset_id) config(): T::AssetId;
|
||||
|
||||
@@ -233,13 +233,12 @@ decl_storage! {
|
||||
|
||||
/// For each session index, we keep a mapping of `AuthIndex`
|
||||
/// to `offchain::OpaqueNetworkState`.
|
||||
ReceivedHeartbeats get(fn received_heartbeats): double_map SessionIndex,
|
||||
blake2_256(AuthIndex) => Option<Vec<u8>>;
|
||||
ReceivedHeartbeats get(fn received_heartbeats): double_map SessionIndex, AuthIndex
|
||||
=> Option<Vec<u8>>;
|
||||
|
||||
/// For each session index, we keep a mapping of `T::ValidatorId` to the
|
||||
/// number of blocks authored by the given authority.
|
||||
AuthoredBlocks get(fn authored_blocks): double_map SessionIndex,
|
||||
blake2_256(T::ValidatorId) => u32;
|
||||
AuthoredBlocks get(fn authored_blocks): double_map SessionIndex, T::ValidatorId => u32;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(keys): Vec<T::AuthorityId>;
|
||||
|
||||
@@ -57,7 +57,7 @@ decl_storage! {
|
||||
Reports get(fn reports): map ReportIdOf<T> => Option<OffenceDetails<T::AccountId, T::IdentificationTuple>>;
|
||||
|
||||
/// A vector of reports of the same kind that happened at the same time slot.
|
||||
ConcurrentReportsIndex: double_map Kind, blake2_256(OpaqueTimeSlot) => Vec<ReportIdOf<T>>;
|
||||
ConcurrentReportsIndex: double_map Kind, OpaqueTimeSlot => Vec<ReportIdOf<T>>;
|
||||
|
||||
/// Enumerates all reports of a kind along with the time they happened.
|
||||
///
|
||||
|
||||
@@ -398,13 +398,15 @@ decl_storage! {
|
||||
///
|
||||
/// The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of
|
||||
/// the trie. Having all data in the same branch should prevent slowing down other queries.
|
||||
NextKeys: double_map hasher(twox_64_concat) Vec<u8>, blake2_256(T::ValidatorId) => Option<T::Keys>;
|
||||
NextKeys: double_map hasher(twox_64_concat) Vec<u8>, hasher(blake2_256) T::ValidatorId
|
||||
=> Option<T::Keys>;
|
||||
|
||||
/// The owner of a key. The second key is the `KeyTypeId` + the encoded key.
|
||||
///
|
||||
/// The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of
|
||||
/// the trie. Having all data in the same branch should prevent slowing down other queries.
|
||||
KeyOwner: double_map hasher(twox_64_concat) Vec<u8>, blake2_256((KeyTypeId, Vec<u8>)) => Option<T::ValidatorId>;
|
||||
KeyOwner: double_map hasher(twox_64_concat) Vec<u8>, hasher(blake2_256) (KeyTypeId, Vec<u8>)
|
||||
=> Option<T::ValidatorId>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(keys): Vec<(T::ValidatorId, T::Keys)>;
|
||||
|
||||
@@ -738,11 +738,11 @@ decl_storage! {
|
||||
/// All slashing events on validators, mapped by era to the highest slash proportion
|
||||
/// and slash value of the era.
|
||||
ValidatorSlashInEra:
|
||||
double_map EraIndex, twox_128(T::AccountId) => Option<(Perbill, BalanceOf<T>)>;
|
||||
double_map EraIndex, hasher(twox_128) T::AccountId => Option<(Perbill, BalanceOf<T>)>;
|
||||
|
||||
/// All slashing events on nominators, mapped by era to the highest slash value of the era.
|
||||
NominatorSlashInEra:
|
||||
double_map EraIndex, twox_128(T::AccountId) => Option<BalanceOf<T>>;
|
||||
double_map EraIndex, hasher(twox_128) T::AccountId => Option<BalanceOf<T>>;
|
||||
|
||||
/// Slashing spans for stash accounts.
|
||||
SlashingSpans: map T::AccountId => Option<slashing::SlashingSpans>;
|
||||
|
||||
@@ -117,7 +117,7 @@ use proc_macro::TokenStream;
|
||||
/// Twox128(module_prefix) ++ Twox128(head_prefix)
|
||||
/// ```
|
||||
///
|
||||
/// * Double map: `Foo: double_map hasher($hash1) u32, $hash2(u32) => u32`: Implements the
|
||||
/// * Double map: `Foo: double_map hasher($hash1) u32, hasher($hash2) u32 => u32`: Implements the
|
||||
/// [`StorageDoubleMap`](../frame_support/storage/trait.StorageDoubleMap.html) trait using the
|
||||
/// [`StorageDoubleMap generator`](../frame_support/storage/generator/trait.StorageDoubleMap.html).
|
||||
/// And [`StoragePrefixedMap`](../frame_support/storage/trait.StoragePrefixedMap.html).
|
||||
@@ -126,10 +126,8 @@ use proc_macro::TokenStream;
|
||||
/// [`Hashable`](../frame_support/trait.Hashable.html) trait. They must be choosen with care, see
|
||||
/// generator documentation.
|
||||
///
|
||||
/// `hasher($hash)` is optional and its default is `blake2_256`.
|
||||
///
|
||||
/// `hasher($hash)` is optional and its default is `blake2_256`. One should use another hasher
|
||||
/// with care, see generator documentation.
|
||||
/// `hasher($hash1)` and `hasher($hash2) are optional and default to `blake2_256`.
|
||||
/// One should use another hasher with care, see generator documentation.
|
||||
///
|
||||
/// If the first key is untrusted, a cryptographic `hasher` such as `blake2_256` must be used.
|
||||
/// Otherwise, other values of all storage items can be compromised.
|
||||
|
||||
@@ -167,11 +167,11 @@ struct DeclStorageLinkedMap {
|
||||
#[derive(Parse, ToTokens, Debug)]
|
||||
struct DeclStorageDoubleMap {
|
||||
pub map_keyword: keyword::double_map,
|
||||
pub hasher: ext::Opt<SetHasher>,
|
||||
pub hasher1: ext::Opt<SetHasher>,
|
||||
pub key1: syn::Type,
|
||||
pub comma_keyword: Token![,],
|
||||
pub key2_hasher: Hasher,
|
||||
pub key2: ext::Parens<syn::Type>,
|
||||
pub hasher2: ext::Opt<SetHasher>,
|
||||
pub key2: syn::Type,
|
||||
pub ass_keyword: Token![=>],
|
||||
pub value: syn::Type,
|
||||
}
|
||||
@@ -380,11 +380,12 @@ fn parse_storage_line_defs(
|
||||
),
|
||||
DeclStorageType::DoubleMap(map) => super::StorageLineTypeDef::DoubleMap(
|
||||
super::DoubleMapDef {
|
||||
hasher1: map.hasher.inner.map(Into::into)
|
||||
hasher1: map.hasher1.inner.map(Into::into)
|
||||
.unwrap_or(super::HasherKind::Blake2_256),
|
||||
hasher2: map.hasher2.inner.map(Into::into)
|
||||
.unwrap_or(super::HasherKind::Blake2_256),
|
||||
hasher2: map.key2_hasher.into(),
|
||||
key1: map.key1,
|
||||
key2: map.key2.content,
|
||||
key2: map.key2,
|
||||
value: map.value,
|
||||
}
|
||||
),
|
||||
|
||||
@@ -261,12 +261,12 @@ mod tests {
|
||||
pub GetterNoFnKeyword get(no_fn): Option<u32>;
|
||||
|
||||
pub DataDM config(test_config) build(|_| vec![(15u32, 16u32, 42u64)]):
|
||||
double_map hasher(twox_64_concat) u32, blake2_256(u32) => u64;
|
||||
double_map hasher(twox_64_concat) u32, hasher(blake2_256) u32 => u64;
|
||||
pub GenericDataDM:
|
||||
double_map T::BlockNumber, twox_128(T::BlockNumber) => T::BlockNumber;
|
||||
double_map T::BlockNumber, hasher(twox_128) T::BlockNumber => T::BlockNumber;
|
||||
pub GenericData2DM:
|
||||
double_map T::BlockNumber, twox_256(T::BlockNumber) => Option<T::BlockNumber>;
|
||||
pub AppendableDM: double_map u32, blake2_256(T::BlockNumber) => Vec<u32>;
|
||||
double_map T::BlockNumber, hasher(twox_256) T::BlockNumber => Option<T::BlockNumber>;
|
||||
pub AppendableDM: double_map u32, T::BlockNumber => Vec<u32>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -562,9 +562,9 @@ mod test_append_and_len {
|
||||
MapVecWithDefault: map u32 => Vec<u32> = vec![6, 9];
|
||||
OptionMapVec: map u32 => Option<Vec<u32>>;
|
||||
|
||||
DoubleMapVec: double_map u32, blake2_256(u32) => Vec<u32>;
|
||||
DoubleMapVecWithDefault: double_map u32, blake2_256(u32) => Vec<u32> = vec![6, 9];
|
||||
OptionDoubleMapVec: double_map u32, blake2_256(u32) => Option<Vec<u32>>;
|
||||
DoubleMapVec: double_map u32, u32 => Vec<u32>;
|
||||
DoubleMapVecWithDefault: double_map u32, u32 => Vec<u32> = vec![6, 9];
|
||||
OptionDoubleMapVec: double_map u32, u32 => Option<Vec<u32>>;
|
||||
|
||||
LinkedMapVec: linked_map u32 => Vec<u32>;
|
||||
LinkedMapVecWithDefault: linked_map u32 => Vec<u32> = vec![6, 9];
|
||||
|
||||
@@ -41,12 +41,12 @@ mod no_instance {
|
||||
pub LinkedMap: linked_map u32 => u32;
|
||||
pub LinkedMap2: linked_map hasher(twox_128) u32 => u32;
|
||||
|
||||
pub DoubleMap: double_map u32, blake2_256(u32) => u32;
|
||||
pub DoubleMap2: double_map hasher(twox_128) u32, blake2_128(u32) => u32;
|
||||
pub DoubleMap: double_map u32, u32 => u32;
|
||||
pub DoubleMap2: double_map hasher(twox_128) u32, hasher(blake2_128) u32 => u32;
|
||||
|
||||
pub TestGenericValue get(fn test_generic_value) config(): Option<T::BlockNumber>;
|
||||
pub TestGenericDoubleMap get(fn foo2) config(test_generic_double_map):
|
||||
double_map u32, blake2_256(T::BlockNumber) => Option<u32>;
|
||||
double_map u32, T::BlockNumber => Option<u32>;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,12 +71,12 @@ mod instance {
|
||||
pub LinkedMap: linked_map u32 => u32;
|
||||
pub LinkedMap2: linked_map hasher(twox_128) u32 => u32;
|
||||
|
||||
pub DoubleMap: double_map u32, blake2_256(u32) => u32;
|
||||
pub DoubleMap2: double_map hasher(twox_128) u32, blake2_128(u32) => u32;
|
||||
pub DoubleMap: double_map u32, u32 => u32;
|
||||
pub DoubleMap2: double_map hasher(twox_128) u32, hasher(blake2_128) u32 => u32;
|
||||
|
||||
pub TestGenericValue get(fn test_generic_value) config(): Option<T::BlockNumber>;
|
||||
pub TestGenericDoubleMap get(fn foo2) config(test_generic_double_map):
|
||||
double_map u32, blake2_256(T::BlockNumber) => Option<u32>;
|
||||
double_map u32, T::BlockNumber => Option<u32>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
// See `decl_storage` limitation.
|
||||
|
||||
@@ -25,7 +25,7 @@ frame_support::decl_module! {
|
||||
|
||||
frame_support::decl_storage! {
|
||||
trait Store for Module<T: Trait> as Example {
|
||||
pub AppendableDM config(t): double_map u32, blake2_256(T::BlockNumber) => Vec<u32>;
|
||||
pub AppendableDM config(t): double_map u32, T::BlockNumber => Vec<u32>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ mod module2 {
|
||||
pub Value config(value): T::Amount;
|
||||
pub Map config(map): map u64 => u64;
|
||||
pub LinkedMap config(linked_map): linked_map u64 => Vec<u8>;
|
||||
pub DoubleMap config(double_map): double_map u64, blake2_256(u64) => u64;
|
||||
pub DoubleMap config(double_map): double_map u64, u64 => u64;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,8 @@ pub struct Multisig<BlockNumber, Balance, AccountId> {
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as Utility {
|
||||
/// The set of open multisig operations.
|
||||
pub Multisigs: double_map hasher(twox_64_concat) T::AccountId, blake2_128_concat([u8; 32])
|
||||
pub Multisigs: double_map
|
||||
hasher(twox_64_concat) T::AccountId, hasher(blake2_128_concat) [u8; 32]
|
||||
=> Option<Multisig<T::BlockNumber, BalanceOf<T>, T::AccountId>>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ use sc_rpc_api::state::StateClient;
|
||||
/// pub LastActionId: u64;
|
||||
/// pub Voxels: map Loc => Block;
|
||||
/// pub Actions: linked_map u64 => Loc;
|
||||
/// pub Prefab: double_map u128, blake2_256((i8, i8, i8)) => Block;
|
||||
/// pub Prefab: double_map u128, (i8, i8, i8) => Block;
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user