Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit b099875

Browse files
committed
add tests, implement StoragePrefixedMap on types
1 parent fae5be6 commit b099875

File tree

7 files changed

+1038
-85
lines changed

7 files changed

+1038
-85
lines changed

frame/support/procedural/src/pallet/expand/module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn expand_module(def: &mut Def) -> proc_macro2::TokenStream {
4949

5050
quote::quote_spanned!(fn_deposit_event_span =>
5151
impl<#type_impl_gen> Module<#type_use_gen> {
52-
fn deposit_event(event: Event<#event_use_gen>) {
52+
pub fn deposit_event(event: Event<#event_use_gen>) {
5353
let event = <
5454
<T as Trait#trait_use_gen>::Event as
5555
From<Event<#event_use_gen>>

frame/support/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,9 @@ pub mod pallet_prelude {
831831
pub use sp_std::marker::PhantomData;
832832
pub use frame_support::traits::{Get, Instance, ModuleInterface, GenesisBuilder, IsType};
833833
pub use frame_support::dispatch::{DispatchResultWithPostInfo, Parameter};
834+
pub use frame_support::storage::types::*;
835+
pub use frame_support::{EqNoBound, PartialEqNoBound, DebugStripped, DebugNoBound, CloneNoBound};
836+
pub use codec::{Encode, Decode};
834837
pub use sp_inherents::ProvideInherent;
835838
pub use sp_inherents::InherentData;
836839
pub use sp_inherents::InherentIdentifier;
@@ -846,7 +849,6 @@ pub mod pallet_prelude {
846849
UnknownTransaction,
847850
},
848851
};
849-
pub use frame_support::storage::types::*;
850852
pub use crate::{
851853
StorageValue, StorageMap, StorageDoubleMap, StoragePrefixedMap, IterableStorageMap,
852854
IterableStorageDoubleMap,
@@ -1146,6 +1148,7 @@ pub mod pallet_prelude {
11461148
/// // Define the module struct placeholder, various pallet function are implemented on it.
11471149
/// // The macro checks struct generics: is expected `T` or `T, I = DefaultInstance`
11481150
/// #[pallet::module]
1151+
/// #[pallet::generate(fn deposit_event)]
11491152
/// pub struct Module<T>(PhantomData<T>);
11501153
///
11511154
/// // Implement on the module interface on module.

frame/support/src/storage/types.rs

+39
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ where
160160
}
161161
}
162162

163+
impl<Prefix, Hasher, Key, Value, QueryKind, OnEmpty> super::StoragePrefixedMap<Value> for
164+
StorageMapType<Prefix, Hasher, Key, Value, QueryKind, OnEmpty>
165+
where
166+
Prefix: StorageInstance,
167+
Hasher: crate::hash::StorageHasher,
168+
Key: FullEncode,
169+
Value: FullCodec,
170+
QueryKind: QueryKindTrait<Value>,
171+
OnEmpty: crate::traits::Get<QueryKind::Query> + 'static,
172+
{
173+
fn module_prefix() -> &'static [u8] {
174+
<Self as super::generator::StorageMap<Key, Value>>::module_prefix()
175+
}
176+
fn storage_prefix() -> &'static [u8] {
177+
<Self as super::generator::StorageMap<Key, Value>>::storage_prefix()
178+
}
179+
}
180+
163181
/// A type that implements StorageDoubleMap when generics are correctly set:
164182
/// * Prefix must implement StorageInstance, when used inside pallet macro with
165183
/// `#[pallet::storage]` just write `_` the macro will expand with an automatically generated
@@ -210,6 +228,27 @@ where
210228
}
211229
}
212230

231+
impl<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty>
232+
super::StoragePrefixedMap<Value> for
233+
StorageDoubleMapType<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty>
234+
where
235+
Prefix: StorageInstance,
236+
Hasher1: crate::hash::StorageHasher,
237+
Hasher2: crate::hash::StorageHasher,
238+
Key1: FullEncode,
239+
Key2: FullEncode,
240+
Value: FullCodec,
241+
QueryKind: QueryKindTrait<Value>,
242+
OnEmpty: crate::traits::Get<QueryKind::Query> + 'static
243+
{
244+
fn module_prefix() -> &'static [u8] {
245+
<Self as super::generator::StorageDoubleMap<Key1, Key2, Value>>::module_prefix()
246+
}
247+
fn storage_prefix() -> &'static [u8] {
248+
<Self as super::generator::StorageDoubleMap<Key1, Key2, Value>>::storage_prefix()
249+
}
250+
}
251+
213252
/// Part of storage metadata for storage value.
214253
pub trait StorageValueMetadata {
215254
const MODIFIER: StorageEntryModifier;

0 commit comments

Comments
 (0)