mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 02:17:58 +00:00
Enrich metadata with type information (#8615)
* Cargo.lock after merge * Restore scale-info feature * Fully qualify TypeInfo derive * Skip PendingSwap T * Add missing skip_type_params attr * metadata docs features * Reduce pallet event attribute to struct * Cargo.lock * Update frame/balances/src/tests_composite.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Line widths check * Cargo.lock * Add scale-info/std * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Use `skip_type_params` to remove `TypeInfo` requirements on checks * Revert "Remove unused Call metadata stuff" This reverts commit 41311f85 * Skip BalanceSwapAction type parameter * Remove unused event metadata macro * Update frame-metadata * Update primitives/npos-elections/compact/src/codec.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Manual TypeInfo for Header * Remove TypeInfo requirement for consts in BoundedVec etc. * Another TypeInfo bound removed * review: fix indentation * TypeInfo impls for Identity types * Add some todos to add custom TypeInfo impls * Update frame/support/procedural/src/pallet/expand/pallet_struct.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Add some todos to add custom TypeInfo impls * Add a test for manual Data TypeInfo impl * Add custom TypeInfo impl for Vote * Era custom TypeInfo crimes * Revert finality-grandpa version to 0.14.z * review: renamed module to pallet_constants_metadata * New line at end of file * Add missing scale-info/std * Update frame/support/src/storage/types/mod.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Remove StorageEntryType::Map unused flag * Add missing scale-info dependency after merge * SignedExtension::AdditionalSigned metadata * Update frame-metadata, use abbreviated docs and args fields * Update frame/example/Cargo.toml Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * Add scale_info/std and remove unused scale-info dependency * Remove scale-info dependency * Remove treasury pallet::metadata * Remove redundant Event test * Add back scale-info as dev dependency * fix error metadata when no error defined in decl_module * Add Module3 to tests * Fix metadata test * Add docs feature to frame-support test * WIP fixing pallet metadata test * Remove redundant FunctionMetadata, FunctionArgumentMetadata as per https://github.com/paritytech/frame-metadata/pull/20 * Use main branch of frame-metadata * Use patch of scale-info for latest changes * Use latest patched scale-info * Manual TypeInfo for DigestItem * Manual TypeInfo for DigestItem * Update scale-info * Skip __Ignore variants for Error, depends on https://github.com/paritytech/scale-info/pull/117 * Named fields for FRAME v2 pallet Call variants * Named fields for FRAME v1 pallet Call variants * Add missing scale-info dependency * WIP expand benchmark call variant * fix benchmark with new function create a new function for each variant of a pallet call. This function is called by benchmarking macro in order not to break call creation with unnamed argument * fix tests * more fix * Fix staking tests * Fix offchain workers calls * Cherry pick rustfmt.toml from master * cargo +nightly-2021-06-22 fmt --all * Update to new call variant structs * More call variant struct updates * Remove unused import * More call variant structs * More call variant structs * Even more call variant structs * Mooar variant structs * Evermore variant structs * Call variant structs ad infinitum * Fmt * More call variants * Last call variant * Call variants all done? * Fix SS58Prefix type * Potential workaround for BitFlags<IdentityFields> TypeInfo * Enable docs capturing for Call, Event, and Error types * Fix IdentityFields TypeInfo * Remove metadata-docs feature * Add capture_docs = true for legacy Call, Event and Error types * Fmt * Fix metadata test type * Update benchmarks with call struct variants * Fmt * More test fixes * Fmt * Fix benches * Use latest capture_docs attr * Latest scale_info * Fmt * review: change &Vec to &[] * Remove pallet metadata attr * review: remove commented out test code * review: skip_type_params trailing comma suggestion * Update to scale-info 0.10.0 * Update construct_runtime ui tests, different because of metadata TypeInfo impls * Add some TypeInfo derives for UI tests * Update storage ensure span ui stderrs * Update call argument bound ui tests Possibly changed because change from tuple to struct variants? * Add scale-info dev dependency * Update to latest finality-grandpa release * review: missing newline * review: missing scale-info/std * review: remove duplicate scale-info/std * review: remove fully qualified TypeInfo * review: add missing scale-info/std * review: remove unnecessary imports. * Fmt * Use crates.io RC version of frame-metadata * Remove scale-info/std because it is a dev dependency * Add missing scale_info dev-dependency for test * Delete empty metadata folder * Fix sp_std import * review: improve manual UncheckedExtrinsic TypeInfo impl * review: use full scale-info for dev-dependency * Remove DefaultByteGetter impl * review: derive TypeInfo for generic header * Fmt * Update primitives/runtime/src/generic/unchecked_extrinsic.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * Update primitives/runtime/src/generic/unchecked_extrinsic.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * Update bin/node/executor/Cargo.toml Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update frame/identity/src/types.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update frame/support/src/dispatch.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Remove redundant derive * Simplify scale-info dependency * Strip underscore prefix from call variant struct names * Another underscore field * More underscore fields * Another underscore field * Update to frame-metadata 14.0.0-rc.2 with combined StorageEntryType::Map * Fmt * Revert weights formatting * Fix up some tests * Fix up some tests for StorageEntryTypeMetadata * scale-info dev dependency * Fix test error * Add missing TypeInfo derives * Add back missing scale-info dependency * Add back missing scale-info dependency * Fix npos compact impls * Cargo.lock * Fmt * Fix errors * Fmt * Fix renamed raw_solution field * Fix error * Fmt * Fix some benchmarks * Fmt * Stray R * Fix * Add missing TypeInfos * ui test fix * Fix line widths * Revert "ui test fix" This reverts commit 2d15ec058a216e3f92d713f1174603a2bb1eac65. * Upgrade to scale-info 0.11.0 * Revert "Upgrade to scale-info 0.11.0" This reverts commit 047bb179085a0059c36cd20ab405f55cf0867e28. * Add Runtime type * Update to scale-info 0.12 * Update to scale-info 1.0 * Update frame-metadata to version 14.0.0 * Patch finality-grandpa until release available * Fix metadata tests * Fix metadata tests * Fmt * Remove patched finality-grandpa * Fix tests, use scale_info imports * Fix pallet tests * Add BlockNumber TypeInfo bound * ui test fix * Cargo.lock * Remove pallet metadata * Cargo.lock * Add missing scale-info dependency * Remove pallet event metadata * Fix error * Fix collective errors * Semicolol * Fmt * Remove another metadata attribute * Add new variant to custom digest TypeInfo * Fmt * Cargo.lock from master * Remove comma lol * Fix example call error * Fix example call error properly Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -15,7 +15,8 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dependencies]
|
||||
serde = { version = "1.0.126", optional = true, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive", "max-encoded-len"] }
|
||||
frame-metadata = { version = "14.0.0-dev", default-features = false, path = "../metadata" }
|
||||
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
|
||||
frame-metadata = { version = "14.0.0", default-features = false, features = ["v14"] }
|
||||
sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" }
|
||||
sp-io = { version = "4.0.0-dev", default-features = false, path = "../../primitives/io" }
|
||||
sp-runtime = { version = "4.0.0-dev", default-features = false, path = "../../primitives/runtime" }
|
||||
@@ -34,6 +35,7 @@ smallvec = "1.4.1"
|
||||
log = { version = "0.4.14", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.3.0"
|
||||
pretty_assertions = "0.6.1"
|
||||
frame-system = { version = "4.0.0-dev", path = "../system" }
|
||||
parity-util-mem = { version = "0.10.0", default-features = false, features = ["primitive-types"] }
|
||||
@@ -45,6 +47,7 @@ std = [
|
||||
"serde",
|
||||
"sp-io/std",
|
||||
"codec/std",
|
||||
"scale-info/std",
|
||||
"sp-std/std",
|
||||
"sp-runtime/std",
|
||||
"sp-tracing/std",
|
||||
|
||||
@@ -54,6 +54,7 @@ pub fn expand_outer_dispatch(
|
||||
Clone, PartialEq, Eq,
|
||||
#scrate::codec::Encode,
|
||||
#scrate::codec::Decode,
|
||||
#scrate::scale_info::TypeInfo,
|
||||
#scrate::RuntimeDebug,
|
||||
)]
|
||||
pub enum Call {
|
||||
|
||||
@@ -75,6 +75,7 @@ pub fn expand_outer_event(
|
||||
Clone, PartialEq, Eq,
|
||||
#scrate::codec::Encode,
|
||||
#scrate::codec::Decode,
|
||||
#scrate::scale_info::TypeInfo,
|
||||
#scrate::RuntimeDebug,
|
||||
)]
|
||||
#[allow(non_camel_case_types)]
|
||||
|
||||
@@ -26,7 +26,7 @@ pub fn expand_runtime_metadata(
|
||||
scrate: &TokenStream,
|
||||
extrinsic: &TypePath,
|
||||
) -> TokenStream {
|
||||
let modules = pallet_declarations
|
||||
let pallets = pallet_declarations
|
||||
.iter()
|
||||
.filter_map(|pallet_declaration| {
|
||||
pallet_declaration.find_part("Pallet").map(|_| {
|
||||
@@ -42,21 +42,21 @@ pub fn expand_runtime_metadata(
|
||||
.map(|(decl, filtered_names)| {
|
||||
let name = &decl.name;
|
||||
let index = &decl.index;
|
||||
let storage = expand_pallet_metadata_storage(&filtered_names, runtime, scrate, decl);
|
||||
let calls = expand_pallet_metadata_calls(&filtered_names, runtime, scrate, decl);
|
||||
let storage = expand_pallet_metadata_storage(&filtered_names, runtime, decl);
|
||||
let calls = expand_pallet_metadata_calls(&filtered_names, runtime, decl);
|
||||
let event = expand_pallet_metadata_events(&filtered_names, runtime, scrate, decl);
|
||||
let constants = expand_pallet_metadata_constants(runtime, scrate, decl);
|
||||
let errors = expand_pallet_metadata_errors(runtime, scrate, decl);
|
||||
let constants = expand_pallet_metadata_constants(runtime, decl);
|
||||
let errors = expand_pallet_metadata_errors(runtime, decl);
|
||||
|
||||
quote! {
|
||||
#scrate::metadata::ModuleMetadata {
|
||||
name: #scrate::metadata::DecodeDifferent::Encode(stringify!(#name)),
|
||||
#scrate::metadata::PalletMetadata {
|
||||
name: stringify!(#name),
|
||||
index: #index,
|
||||
storage: #storage,
|
||||
calls: #calls,
|
||||
event: #event,
|
||||
constants: #constants,
|
||||
errors: #errors,
|
||||
error: #errors,
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -65,20 +65,26 @@ pub fn expand_runtime_metadata(
|
||||
quote! {
|
||||
impl #runtime {
|
||||
pub fn metadata() -> #scrate::metadata::RuntimeMetadataPrefixed {
|
||||
#scrate::metadata::RuntimeMetadataLastVersion {
|
||||
modules: #scrate::metadata::DecodeDifferent::Encode(&[ #(#modules),* ]),
|
||||
extrinsic: #scrate::metadata::ExtrinsicMetadata {
|
||||
#scrate::metadata::RuntimeMetadataLastVersion::new(
|
||||
#scrate::sp_std::vec![ #(#pallets),* ],
|
||||
#scrate::metadata::ExtrinsicMetadata {
|
||||
ty: #scrate::scale_info::meta_type::<#extrinsic>(),
|
||||
version: <#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata>::VERSION,
|
||||
signed_extensions: <
|
||||
<
|
||||
#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata
|
||||
>::SignedExtensions as #scrate::sp_runtime::traits::SignedExtension
|
||||
>::identifier()
|
||||
>::metadata()
|
||||
.into_iter()
|
||||
.map(#scrate::metadata::DecodeDifferent::Encode)
|
||||
.map(|meta| #scrate::metadata::SignedExtensionMetadata {
|
||||
identifier: meta.identifier,
|
||||
ty: meta.ty,
|
||||
additional_signed: meta.additional_signed,
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
}.into()
|
||||
#scrate::scale_info::meta_type::<#runtime>()
|
||||
).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,7 +93,6 @@ pub fn expand_runtime_metadata(
|
||||
fn expand_pallet_metadata_storage(
|
||||
filtered_names: &[&'static str],
|
||||
runtime: &Ident,
|
||||
scrate: &TokenStream,
|
||||
decl: &Pallet,
|
||||
) -> TokenStream {
|
||||
if filtered_names.contains(&"Storage") {
|
||||
@@ -95,11 +100,7 @@ fn expand_pallet_metadata_storage(
|
||||
let path = &decl.path;
|
||||
|
||||
quote! {
|
||||
Some(#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::storage_metadata
|
||||
)
|
||||
))
|
||||
Some(#path::Pallet::<#runtime #(, #path::#instance)*>::storage_metadata())
|
||||
}
|
||||
} else {
|
||||
quote!(None)
|
||||
@@ -109,7 +110,6 @@ fn expand_pallet_metadata_storage(
|
||||
fn expand_pallet_metadata_calls(
|
||||
filtered_names: &[&'static str],
|
||||
runtime: &Ident,
|
||||
scrate: &TokenStream,
|
||||
decl: &Pallet,
|
||||
) -> TokenStream {
|
||||
if filtered_names.contains(&"Call") {
|
||||
@@ -117,11 +117,7 @@ fn expand_pallet_metadata_calls(
|
||||
let path = &decl.path;
|
||||
|
||||
quote! {
|
||||
Some(#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::call_functions
|
||||
)
|
||||
))
|
||||
Some(#path::Pallet::<#runtime #(, #path::#instance)*>::call_functions())
|
||||
}
|
||||
} else {
|
||||
quote!(None)
|
||||
@@ -150,45 +146,31 @@ fn expand_pallet_metadata_events(
|
||||
};
|
||||
|
||||
quote! {
|
||||
Some(#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(#pallet_event::metadata)
|
||||
))
|
||||
Some(
|
||||
#scrate::metadata::PalletEventMetadata {
|
||||
ty: #scrate::scale_info::meta_type::<#pallet_event>()
|
||||
}
|
||||
)
|
||||
}
|
||||
} else {
|
||||
quote!(None)
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_pallet_metadata_constants(
|
||||
runtime: &Ident,
|
||||
scrate: &TokenStream,
|
||||
decl: &Pallet,
|
||||
) -> TokenStream {
|
||||
fn expand_pallet_metadata_constants(runtime: &Ident, decl: &Pallet) -> TokenStream {
|
||||
let path = &decl.path;
|
||||
let instance = decl.instance.as_ref().into_iter();
|
||||
|
||||
quote! {
|
||||
#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::module_constants_metadata
|
||||
)
|
||||
)
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::pallet_constants_metadata()
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_pallet_metadata_errors(
|
||||
runtime: &Ident,
|
||||
scrate: &TokenStream,
|
||||
decl: &Pallet,
|
||||
) -> TokenStream {
|
||||
fn expand_pallet_metadata_errors(runtime: &Ident, decl: &Pallet) -> TokenStream {
|
||||
let path = &decl.path;
|
||||
let instance = decl.instance.as_ref().into_iter();
|
||||
|
||||
quote! {
|
||||
#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(
|
||||
<#path::Pallet::<#runtime #(, #path::#instance)*> as #scrate::metadata::ModuleErrorMetadata>::metadata
|
||||
)
|
||||
)
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::error_metadata()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,10 @@ pub fn expand_outer_origin(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, #scrate::RuntimeDebug, #scrate::codec::Encode, #scrate::codec::Decode)]
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq, #scrate::RuntimeDebug, #scrate::codec::Encode,
|
||||
#scrate::codec::Decode, #scrate::scale_info::TypeInfo,
|
||||
)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum OriginCaller {
|
||||
#[codec(index = #system_index)]
|
||||
|
||||
@@ -151,7 +151,10 @@ fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream
|
||||
type __hidden_use_of_unchecked_extrinsic = #unchecked_extrinsic;
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, #scrate::sp_runtime::RuntimeDebug)]
|
||||
#[derive(
|
||||
Clone, Copy, PartialEq, Eq, #scrate::sp_runtime::RuntimeDebug,
|
||||
#scrate::scale_info::TypeInfo
|
||||
)]
|
||||
pub struct #name;
|
||||
impl #scrate::sp_runtime::traits::GetNodeBlockType for #name {
|
||||
type NodeBlock = #node_block;
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn impl_key_prefix_for_tuples(input: proc_macro::TokenStream) -> Result<Toke
|
||||
|
||||
let trait_impls = quote! {
|
||||
impl<
|
||||
#(#current_tuple: FullCodec,)*
|
||||
#(#current_tuple: FullCodec + StaticTypeInfo,)*
|
||||
#(#hashers: StorageHasher,)*
|
||||
#(#kargs: EncodeLike<#prefixes>),*
|
||||
> HasKeyPrefix<( #( #kargs, )* )> for ( #( Key<#hashers, #current_tuple>, )* ) {
|
||||
@@ -60,7 +60,7 @@ pub fn impl_key_prefix_for_tuples(input: proc_macro::TokenStream) -> Result<Toke
|
||||
}
|
||||
|
||||
impl<
|
||||
#(#current_tuple: FullCodec,)*
|
||||
#(#current_tuple: FullCodec + StaticTypeInfo,)*
|
||||
#(#hashers: ReversibleStorageHasher,)*
|
||||
#(#kargs: EncodeLike<#prefixes>),*
|
||||
> HasReversibleKeyPrefix<( #( #kargs, )* )> for ( #( Key<#hashers, #current_tuple>, )* ) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{pallet::Def, COUNTER};
|
||||
use frame_support_procedural_tools::clean_type_string;
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
///
|
||||
@@ -43,6 +42,15 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
let pallet_ident = &def.pallet_struct.pallet;
|
||||
|
||||
let fn_name = methods.iter().map(|method| &method.name).collect::<Vec<_>>();
|
||||
let new_call_variant_fn_name = fn_name
|
||||
.iter()
|
||||
.map(|fn_name| quote::format_ident!("new_call_variant_{}", fn_name))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let new_call_variant_doc = fn_name
|
||||
.iter()
|
||||
.map(|fn_name| format!("Create a call with the variant `{}`.", fn_name))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let fn_weight = methods.iter().map(|method| &method.weight);
|
||||
|
||||
@@ -53,6 +61,42 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
.map(|method| method.args.iter().map(|(_, name, _)| name.clone()).collect::<Vec<_>>())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let args_name_stripped = methods
|
||||
.iter()
|
||||
.map(|method| {
|
||||
method
|
||||
.args
|
||||
.iter()
|
||||
.map(|(_, name, _)| {
|
||||
syn::Ident::new(&name.to_string().trim_start_matches('_'), name.span())
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let make_args_name_pattern = |ref_tok| {
|
||||
args_name
|
||||
.iter()
|
||||
.zip(args_name_stripped.iter())
|
||||
.map(|(args_name, args_name_stripped)| {
|
||||
args_name
|
||||
.iter()
|
||||
.zip(args_name_stripped)
|
||||
.map(|(args_name, args_name_stripped)| {
|
||||
if args_name == args_name_stripped {
|
||||
quote::quote!( #ref_tok #args_name )
|
||||
} else {
|
||||
quote::quote!( #args_name_stripped: #ref_tok #args_name )
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
let args_name_pattern = make_args_name_pattern(None);
|
||||
let args_name_pattern_ref = make_args_name_pattern(Some(quote::quote!(ref)));
|
||||
|
||||
let args_type = methods
|
||||
.iter()
|
||||
.map(|method| method.args.iter().map(|(_, _, type_)| type_.clone()).collect::<Vec<_>>())
|
||||
@@ -72,21 +116,6 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
|
||||
let args_metadata_type = methods.iter().map(|method| {
|
||||
method
|
||||
.args
|
||||
.iter()
|
||||
.map(|(is_compact, _, type_)| {
|
||||
let final_type = if *is_compact {
|
||||
quote::quote_spanned!(type_.span() => Compact<#type_>)
|
||||
} else {
|
||||
quote::quote!(#type_)
|
||||
};
|
||||
clean_type_string(&final_type.to_string())
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
|
||||
let default_docs = [syn::parse_quote!(
|
||||
r"Contains one variant per dispatchable that can be called by an extrinsic."
|
||||
)];
|
||||
@@ -131,9 +160,11 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
#frame_support::PartialEqNoBound,
|
||||
#frame_support::codec::Encode,
|
||||
#frame_support::codec::Decode,
|
||||
#frame_support::scale_info::TypeInfo,
|
||||
)]
|
||||
#[codec(encode_bound())]
|
||||
#[codec(decode_bound())]
|
||||
#[scale_info(skip_type_params(#type_use_gen), capture_docs = "always")]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum #call_ident<#type_decl_bounded_gen> #where_clause {
|
||||
#[doc(hidden)]
|
||||
@@ -142,7 +173,25 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
#frame_support::sp_std::marker::PhantomData<(#type_use_gen,)>,
|
||||
#frame_support::Never,
|
||||
),
|
||||
#( #( #[doc = #fn_doc] )* #fn_name( #( #args_compact_attr #args_type ),* ), )*
|
||||
#(
|
||||
#( #[doc = #fn_doc] )*
|
||||
#fn_name {
|
||||
#( #args_compact_attr #args_name_stripped: #args_type ),*
|
||||
},
|
||||
)*
|
||||
}
|
||||
|
||||
impl<#type_impl_gen> #call_ident<#type_use_gen> #where_clause {
|
||||
#(
|
||||
#[doc = #new_call_variant_doc]
|
||||
pub fn #new_call_variant_fn_name(
|
||||
#( #args_name_stripped: #args_type ),*
|
||||
) -> Self {
|
||||
Self::#fn_name {
|
||||
#( #args_name_stripped ),*
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
||||
impl<#type_impl_gen> #frame_support::dispatch::GetDispatchInfo
|
||||
@@ -152,7 +201,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
fn get_dispatch_info(&self) -> #frame_support::dispatch::DispatchInfo {
|
||||
match *self {
|
||||
#(
|
||||
Self::#fn_name ( #( ref #args_name, )* ) => {
|
||||
Self::#fn_name { #( #args_name_pattern_ref, )* } => {
|
||||
let __pallet_base_weight = #fn_weight;
|
||||
|
||||
let __pallet_weight = <
|
||||
@@ -186,7 +235,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
{
|
||||
fn get_call_name(&self) -> &'static str {
|
||||
match *self {
|
||||
#( Self::#fn_name(..) => stringify!(#fn_name), )*
|
||||
#( Self::#fn_name { .. } => stringify!(#fn_name), )*
|
||||
Self::__Ignore(_, _) => unreachable!("__PhantomItem cannot be used."),
|
||||
}
|
||||
}
|
||||
@@ -207,7 +256,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
) -> #frame_support::dispatch::DispatchResultWithPostInfo {
|
||||
match self {
|
||||
#(
|
||||
Self::#fn_name( #( #args_name, )* ) => {
|
||||
Self::#fn_name { #( #args_name_pattern, )* } => {
|
||||
#frame_support::sp_tracing::enter_span!(
|
||||
#frame_support::sp_tracing::trace_span!(stringify!(#fn_name))
|
||||
);
|
||||
@@ -231,30 +280,8 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
|
||||
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #where_clause {
|
||||
#[doc(hidden)]
|
||||
#[allow(dead_code)]
|
||||
pub fn call_functions() -> &'static [#frame_support::dispatch::FunctionMetadata] {
|
||||
&[ #(
|
||||
#frame_support::dispatch::FunctionMetadata {
|
||||
name: #frame_support::dispatch::DecodeDifferent::Encode(
|
||||
stringify!(#fn_name)
|
||||
),
|
||||
arguments: #frame_support::dispatch::DecodeDifferent::Encode(
|
||||
&[ #(
|
||||
#frame_support::dispatch::FunctionArgumentMetadata {
|
||||
name: #frame_support::dispatch::DecodeDifferent::Encode(
|
||||
stringify!(#args_name)
|
||||
),
|
||||
ty: #frame_support::dispatch::DecodeDifferent::Encode(
|
||||
#args_metadata_type
|
||||
),
|
||||
},
|
||||
)* ]
|
||||
),
|
||||
documentation: #frame_support::dispatch::DecodeDifferent::Encode(
|
||||
&[ #( #fn_doc ),* ]
|
||||
),
|
||||
},
|
||||
)* ]
|
||||
pub fn call_functions() -> #frame_support::metadata::PalletCallMetadata {
|
||||
#frame_support::scale_info::meta_type::<#call_ident<#type_use_gen>>().into()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::pallet::{parse::helper::get_doc_literals, Def};
|
||||
use crate::pallet::Def;
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
|
||||
///
|
||||
/// * Generate default rust doc
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::pallet::Def;
|
||||
use frame_support_procedural_tools::clean_type_string;
|
||||
use quote::ToTokens;
|
||||
|
||||
struct ConstDef {
|
||||
/// Name of the associated type.
|
||||
@@ -35,7 +33,6 @@ struct ConstDef {
|
||||
pub fn expand_constants(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
let frame_support = &def.frame_support;
|
||||
let type_impl_gen = &def.type_impl_generics(proc_macro2::Span::call_site());
|
||||
let type_decl_gen = &def.type_decl_generics(proc_macro2::Span::call_site());
|
||||
let type_use_gen = &def.type_use_generics(proc_macro2::Span::call_site());
|
||||
let pallet_ident = &def.pallet_struct.pallet;
|
||||
|
||||
@@ -74,50 +71,17 @@ pub fn expand_constants(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
|
||||
let consts = config_consts.chain(extra_consts).map(|const_| {
|
||||
let const_type = &const_.type_;
|
||||
let const_type_str = clean_type_string(&const_type.to_token_stream().to_string());
|
||||
let ident = &const_.ident;
|
||||
let ident_str = format!("{}", ident);
|
||||
let doc = const_.doc.clone().into_iter();
|
||||
let default_byte_impl = &const_.default_byte_impl;
|
||||
let default_byte_getter =
|
||||
syn::Ident::new(&format!("{}DefaultByteGetter", ident), ident.span());
|
||||
|
||||
quote::quote!({
|
||||
#[allow(non_upper_case_types)]
|
||||
#[allow(non_camel_case_types)]
|
||||
struct #default_byte_getter<#type_decl_gen>(
|
||||
#frame_support::sp_std::marker::PhantomData<(#type_use_gen)>
|
||||
);
|
||||
|
||||
impl<#type_impl_gen> #frame_support::dispatch::DefaultByte for
|
||||
#default_byte_getter<#type_use_gen>
|
||||
#completed_where_clause
|
||||
{
|
||||
fn default_byte(&self) -> #frame_support::sp_std::vec::Vec<u8> {
|
||||
#default_byte_impl
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<#type_impl_gen> Send for #default_byte_getter<#type_use_gen>
|
||||
#completed_where_clause
|
||||
{}
|
||||
unsafe impl<#type_impl_gen> Sync for #default_byte_getter<#type_use_gen>
|
||||
#completed_where_clause
|
||||
{}
|
||||
|
||||
#frame_support::dispatch::ModuleConstantMetadata {
|
||||
name: #frame_support::dispatch::DecodeDifferent::Encode(#ident_str),
|
||||
ty: #frame_support::dispatch::DecodeDifferent::Encode(#const_type_str),
|
||||
value: #frame_support::dispatch::DecodeDifferent::Encode(
|
||||
#frame_support::dispatch::DefaultByteGetter(
|
||||
&#default_byte_getter::<#type_use_gen>(
|
||||
#frame_support::sp_std::marker::PhantomData
|
||||
)
|
||||
)
|
||||
),
|
||||
documentation: #frame_support::dispatch::DecodeDifferent::Encode(
|
||||
&[ #( #doc ),* ]
|
||||
),
|
||||
#frame_support::metadata::PalletConstantMetadata {
|
||||
name: #ident_str,
|
||||
ty: #frame_support::scale_info::meta_type::<#const_type>(),
|
||||
value: { #default_byte_impl },
|
||||
docs: #frame_support::sp_std::vec![ #( #doc ),* ],
|
||||
}
|
||||
})
|
||||
});
|
||||
@@ -126,10 +90,10 @@ pub fn expand_constants(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause{
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn module_constants_metadata()
|
||||
-> &'static [#frame_support::dispatch::ModuleConstantMetadata]
|
||||
pub fn pallet_constants_metadata()
|
||||
-> #frame_support::sp_std::vec::Vec<#frame_support::metadata::PalletConstantMetadata>
|
||||
{
|
||||
&[ #( #consts ),* ]
|
||||
#frame_support::sp_std::vec![ #( #consts ),* ]
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::pallet::{parse::helper::get_doc_literals, Def};
|
||||
use crate::pallet::Def;
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
|
||||
///
|
||||
/// * impl various trait on Error
|
||||
/// * impl ModuleErrorMetadata for Error
|
||||
pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
let error = if let Some(error) = &def.error { error } else { return Default::default() };
|
||||
|
||||
@@ -32,6 +32,7 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
|
||||
let phantom_variant: syn::Variant = syn::parse_quote!(
|
||||
#[doc(hidden)]
|
||||
#[codec(skip)]
|
||||
__Ignore(
|
||||
#frame_support::sp_std::marker::PhantomData<(#type_use_gen)>,
|
||||
#frame_support::Never,
|
||||
@@ -47,16 +48,6 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
quote::quote_spanned!(error.attr_span => Self::#variant => #variant_str,)
|
||||
});
|
||||
|
||||
let metadata = error.variants.iter().map(|(variant, doc)| {
|
||||
let variant_str = format!("{}", variant);
|
||||
quote::quote_spanned!(error.attr_span =>
|
||||
#frame_support::error::ErrorMetadata {
|
||||
name: #frame_support::error::DecodeDifferent::Encode(#variant_str),
|
||||
documentation: #frame_support::error::DecodeDifferent::Encode(&[ #( #doc, )* ]),
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
let error_item = {
|
||||
let item = &mut def.item.content.as_mut().expect("Checked by def parser").1[error.index];
|
||||
if let syn::Item::Enum(item) = item {
|
||||
@@ -67,6 +58,13 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
};
|
||||
|
||||
error_item.variants.insert(0, phantom_variant);
|
||||
// derive TypeInfo for error metadata
|
||||
error_item
|
||||
.attrs
|
||||
.push(syn::parse_quote!( #[derive(#frame_support::scale_info::TypeInfo)] ));
|
||||
error_item.attrs.push(syn::parse_quote!(
|
||||
#[scale_info(skip_type_params(#type_use_gen), capture_docs = "always")]
|
||||
));
|
||||
|
||||
if get_doc_literals(&error_item.attrs).is_empty() {
|
||||
error_item.attrs.push(syn::parse_quote!(
|
||||
@@ -130,14 +128,5 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<#type_impl_gen> #frame_support::error::ModuleErrorMetadata
|
||||
for #error_ident<#type_use_gen>
|
||||
#config_where_clause
|
||||
{
|
||||
fn metadata() -> &'static [#frame_support::error::ErrorMetadata] {
|
||||
&[ #( #metadata )* ]
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{
|
||||
pallet::{parse::helper::get_doc_literals, Def},
|
||||
pallet::{parse::event::PalletEventDepositAttr, Def},
|
||||
COUNTER,
|
||||
};
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use syn::{spanned::Spanned, Ident};
|
||||
|
||||
///
|
||||
@@ -69,20 +70,6 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
let frame_support = &def.frame_support;
|
||||
let event_use_gen = &event.gen_kind.type_use_gen(event.attr_span);
|
||||
let event_impl_gen = &event.gen_kind.type_impl_gen(event.attr_span);
|
||||
let metadata = event.metadata.iter().map(|(ident, args, docs)| {
|
||||
let name = format!("{}", ident);
|
||||
quote::quote_spanned!(event.attr_span =>
|
||||
#frame_support::event::EventMetadata {
|
||||
name: #frame_support::event::DecodeDifferent::Encode(#name),
|
||||
arguments: #frame_support::event::DecodeDifferent::Encode(&[
|
||||
#( #args, )*
|
||||
]),
|
||||
documentation: #frame_support::event::DecodeDifferent::Encode(&[
|
||||
#( #docs, )*
|
||||
]),
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
let event_item = {
|
||||
let item = &mut def.item.content.as_mut().expect("Checked by def parser").1[event.index];
|
||||
@@ -126,15 +113,23 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
#frame_support::RuntimeDebugNoBound,
|
||||
#frame_support::codec::Encode,
|
||||
#frame_support::codec::Decode,
|
||||
#frame_support::scale_info::TypeInfo,
|
||||
)]
|
||||
));
|
||||
|
||||
let deposit_event = if let Some((fn_vis, fn_span)) = &event.deposit_event {
|
||||
// skip requirement for type params to implement `TypeInfo`, and require docs capture
|
||||
event_item.attrs.push(syn::parse_quote!(
|
||||
#[scale_info(skip_type_params(#event_use_gen), capture_docs = "always")]
|
||||
));
|
||||
|
||||
let deposit_event = if let Some(deposit_event) = &event.deposit_event {
|
||||
let event_use_gen = &event.gen_kind.type_use_gen(event.attr_span);
|
||||
let trait_use_gen = &def.trait_use_generics(event.attr_span);
|
||||
let type_impl_gen = &def.type_impl_generics(event.attr_span);
|
||||
let type_use_gen = &def.type_use_generics(event.attr_span);
|
||||
|
||||
let PalletEventDepositAttr { fn_vis, fn_span, .. } = deposit_event;
|
||||
|
||||
quote::quote_spanned!(*fn_span =>
|
||||
impl<#type_impl_gen> Pallet<#type_use_gen> #completed_where_clause {
|
||||
#fn_vis fn deposit_event(event: Event<#event_use_gen>) {
|
||||
@@ -174,13 +169,5 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
impl<#event_impl_gen> From<#event_ident<#event_use_gen>> for () #event_where_clause {
|
||||
fn from(_: #event_ident<#event_use_gen>) {}
|
||||
}
|
||||
|
||||
impl<#event_impl_gen> #event_ident<#event_use_gen> #event_where_clause {
|
||||
#[allow(dead_code)]
|
||||
#[doc(hidden)]
|
||||
pub fn metadata() -> &'static [#frame_support::event::EventMetadata] {
|
||||
&[ #( #metadata )* ]
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{
|
||||
pallet::{parse::helper::get_doc_literals, Def},
|
||||
COUNTER,
|
||||
};
|
||||
use crate::{pallet::Def, COUNTER};
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use syn::{spanned::Spanned, Ident};
|
||||
|
||||
///
|
||||
|
||||
@@ -32,7 +32,8 @@ mod store_trait;
|
||||
mod type_value;
|
||||
mod validate_unsigned;
|
||||
|
||||
use crate::pallet::{parse::helper::get_doc_literals, Def};
|
||||
use crate::pallet::Def;
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use quote::ToTokens;
|
||||
|
||||
/// Merge where clause together, `where` token span is taken from the first not none one.
|
||||
|
||||
@@ -15,13 +15,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::pallet::{expand::merge_where_clauses, parse::helper::get_doc_literals, Def};
|
||||
use crate::pallet::{expand::merge_where_clauses, Def};
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
|
||||
///
|
||||
/// * Add derive trait on Pallet
|
||||
/// * Implement GetStorageVersion on Pallet
|
||||
/// * Implement OnGenesis on Pallet
|
||||
/// * Implement ModuleErrorMetadata on Pallet
|
||||
/// * Implement `fn error_metadata` on Pallet
|
||||
/// * declare Module type alias for construct_runtime
|
||||
/// * replace the first field type of `struct Pallet` with `PhantomData` if it is `_`
|
||||
/// * implementation of `PalletInfoAccess` information
|
||||
@@ -76,28 +77,22 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
)]
|
||||
));
|
||||
|
||||
let module_error_metadata = if let Some(error_def) = &def.error {
|
||||
let pallet_error_metadata = if let Some(error_def) = &def.error {
|
||||
let error_ident = &error_def.error;
|
||||
quote::quote_spanned!(def.pallet_struct.attr_span =>
|
||||
impl<#type_impl_gen> #frame_support::error::ModuleErrorMetadata
|
||||
for #pallet_ident<#type_use_gen>
|
||||
#config_where_clause
|
||||
{
|
||||
fn metadata() -> &'static [#frame_support::error::ErrorMetadata] {
|
||||
<
|
||||
#error_ident<#type_use_gen> as #frame_support::error::ModuleErrorMetadata
|
||||
>::metadata()
|
||||
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #config_where_clause {
|
||||
pub fn error_metadata() -> Option<#frame_support::metadata::PalletErrorMetadata> {
|
||||
Some(#frame_support::metadata::PalletErrorMetadata {
|
||||
ty: #frame_support::scale_info::meta_type::<#error_ident<#type_use_gen>>()
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
quote::quote_spanned!(def.pallet_struct.attr_span =>
|
||||
impl<#type_impl_gen> #frame_support::error::ModuleErrorMetadata
|
||||
for #pallet_ident<#type_use_gen>
|
||||
#config_where_clause
|
||||
{
|
||||
fn metadata() -> &'static [#frame_support::error::ErrorMetadata] {
|
||||
&[]
|
||||
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #config_where_clause {
|
||||
pub fn error_metadata() -> Option<#frame_support::metadata::PalletErrorMetadata> {
|
||||
None
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -159,7 +154,7 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
};
|
||||
|
||||
quote::quote_spanned!(def.pallet_struct.attr_span =>
|
||||
#module_error_metadata
|
||||
#pallet_error_metadata
|
||||
|
||||
/// Type alias to `Pallet`, to be used by `construct_runtime`.
|
||||
///
|
||||
|
||||
@@ -19,7 +19,6 @@ use crate::pallet::{
|
||||
parse::storage::{Metadata, QueryKind, StorageDef, StorageGenerics},
|
||||
Def,
|
||||
};
|
||||
use frame_support_procedural_tools::clean_type_string;
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// Generate the prefix_ident related the the storage.
|
||||
@@ -176,89 +175,15 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
|
||||
let cfg_attrs = &storage.cfg_attrs;
|
||||
|
||||
let metadata_trait = match &storage.metadata {
|
||||
Metadata::Value { .. } => quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::storage::types::StorageValueMetadata
|
||||
),
|
||||
Metadata::Map { .. } => quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::storage::types::StorageMapMetadata
|
||||
),
|
||||
Metadata::DoubleMap { .. } => quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::storage::types::StorageDoubleMapMetadata
|
||||
),
|
||||
Metadata::NMap { .. } => quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::storage::types::StorageNMapMetadata
|
||||
),
|
||||
};
|
||||
|
||||
let ty = match &storage.metadata {
|
||||
Metadata::Value { value } => {
|
||||
let value = clean_type_string("e::quote!(#value).to_string());
|
||||
quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::metadata::StorageEntryType::Plain(
|
||||
#frame_support::metadata::DecodeDifferent::Encode(#value)
|
||||
)
|
||||
)
|
||||
},
|
||||
Metadata::Map { key, value } => {
|
||||
let value = clean_type_string("e::quote!(#value).to_string());
|
||||
let key = clean_type_string("e::quote!(#key).to_string());
|
||||
quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::metadata::StorageEntryType::Map {
|
||||
hasher: <#full_ident as #metadata_trait>::HASHER,
|
||||
key: #frame_support::metadata::DecodeDifferent::Encode(#key),
|
||||
value: #frame_support::metadata::DecodeDifferent::Encode(#value),
|
||||
unused: false,
|
||||
}
|
||||
)
|
||||
},
|
||||
Metadata::DoubleMap { key1, key2, value } => {
|
||||
let value = clean_type_string("e::quote!(#value).to_string());
|
||||
let key1 = clean_type_string("e::quote!(#key1).to_string());
|
||||
let key2 = clean_type_string("e::quote!(#key2).to_string());
|
||||
quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::metadata::StorageEntryType::DoubleMap {
|
||||
hasher: <#full_ident as #metadata_trait>::HASHER1,
|
||||
key2_hasher: <#full_ident as #metadata_trait>::HASHER2,
|
||||
key1: #frame_support::metadata::DecodeDifferent::Encode(#key1),
|
||||
key2: #frame_support::metadata::DecodeDifferent::Encode(#key2),
|
||||
value: #frame_support::metadata::DecodeDifferent::Encode(#value),
|
||||
}
|
||||
)
|
||||
},
|
||||
Metadata::NMap { keys, value, .. } => {
|
||||
let keys = keys
|
||||
.iter()
|
||||
.map(|key| clean_type_string("e::quote!(#key).to_string()))
|
||||
.collect::<Vec<_>>();
|
||||
let value = clean_type_string("e::quote!(#value).to_string());
|
||||
quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::metadata::StorageEntryType::NMap {
|
||||
keys: #frame_support::metadata::DecodeDifferent::Encode(&[
|
||||
#( #keys, )*
|
||||
]),
|
||||
hashers: #frame_support::metadata::DecodeDifferent::Encode(
|
||||
<#full_ident as #metadata_trait>::HASHERS,
|
||||
),
|
||||
value: #frame_support::metadata::DecodeDifferent::Encode(#value),
|
||||
}
|
||||
)
|
||||
},
|
||||
};
|
||||
|
||||
quote::quote_spanned!(storage.attr_span =>
|
||||
#(#cfg_attrs)* #frame_support::metadata::StorageEntryMetadata {
|
||||
name: #frame_support::metadata::DecodeDifferent::Encode(
|
||||
<#full_ident as #metadata_trait>::NAME
|
||||
),
|
||||
modifier: <#full_ident as #metadata_trait>::MODIFIER,
|
||||
ty: #ty,
|
||||
default: #frame_support::metadata::DecodeDifferent::Encode(
|
||||
<#full_ident as #metadata_trait>::DEFAULT
|
||||
),
|
||||
documentation: #frame_support::metadata::DecodeDifferent::Encode(&[
|
||||
name: <#full_ident as #frame_support::storage::StorageEntryMetadata>::NAME,
|
||||
modifier: <#full_ident as #frame_support::storage::StorageEntryMetadata>::MODIFIER,
|
||||
ty: <#full_ident as #frame_support::storage::StorageEntryMetadata>::ty(),
|
||||
default: <#full_ident as #frame_support::storage::StorageEntryMetadata>::default(),
|
||||
docs: #frame_support::sp_std::vec![
|
||||
#( #docs, )*
|
||||
]),
|
||||
],
|
||||
}
|
||||
)
|
||||
});
|
||||
@@ -419,18 +344,16 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
#completed_where_clause
|
||||
{
|
||||
#[doc(hidden)]
|
||||
pub fn storage_metadata() -> #frame_support::metadata::StorageMetadata {
|
||||
#frame_support::metadata::StorageMetadata {
|
||||
prefix: #frame_support::metadata::DecodeDifferent::Encode(
|
||||
<
|
||||
<T as #frame_system::Config>::PalletInfo as
|
||||
#frame_support::traits::PalletInfo
|
||||
>::name::<#pallet_ident<#type_use_gen>>()
|
||||
.expect("Every active pallet has a name in the runtime; qed")
|
||||
),
|
||||
entries: #frame_support::metadata::DecodeDifferent::Encode(
|
||||
&[ #( #entries, )* ]
|
||||
),
|
||||
pub fn storage_metadata() -> #frame_support::metadata::PalletStorageMetadata {
|
||||
#frame_support::metadata::PalletStorageMetadata {
|
||||
prefix: <
|
||||
<T as #frame_system::Config>::PalletInfo as
|
||||
#frame_support::traits::PalletInfo
|
||||
>::name::<#pallet_ident<#type_use_gen>>()
|
||||
.expect("Every active pallet has a name in the runtime; qed"),
|
||||
entries: #frame_support::sp_std::vec![
|
||||
#( #entries, )*
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use super::helper;
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use quote::ToTokens;
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
@@ -219,7 +220,7 @@ impl CallDef {
|
||||
args.push((!arg_attrs.is_empty(), arg_ident, arg.ty.clone()));
|
||||
}
|
||||
|
||||
let docs = helper::get_doc_literals(&method.attrs);
|
||||
let docs = get_doc_literals(&method.attrs);
|
||||
|
||||
methods.push(CallVariantDef { name: method.sig.ident.clone(), weight, args, docs });
|
||||
} else {
|
||||
@@ -234,7 +235,7 @@ impl CallDef {
|
||||
instances,
|
||||
methods,
|
||||
where_clause: item.generics.where_clause.clone(),
|
||||
docs: helper::get_doc_literals(&item.attrs),
|
||||
docs: get_doc_literals(&item.attrs),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
use super::helper;
|
||||
use core::convert::TryFrom;
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use quote::ToTokens;
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
@@ -69,7 +70,7 @@ impl TryFrom<&syn::TraitItemType> for ConstMetadataDef {
|
||||
let err = |span, msg| {
|
||||
syn::Error::new(span, format!("Invalid usage of `#[pallet::constant]`: {}", msg))
|
||||
};
|
||||
let doc = helper::get_doc_literals(&trait_ty.attrs);
|
||||
let doc = get_doc_literals(&trait_ty.attrs);
|
||||
let ident = trait_ty.ident.clone();
|
||||
let bound = trait_ty
|
||||
.bounds
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use super::helper;
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use quote::ToTokens;
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
@@ -80,7 +81,7 @@ impl ErrorDef {
|
||||
return Err(syn::Error::new(span, msg))
|
||||
}
|
||||
|
||||
Ok((variant.ident.clone(), helper::get_doc_literals(&variant.attrs)))
|
||||
Ok((variant.ident.clone(), get_doc_literals(&variant.attrs)))
|
||||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
// limitations under the License.
|
||||
|
||||
use super::helper;
|
||||
use frame_support_procedural_tools::clean_type_string;
|
||||
use quote::ToTokens;
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
/// List of additional token to be used for parsing.
|
||||
mod keyword {
|
||||
syn::custom_keyword!(metadata);
|
||||
syn::custom_keyword!(Event);
|
||||
syn::custom_keyword!(pallet);
|
||||
syn::custom_keyword!(generate_deposit);
|
||||
@@ -35,60 +33,31 @@ pub struct EventDef {
|
||||
pub index: usize,
|
||||
/// The keyword Event used (contains span).
|
||||
pub event: keyword::Event,
|
||||
/// Event metadatas: `(name, args, docs)`.
|
||||
pub metadata: Vec<(syn::Ident, Vec<String>, Vec<syn::Lit>)>,
|
||||
/// A set of usage of instance, must be check for consistency with trait.
|
||||
pub instances: Vec<helper::InstanceUsage>,
|
||||
/// The kind of generic the type `Event` has.
|
||||
pub gen_kind: super::GenericKind,
|
||||
/// Whether the function `deposit_event` must be generated.
|
||||
pub deposit_event: Option<(syn::Visibility, proc_macro2::Span)>,
|
||||
pub deposit_event: Option<PalletEventDepositAttr>,
|
||||
/// Where clause used in event definition.
|
||||
pub where_clause: Option<syn::WhereClause>,
|
||||
/// The span of the pallet::event attribute.
|
||||
pub attr_span: proc_macro2::Span,
|
||||
}
|
||||
|
||||
/// Attribute for Event: defines metadata name to use.
|
||||
/// Attribute for a pallet's Event.
|
||||
///
|
||||
/// Syntax is:
|
||||
/// * `#[pallet::metadata(SomeType = MetadataName, ...)]`
|
||||
/// * `#[pallet::generate_deposit($vis fn deposit_event)]`
|
||||
enum PalletEventAttr {
|
||||
Metadata {
|
||||
metadata: Vec<(syn::Type, String)>,
|
||||
// Span of the attribute
|
||||
span: proc_macro2::Span,
|
||||
},
|
||||
DepositEvent {
|
||||
fn_vis: syn::Visibility,
|
||||
// Span for the keyword deposit_event
|
||||
fn_span: proc_macro2::Span,
|
||||
// Span of the attribute
|
||||
span: proc_macro2::Span,
|
||||
},
|
||||
pub struct PalletEventDepositAttr {
|
||||
pub fn_vis: syn::Visibility,
|
||||
// Span for the keyword deposit_event
|
||||
pub fn_span: proc_macro2::Span,
|
||||
// Span of the attribute
|
||||
pub span: proc_macro2::Span,
|
||||
}
|
||||
|
||||
impl PalletEventAttr {
|
||||
fn span(&self) -> proc_macro2::Span {
|
||||
match self {
|
||||
Self::Metadata { span, .. } => *span,
|
||||
Self::DepositEvent { span, .. } => *span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse for syntax `$Type = "$SomeString"`.
|
||||
fn parse_event_metadata_element(
|
||||
input: syn::parse::ParseStream,
|
||||
) -> syn::Result<(syn::Type, String)> {
|
||||
let typ = input.parse::<syn::Type>()?;
|
||||
input.parse::<syn::Token![=]>()?;
|
||||
let ident = input.parse::<syn::LitStr>()?;
|
||||
Ok((typ, ident.value()))
|
||||
}
|
||||
|
||||
impl syn::parse::Parse for PalletEventAttr {
|
||||
impl syn::parse::Parse for PalletEventDepositAttr {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
input.parse::<syn::Token![#]>()?;
|
||||
let content;
|
||||
@@ -96,56 +65,33 @@ impl syn::parse::Parse for PalletEventAttr {
|
||||
content.parse::<keyword::pallet>()?;
|
||||
content.parse::<syn::Token![::]>()?;
|
||||
|
||||
let lookahead = content.lookahead1();
|
||||
if lookahead.peek(keyword::metadata) {
|
||||
let span = content.parse::<keyword::metadata>()?.span();
|
||||
let metadata_content;
|
||||
syn::parenthesized!(metadata_content in content);
|
||||
let span = content.parse::<keyword::generate_deposit>()?.span();
|
||||
let generate_content;
|
||||
syn::parenthesized!(generate_content in content);
|
||||
let fn_vis = generate_content.parse::<syn::Visibility>()?;
|
||||
generate_content.parse::<syn::Token![fn]>()?;
|
||||
let fn_span = generate_content.parse::<keyword::deposit_event>()?.span();
|
||||
|
||||
let metadata = metadata_content
|
||||
.parse_terminated::<_, syn::Token![,]>(parse_event_metadata_element)?
|
||||
.into_pairs()
|
||||
.map(syn::punctuated::Pair::into_value)
|
||||
.collect();
|
||||
|
||||
Ok(PalletEventAttr::Metadata { metadata, span })
|
||||
} else if lookahead.peek(keyword::generate_deposit) {
|
||||
let span = content.parse::<keyword::generate_deposit>()?.span();
|
||||
|
||||
let generate_content;
|
||||
syn::parenthesized!(generate_content in content);
|
||||
let fn_vis = generate_content.parse::<syn::Visibility>()?;
|
||||
generate_content.parse::<syn::Token![fn]>()?;
|
||||
let fn_span = generate_content.parse::<keyword::deposit_event>()?.span();
|
||||
|
||||
Ok(PalletEventAttr::DepositEvent { fn_vis, span, fn_span })
|
||||
} else {
|
||||
Err(lookahead.error())
|
||||
}
|
||||
Ok(PalletEventDepositAttr { fn_vis, span, fn_span })
|
||||
}
|
||||
}
|
||||
|
||||
struct PalletEventAttrInfo {
|
||||
metadata: Option<Vec<(syn::Type, String)>>,
|
||||
deposit_event: Option<(syn::Visibility, proc_macro2::Span)>,
|
||||
deposit_event: Option<PalletEventDepositAttr>,
|
||||
}
|
||||
|
||||
impl PalletEventAttrInfo {
|
||||
fn from_attrs(attrs: Vec<PalletEventAttr>) -> syn::Result<Self> {
|
||||
let mut metadata = None;
|
||||
fn from_attrs(attrs: Vec<PalletEventDepositAttr>) -> syn::Result<Self> {
|
||||
let mut deposit_event = None;
|
||||
for attr in attrs {
|
||||
match attr {
|
||||
PalletEventAttr::Metadata { metadata: m, .. } if metadata.is_none() =>
|
||||
metadata = Some(m),
|
||||
PalletEventAttr::DepositEvent { fn_vis, fn_span, .. }
|
||||
if deposit_event.is_none() =>
|
||||
deposit_event = Some((fn_vis, fn_span)),
|
||||
attr => return Err(syn::Error::new(attr.span(), "Duplicate attribute")),
|
||||
if deposit_event.is_none() {
|
||||
deposit_event = Some(attr)
|
||||
} else {
|
||||
return Err(syn::Error::new(attr.span, "Duplicate attribute"))
|
||||
}
|
||||
}
|
||||
|
||||
Ok(PalletEventAttrInfo { metadata, deposit_event })
|
||||
Ok(PalletEventAttrInfo { deposit_event })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,9 +107,9 @@ impl EventDef {
|
||||
return Err(syn::Error::new(item.span(), "Invalid pallet::event, expected item enum"))
|
||||
};
|
||||
|
||||
let event_attrs: Vec<PalletEventAttr> = helper::take_item_pallet_attrs(&mut item.attrs)?;
|
||||
let event_attrs: Vec<PalletEventDepositAttr> =
|
||||
helper::take_item_pallet_attrs(&mut item.attrs)?;
|
||||
let attr_info = PalletEventAttrInfo::from_attrs(event_attrs)?;
|
||||
let metadata = attr_info.metadata.unwrap_or_else(Vec::new);
|
||||
let deposit_event = attr_info.deposit_event;
|
||||
|
||||
if !matches!(item.vis, syn::Visibility::Public(_)) {
|
||||
@@ -190,39 +136,6 @@ impl EventDef {
|
||||
|
||||
let event = syn::parse2::<keyword::Event>(item.ident.to_token_stream())?;
|
||||
|
||||
let metadata = item
|
||||
.variants
|
||||
.iter()
|
||||
.map(|variant| {
|
||||
let name = variant.ident.clone();
|
||||
let docs = helper::get_doc_literals(&variant.attrs);
|
||||
let args = variant
|
||||
.fields
|
||||
.iter()
|
||||
.map(|field| {
|
||||
metadata
|
||||
.iter()
|
||||
.find(|m| m.0 == field.ty)
|
||||
.map(|m| m.1.clone())
|
||||
.unwrap_or_else(|| {
|
||||
clean_type_string(&field.ty.to_token_stream().to_string())
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
(name, args, docs)
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(EventDef {
|
||||
attr_span,
|
||||
index,
|
||||
metadata,
|
||||
instances,
|
||||
deposit_event,
|
||||
event,
|
||||
gen_kind,
|
||||
where_clause,
|
||||
})
|
||||
Ok(EventDef { attr_span, index, instances, deposit_event, event, gen_kind, where_clause })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use super::helper;
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
/// List of additional token to be used for parsing.
|
||||
@@ -104,7 +105,7 @@ impl ExtraConstantsDef {
|
||||
extra_constants.push(ExtraConstantDef {
|
||||
ident: method.sig.ident.clone(),
|
||||
type_,
|
||||
doc: helper::get_doc_literals(&method.attrs),
|
||||
doc: get_doc_literals(&method.attrs),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -139,24 +139,6 @@ impl MutItemAttrs for syn::ItemMod {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return all doc attributes literals found.
|
||||
pub fn get_doc_literals(attrs: &Vec<syn::Attribute>) -> Vec<syn::Lit> {
|
||||
attrs
|
||||
.iter()
|
||||
.filter_map(|attr| {
|
||||
if let Ok(syn::Meta::NameValue(meta)) = attr.parse_meta() {
|
||||
if meta.path.get_ident().map_or(false, |ident| ident == "doc") {
|
||||
Some(meta.lit)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Parse for `()`
|
||||
struct Unit;
|
||||
impl syn::parse::Parse for Unit {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use super::helper;
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use quote::ToTokens;
|
||||
use std::collections::HashMap;
|
||||
use syn::spanned::Spanned;
|
||||
@@ -609,7 +610,7 @@ impl StorageDef {
|
||||
instances.push(helper::check_type_def_gen(&item.generics, item.ident.span())?);
|
||||
|
||||
let where_clause = item.generics.where_clause.clone();
|
||||
let docs = helper::get_doc_literals(&item.attrs);
|
||||
let docs = get_doc_literals(&item.attrs);
|
||||
|
||||
let typ = if let syn::Type::Path(typ) = &*item.ty {
|
||||
typ
|
||||
|
||||
@@ -126,6 +126,7 @@ fn create_and_impl_instance_struct(
|
||||
Clone, Eq, PartialEq,
|
||||
#scrate::codec::Encode,
|
||||
#scrate::codec::Decode,
|
||||
#scrate::scale_info::TypeInfo,
|
||||
#scrate::RuntimeDebug,
|
||||
)]
|
||||
#doc
|
||||
|
||||
@@ -18,31 +18,28 @@
|
||||
//! Implementation of `storage_metadata` on module structure, used by construct_runtime.
|
||||
|
||||
use super::{DeclStorageDefExt, StorageLineDefExt, StorageLineTypeDef};
|
||||
use frame_support_procedural_tools::clean_type_string;
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
fn storage_line_metadata_type(scrate: &TokenStream, line: &StorageLineDefExt) -> TokenStream {
|
||||
let value_type = &line.value_type;
|
||||
let value_type = clean_type_string("e!( #value_type ).to_string());
|
||||
match &line.storage_type {
|
||||
StorageLineTypeDef::Simple(_) => {
|
||||
quote! {
|
||||
#scrate::metadata::StorageEntryType::Plain(
|
||||
#scrate::metadata::DecodeDifferent::Encode(#value_type),
|
||||
#scrate::scale_info::meta_type::<#value_type>()
|
||||
)
|
||||
}
|
||||
},
|
||||
StorageLineTypeDef::Map(map) => {
|
||||
let hasher = map.hasher.into_metadata();
|
||||
let key = &map.key;
|
||||
let key = clean_type_string("e!(#key).to_string());
|
||||
quote! {
|
||||
#scrate::metadata::StorageEntryType::Map {
|
||||
hasher: #scrate::metadata::#hasher,
|
||||
key: #scrate::metadata::DecodeDifferent::Encode(#key),
|
||||
value: #scrate::metadata::DecodeDifferent::Encode(#value_type),
|
||||
unused: false,
|
||||
hashers: #scrate::sp_std::vec! [ #scrate::metadata::#hasher ],
|
||||
key: #scrate::scale_info::meta_type::<#key>(),
|
||||
value: #scrate::scale_info::meta_type::<#value_type>(),
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -50,39 +47,32 @@ fn storage_line_metadata_type(scrate: &TokenStream, line: &StorageLineDefExt) ->
|
||||
let hasher1 = map.hasher1.into_metadata();
|
||||
let hasher2 = map.hasher2.into_metadata();
|
||||
let key1 = &map.key1;
|
||||
let key1 = clean_type_string("e!(#key1).to_string());
|
||||
let key2 = &map.key2;
|
||||
let key2 = clean_type_string("e!(#key2).to_string());
|
||||
quote! {
|
||||
#scrate::metadata::StorageEntryType::DoubleMap {
|
||||
hasher: #scrate::metadata::#hasher1,
|
||||
key1: #scrate::metadata::DecodeDifferent::Encode(#key1),
|
||||
key2: #scrate::metadata::DecodeDifferent::Encode(#key2),
|
||||
value: #scrate::metadata::DecodeDifferent::Encode(#value_type),
|
||||
key2_hasher: #scrate::metadata::#hasher2,
|
||||
#scrate::metadata::StorageEntryType::Map {
|
||||
hashers: #scrate::sp_std::vec! [
|
||||
#scrate::metadata::#hasher1,
|
||||
#scrate::metadata::#hasher2,
|
||||
],
|
||||
key: #scrate::scale_info::meta_type::<(#key1, #key2)>(),
|
||||
value: #scrate::scale_info::meta_type::<#value_type>(),
|
||||
}
|
||||
}
|
||||
},
|
||||
StorageLineTypeDef::NMap(map) => {
|
||||
let keys = map
|
||||
.keys
|
||||
.iter()
|
||||
.map(|key| clean_type_string("e!(#key).to_string()))
|
||||
.collect::<Vec<_>>();
|
||||
let key_tuple = &map.to_key_tuple();
|
||||
let hashers = map
|
||||
.hashers
|
||||
.iter()
|
||||
.map(|hasher| hasher.to_storage_hasher_struct())
|
||||
.collect::<Vec<_>>();
|
||||
quote! {
|
||||
#scrate::metadata::StorageEntryType::NMap {
|
||||
keys: #scrate::metadata::DecodeDifferent::Encode(&[
|
||||
#( #keys, )*
|
||||
]),
|
||||
hashers: #scrate::metadata::DecodeDifferent::Encode(&[
|
||||
#scrate::metadata::StorageEntryType::Map {
|
||||
hashers: #scrate::sp_std::vec! [
|
||||
#( #scrate::metadata::StorageHasher::#hashers, )*
|
||||
]),
|
||||
value: #scrate::metadata::DecodeDifferent::Encode(#value_type),
|
||||
],
|
||||
key: #scrate::scale_info::meta_type::<#key_tuple>(),
|
||||
value: #scrate::scale_info::meta_type::<#value_type>(),
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -129,8 +119,7 @@ fn default_byte_getter(
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<#runtime_generic: #runtime_trait, #optional_instance_bound>
|
||||
#scrate::metadata::DefaultByte
|
||||
for #struct_name<#runtime_generic, #optional_instance>
|
||||
#struct_name<#runtime_generic, #optional_instance>
|
||||
#where_clause
|
||||
{
|
||||
fn default_byte(&self) -> #scrate::sp_std::vec::Vec<u8> {
|
||||
@@ -142,16 +131,9 @@ fn default_byte_getter(
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<#runtime_generic: #runtime_trait, #optional_instance_bound> Send
|
||||
for #struct_name<#runtime_generic, #optional_instance> #where_clause {}
|
||||
|
||||
unsafe impl<#runtime_generic: #runtime_trait, #optional_instance_bound> Sync
|
||||
for #struct_name<#runtime_generic, #optional_instance> #where_clause {}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl<#runtime_generic: #runtime_trait, #optional_instance_bound>
|
||||
#scrate::metadata::DefaultByte
|
||||
for #struct_name<#runtime_generic, #optional_instance>
|
||||
#struct_name<#runtime_generic, #optional_instance>
|
||||
#where_clause
|
||||
{
|
||||
fn default_byte(&self) -> #scrate::sp_std::vec::Vec<u8> {
|
||||
@@ -187,25 +169,15 @@ pub fn impl_metadata(def: &DeclStorageDefExt) -> TokenStream {
|
||||
let (default_byte_getter_struct_def, default_byte_getter_struct_instance) =
|
||||
default_byte_getter(scrate, line, def);
|
||||
|
||||
let mut docs = TokenStream::new();
|
||||
for attr in line.attrs.iter().filter_map(|v| v.parse_meta().ok()) {
|
||||
if let syn::Meta::NameValue(meta) = attr {
|
||||
if meta.path.is_ident("doc") {
|
||||
let lit = meta.lit;
|
||||
docs.extend(quote!(#lit,));
|
||||
}
|
||||
}
|
||||
}
|
||||
let docs = get_doc_literals(&line.attrs);
|
||||
|
||||
let entry = quote! {
|
||||
#scrate::metadata::StorageEntryMetadata {
|
||||
name: #scrate::metadata::DecodeDifferent::Encode(#str_name),
|
||||
name: #str_name,
|
||||
modifier: #modifier,
|
||||
ty: #ty,
|
||||
default: #scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::DefaultByteGetter(&#default_byte_getter_struct_instance)
|
||||
),
|
||||
documentation: #scrate::metadata::DecodeDifferent::Encode(&[ #docs ]),
|
||||
default: #default_byte_getter_struct_instance.default_byte(),
|
||||
docs: #scrate::sp_std::vec![ #( #docs ),* ],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -222,9 +194,9 @@ pub fn impl_metadata(def: &DeclStorageDefExt) -> TokenStream {
|
||||
};
|
||||
|
||||
let store_metadata = quote!(
|
||||
#scrate::metadata::StorageMetadata {
|
||||
prefix: #scrate::metadata::DecodeDifferent::Encode(#prefix),
|
||||
entries: #scrate::metadata::DecodeDifferent::Encode(&[ #entries ][..]),
|
||||
#scrate::metadata::PalletStorageMetadata {
|
||||
prefix: #prefix,
|
||||
entries: #scrate::sp_std::vec![ #entries ],
|
||||
}
|
||||
);
|
||||
|
||||
@@ -237,7 +209,7 @@ pub fn impl_metadata(def: &DeclStorageDefExt) -> TokenStream {
|
||||
|
||||
impl#module_impl #module_struct #where_clause {
|
||||
#[doc(hidden)]
|
||||
pub fn storage_metadata() -> #scrate::metadata::StorageMetadata {
|
||||
pub fn storage_metadata() -> #scrate::metadata::PalletStorageMetadata {
|
||||
#store_metadata
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,3 +100,21 @@ pub fn clean_type_string(input: &str) -> String {
|
||||
.replace("< ", "<")
|
||||
.replace(" >", ">")
|
||||
}
|
||||
|
||||
/// Return all doc attributes literals found.
|
||||
pub fn get_doc_literals(attrs: &[syn::Attribute]) -> Vec<syn::Lit> {
|
||||
attrs
|
||||
.iter()
|
||||
.filter_map(|attr| {
|
||||
if let Ok(syn::Meta::NameValue(meta)) = attr.parse_meta() {
|
||||
if meta.path.get_ident().map_or(false, |ident| ident == "doc") {
|
||||
Some(meta.lit)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -33,10 +33,6 @@ pub use crate::{
|
||||
TransactionPriority, WeighData, Weight, WithPostDispatchInfo,
|
||||
},
|
||||
};
|
||||
pub use frame_metadata::{
|
||||
DecodeDifferent, DecodeDifferentArray, DefaultByte, DefaultByteGetter, ErrorMetadata,
|
||||
FunctionArgumentMetadata, FunctionMetadata, ModuleConstantMetadata, ModuleErrorMetadata,
|
||||
};
|
||||
pub use sp_runtime::{traits::Dispatchable, DispatchError};
|
||||
|
||||
/// The return type of a `Dispatchable` in frame. When returned explicitly from
|
||||
@@ -67,8 +63,8 @@ pub type CallableCallFor<A, R> = <A as Callable<R>>::Call;
|
||||
/// A type that can be used as a parameter in a dispatchable function.
|
||||
///
|
||||
/// When using `decl_module` all arguments for call functions must implement this trait.
|
||||
pub trait Parameter: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
pub trait Parameter: Codec + EncodeLike + Clone + Eq + fmt::Debug + scale_info::TypeInfo {}
|
||||
impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug + scale_info::TypeInfo {}
|
||||
|
||||
/// Declares a `Module` struct and a `Call` enum, which implements the dispatch logic.
|
||||
///
|
||||
@@ -1169,7 +1165,7 @@ macro_rules! decl_module {
|
||||
{ $( $on_finalize )* }
|
||||
{ $( $offchain )* }
|
||||
{ $( $constants )* }
|
||||
{ &'static str }
|
||||
{ __NO_ERROR_DEFINED }
|
||||
{ $( $integrity_test )* }
|
||||
{ $( $storage_version )* }
|
||||
[ $($t)* ]
|
||||
@@ -1239,7 +1235,7 @@ macro_rules! decl_module {
|
||||
{ $( $on_finalize:tt )* }
|
||||
{ $( $offchain:tt )* }
|
||||
{ $( $constants:tt )* }
|
||||
{ $error_type:ty }
|
||||
{ $( $error_type:tt )* }
|
||||
{ $( $integrity_test:tt )* }
|
||||
{ $( $storage_version:tt )* }
|
||||
[ $( $dispatchables:tt )* ]
|
||||
@@ -1265,8 +1261,8 @@ macro_rules! decl_module {
|
||||
{ $( $on_finalize )* }
|
||||
{ $( $offchain )* }
|
||||
{ $( $constants )* }
|
||||
{ $error_type }
|
||||
{ $( $integrity_test )* }
|
||||
{ $( $error_type )* }
|
||||
{ $( $integrity_test)* }
|
||||
{ $( $storage_version )* }
|
||||
[
|
||||
$( $dispatchables )*
|
||||
@@ -1750,7 +1746,6 @@ macro_rules! decl_module {
|
||||
(@impl_function
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
$origin_ty:ty;
|
||||
$error_type:ty;
|
||||
$ignore:ident;
|
||||
$(#[$fn_attr:meta])*
|
||||
$vis:vis fn $name:ident (
|
||||
@@ -1772,7 +1767,6 @@ macro_rules! decl_module {
|
||||
(@impl_function
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
$origin_ty:ty;
|
||||
$error_type:ty;
|
||||
$ignore:ident;
|
||||
$(#[$fn_attr:meta])*
|
||||
$vis:vis fn $name:ident (
|
||||
@@ -1796,7 +1790,7 @@ macro_rules! decl_module {
|
||||
variant $fn_name:ident;
|
||||
$( #[doc = $doc_attr:tt] )*
|
||||
#[compact]
|
||||
$type:ty;
|
||||
$name:ident : $type:ty;
|
||||
$( $rest:tt )*
|
||||
) => {
|
||||
$crate::decl_module! {
|
||||
@@ -1808,7 +1802,7 @@ macro_rules! decl_module {
|
||||
{
|
||||
$( $current_params )*
|
||||
#[codec(compact)]
|
||||
$type,
|
||||
$name: $type,
|
||||
}
|
||||
variant $fn_name;
|
||||
$( #[doc = $doc_attr] )*
|
||||
@@ -1825,7 +1819,7 @@ macro_rules! decl_module {
|
||||
{ $( $current_params:tt )* }
|
||||
variant $fn_name:ident;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$type:ty;
|
||||
$name:ident : $type:ty;
|
||||
$( $rest:tt )*
|
||||
) => {
|
||||
$crate::decl_module! {
|
||||
@@ -1836,7 +1830,7 @@ macro_rules! decl_module {
|
||||
{ $( $generated_variants )* }
|
||||
{
|
||||
$( $current_params )*
|
||||
$type,
|
||||
$name: $type,
|
||||
}
|
||||
variant $fn_name;
|
||||
$( #[doc = $doc_attr] )*
|
||||
@@ -1866,9 +1860,9 @@ macro_rules! decl_module {
|
||||
$( $generated_variants )*
|
||||
#[allow(non_camel_case_types)]
|
||||
$(#[doc = $doc_attr])*
|
||||
$fn_name (
|
||||
$fn_name {
|
||||
$( $current_params )*
|
||||
),
|
||||
},
|
||||
}
|
||||
{}
|
||||
$(
|
||||
@@ -1888,7 +1882,8 @@ macro_rules! decl_module {
|
||||
/// Dispatchable calls.
|
||||
///
|
||||
/// Each variant of this enum maps to a dispatchable function from the associated module.
|
||||
#[derive($crate::codec::Encode, $crate::codec::Decode)]
|
||||
#[derive($crate::codec::Encode, $crate::codec::Decode, $crate::scale_info::TypeInfo)]
|
||||
#[scale_info(skip_type_params($trait_instance $(, $instance)?), capture_docs = "always")]
|
||||
pub enum $call_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $( = $module_default_instance)?)?>
|
||||
where $( $other_where_bounds )*
|
||||
{
|
||||
@@ -1965,7 +1960,7 @@ macro_rules! decl_module {
|
||||
{ $( $on_finalize:tt )* }
|
||||
{ $( $offchain:tt )* }
|
||||
{ $( $constants:tt )* }
|
||||
{ $error_type:ty }
|
||||
{ $( $error_type:tt )* }
|
||||
{ $( $integrity_test:tt )* }
|
||||
{ $( $storage_version:tt )* }
|
||||
) => {
|
||||
@@ -2051,7 +2046,6 @@ macro_rules! decl_module {
|
||||
@impl_function
|
||||
$mod_type<$trait_instance: $trait_name $(<I>, $fn_instance: $fn_instantiable)?>;
|
||||
$origin_type;
|
||||
$error_type;
|
||||
$from;
|
||||
$(#[doc = $doc_attr])*
|
||||
///
|
||||
@@ -2076,11 +2070,28 @@ macro_rules! decl_module {
|
||||
$(#[doc = $doc_attr])*
|
||||
$(
|
||||
$(#[$codec_attr])*
|
||||
$param;
|
||||
$param_name : $param;
|
||||
)*
|
||||
)*
|
||||
}
|
||||
|
||||
$crate::paste::paste! {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>
|
||||
$call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
$(
|
||||
#[doc = "Create a call with the variant `" $fn_name "`."]
|
||||
pub fn [< new_call_variant_ $fn_name >](
|
||||
$( $param_name: $param ),*
|
||||
) -> Self {
|
||||
Self::$fn_name {
|
||||
$( $param_name ),*
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
$crate::decl_module! {
|
||||
@impl_get_storage_version
|
||||
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
|
||||
@@ -2095,7 +2106,7 @@ macro_rules! decl_module {
|
||||
fn get_dispatch_info(&self) -> $crate::dispatch::DispatchInfo {
|
||||
match *self {
|
||||
$(
|
||||
$call_type::$fn_name( $( ref $param_name ),* ) => {
|
||||
$call_type::$fn_name { $( ref $param_name ),* } => {
|
||||
let __pallet_base_weight = $weight;
|
||||
let __pallet_weight = <dyn $crate::dispatch::WeighData<( $( & $param, )* )>>::weigh_data(
|
||||
&__pallet_base_weight,
|
||||
@@ -2149,7 +2160,7 @@ macro_rules! decl_module {
|
||||
fn get_call_name(&self) -> &'static str {
|
||||
match *self {
|
||||
$(
|
||||
$call_type::$fn_name( $( ref $param_name ),* ) => {
|
||||
$call_type::$fn_name { $( ref $param_name ),* } => {
|
||||
// Don't generate any warnings for unused variables
|
||||
let _ = ( $( $param_name ),* );
|
||||
stringify!($fn_name)
|
||||
@@ -2186,8 +2197,8 @@ macro_rules! decl_module {
|
||||
fn clone(&self) -> Self {
|
||||
match *self {
|
||||
$(
|
||||
$call_type::$fn_name( $( ref $param_name ),* ) =>
|
||||
$call_type::$fn_name( $( (*$param_name).clone() ),* )
|
||||
$call_type::$fn_name { $( ref $param_name ),* } =>
|
||||
$call_type::$fn_name { $( $param_name: (*$param_name).clone() ),* }
|
||||
,)*
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -2200,9 +2211,9 @@ macro_rules! decl_module {
|
||||
fn eq(&self, _other: &Self) -> bool {
|
||||
match *self {
|
||||
$(
|
||||
$call_type::$fn_name( $( ref $param_name ),* ) => {
|
||||
$call_type::$fn_name { $( ref $param_name ),* } => {
|
||||
let self_params = ( $( $param_name, )* );
|
||||
if let $call_type::$fn_name( $( ref $param_name ),* ) = *_other {
|
||||
if let $call_type::$fn_name { $( ref $param_name ),* } = *_other {
|
||||
self_params == ( $( $param_name, )* )
|
||||
} else {
|
||||
match *_other {
|
||||
@@ -2230,7 +2241,7 @@ macro_rules! decl_module {
|
||||
) -> $crate::dispatch::result::Result<(), $crate::dispatch::fmt::Error> {
|
||||
match *self {
|
||||
$(
|
||||
$call_type::$fn_name( $( ref $param_name ),* ) =>
|
||||
$call_type::$fn_name { $( ref $param_name ),* } =>
|
||||
write!(_f, "{}{:?}",
|
||||
stringify!($fn_name),
|
||||
( $( $param_name.clone(), )* )
|
||||
@@ -2248,7 +2259,7 @@ macro_rules! decl_module {
|
||||
fn dispatch_bypass_filter(self, _origin: Self::Origin) -> $crate::dispatch::DispatchResultWithPostInfo {
|
||||
match self {
|
||||
$(
|
||||
$call_type::$fn_name( $( $param_name ),* ) => {
|
||||
$call_type::$fn_name { $( $param_name ),* } => {
|
||||
$crate::decl_module!(
|
||||
@call
|
||||
$from
|
||||
@@ -2277,20 +2288,17 @@ macro_rules! decl_module {
|
||||
)*
|
||||
}
|
||||
}
|
||||
$crate::__impl_error_metadata! {
|
||||
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>
|
||||
{ $( $other_where_bounds )* }
|
||||
$( $error_type )*
|
||||
}
|
||||
$crate::__impl_module_constants_metadata ! {
|
||||
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>
|
||||
{ $( $other_where_bounds )* }
|
||||
$( $constants )*
|
||||
}
|
||||
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::ModuleErrorMetadata
|
||||
for $mod_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn metadata() -> &'static [$crate::dispatch::ErrorMetadata] {
|
||||
<$error_type as $crate::dispatch::ModuleErrorMetadata>::metadata()
|
||||
}
|
||||
}
|
||||
|
||||
$crate::__generate_dummy_part_checker!();
|
||||
}
|
||||
}
|
||||
@@ -2302,6 +2310,7 @@ macro_rules! __dispatch_impl_metadata {
|
||||
(
|
||||
$mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>
|
||||
{ $( $other_where_bounds:tt )* }
|
||||
$call_type:ident
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?>
|
||||
@@ -2309,13 +2318,51 @@ macro_rules! __dispatch_impl_metadata {
|
||||
{
|
||||
#[doc(hidden)]
|
||||
#[allow(dead_code)]
|
||||
pub fn call_functions() -> &'static [$crate::dispatch::FunctionMetadata] {
|
||||
$crate::__call_to_functions!($($rest)*)
|
||||
pub fn call_functions() -> $crate::metadata::PalletCallMetadata {
|
||||
$crate::scale_info::meta_type::<$call_type<$trait_instance $(, $instance)?>>().into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement metadata for pallet error.
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __impl_error_metadata {
|
||||
(
|
||||
$mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>
|
||||
{ $( $other_where_bounds:tt )* }
|
||||
__NO_ERROR_DEFINED
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?>
|
||||
where $( $other_where_bounds )*
|
||||
{
|
||||
#[doc(hidden)]
|
||||
#[allow(dead_code)]
|
||||
pub fn error_metadata() -> Option<$crate::metadata::PalletErrorMetadata> {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
(
|
||||
$mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>
|
||||
{ $( $other_where_bounds:tt )* }
|
||||
$( $error_type:tt )*
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?>
|
||||
where $( $other_where_bounds )*
|
||||
{
|
||||
#[doc(hidden)]
|
||||
#[allow(dead_code)]
|
||||
pub fn error_metadata() -> Option<$crate::metadata::PalletErrorMetadata> {
|
||||
Some($crate::metadata::PalletErrorMetadata {
|
||||
ty: $crate::scale_info::meta_type::<$( $error_type )*>()
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Implement metadata for module constants.
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
@@ -2383,7 +2430,7 @@ macro_rules! __impl_module_constants_metadata {
|
||||
{
|
||||
#[doc(hidden)]
|
||||
#[allow(dead_code)]
|
||||
pub fn module_constants_metadata() -> &'static [$crate::dispatch::ModuleConstantMetadata] {
|
||||
pub fn pallet_constants_metadata() -> $crate::sp_std::vec::Vec<$crate::metadata::PalletConstantMetadata> {
|
||||
// Create the `ByteGetter`s
|
||||
$(
|
||||
#[allow(non_upper_case_types)]
|
||||
@@ -2397,40 +2444,23 @@ macro_rules! __impl_module_constants_metadata {
|
||||
>);
|
||||
impl<$const_trait_instance: 'static + $const_trait_name $(
|
||||
<I>, $const_instance: $const_instantiable)?
|
||||
> $crate::dispatch::DefaultByte
|
||||
for $default_byte_name <$const_trait_instance $(, $const_instance)?>
|
||||
> $default_byte_name <$const_trait_instance $(, $const_instance)?>
|
||||
{
|
||||
fn default_byte(&self) -> $crate::dispatch::Vec<u8> {
|
||||
let value: $type = $value;
|
||||
$crate::dispatch::Encode::encode(&value)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<$const_trait_instance: 'static + $const_trait_name $(
|
||||
<I>, $const_instance: $const_instantiable)?
|
||||
> Send for $default_byte_name <$const_trait_instance $(, $const_instance)?> {}
|
||||
|
||||
unsafe impl<$const_trait_instance: 'static + $const_trait_name $(
|
||||
<I>, $const_instance: $const_instantiable)?
|
||||
> Sync for $default_byte_name <$const_trait_instance $(, $const_instance)?> {}
|
||||
)*
|
||||
&[
|
||||
$crate::sp_std::vec![
|
||||
$(
|
||||
$crate::dispatch::ModuleConstantMetadata {
|
||||
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($name)),
|
||||
ty: $crate::dispatch::DecodeDifferent::Encode(stringify!($type)),
|
||||
value: $crate::dispatch::DecodeDifferent::Encode(
|
||||
$crate::dispatch::DefaultByteGetter(
|
||||
&$default_byte_name::<
|
||||
$const_trait_instance $(, $const_instance)?
|
||||
>(
|
||||
$crate::dispatch::marker::PhantomData
|
||||
)
|
||||
)
|
||||
),
|
||||
documentation: $crate::dispatch::DecodeDifferent::Encode(
|
||||
&[ $( $doc_attr ),* ]
|
||||
),
|
||||
$crate::metadata::PalletConstantMetadata {
|
||||
name: stringify!($name),
|
||||
ty: $crate::scale_info::meta_type::<$type>(),
|
||||
value: $default_byte_name::<$const_trait_instance $(, $const_instance)?>(
|
||||
Default::default()
|
||||
).default_byte(),
|
||||
docs: $crate::sp_std::vec![ $( $doc_attr ),* ],
|
||||
}
|
||||
),*
|
||||
]
|
||||
@@ -2439,106 +2469,6 @@ macro_rules! __impl_module_constants_metadata {
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the list of calls into their JSON representation, joined by ",".
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __call_to_functions {
|
||||
(
|
||||
$call_type:ident $origin_type:ty
|
||||
{
|
||||
$(
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
fn $fn_name:ident($from:ident
|
||||
$(
|
||||
, $(#[$codec_attr:ident])* $param_name:ident : $param:ty
|
||||
)*
|
||||
);
|
||||
)*
|
||||
}
|
||||
) => {
|
||||
$crate::__functions_to_metadata!(0; $origin_type;; $(
|
||||
fn $fn_name( $($(#[$codec_attr])* $param_name: $param ),* );
|
||||
$( $doc_attr ),*;
|
||||
)*)
|
||||
};
|
||||
}
|
||||
|
||||
/// Convert a list of functions into a list of `FunctionMetadata` items.
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __functions_to_metadata{
|
||||
(
|
||||
$fn_id:expr;
|
||||
$origin_type:ty;
|
||||
$( $function_metadata:expr ),*;
|
||||
fn $fn_name:ident(
|
||||
$(
|
||||
$(#[$codec_attr:ident])* $param_name:ident : $param:ty
|
||||
),*
|
||||
);
|
||||
$( $fn_doc:expr ),*;
|
||||
$( $rest:tt )*
|
||||
) => {
|
||||
$crate::__functions_to_metadata!(
|
||||
$fn_id + 1; $origin_type;
|
||||
$( $function_metadata, )* $crate::__function_to_metadata!(
|
||||
fn $fn_name($( $(#[$codec_attr])* $param_name : $param ),*); $( $fn_doc ),*; $fn_id;
|
||||
);
|
||||
$($rest)*
|
||||
)
|
||||
};
|
||||
(
|
||||
$fn_id:expr;
|
||||
$origin_type:ty;
|
||||
$( $function_metadata:expr ),*;
|
||||
) => {
|
||||
&[ $( $function_metadata ),* ]
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a function into its metadata representation.
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __function_to_metadata {
|
||||
(
|
||||
fn $fn_name:ident(
|
||||
$( $(#[$codec_attr:ident])* $param_name:ident : $param:ty),*
|
||||
);
|
||||
$( $fn_doc:expr ),*;
|
||||
$fn_id:expr;
|
||||
) => {
|
||||
$crate::dispatch::FunctionMetadata {
|
||||
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($fn_name)),
|
||||
arguments: $crate::dispatch::DecodeDifferent::Encode(&[
|
||||
$(
|
||||
$crate::dispatch::FunctionArgumentMetadata {
|
||||
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($param_name)),
|
||||
ty: $crate::dispatch::DecodeDifferent::Encode(
|
||||
$crate::__function_to_metadata!(@stringify_expand_attr
|
||||
$(#[$codec_attr])* $param_name: $param
|
||||
)
|
||||
),
|
||||
}
|
||||
),*
|
||||
]),
|
||||
documentation: $crate::dispatch::DecodeDifferent::Encode(&[ $( $fn_doc ),* ]),
|
||||
}
|
||||
};
|
||||
|
||||
(@stringify_expand_attr #[compact] $param_name:ident : $param:ty) => {
|
||||
concat!("Compact<", stringify!($param), ">")
|
||||
};
|
||||
|
||||
(@stringify_expand_attr $param_name:ident : $param:ty) => { stringify!($param) };
|
||||
|
||||
(@stringify_expand_attr $(#[codec_attr:ident])* $param_name:ident : $param:ty) => {
|
||||
compile_error!(concat!(
|
||||
"Invalid attribute for parameter `", stringify!($param_name),
|
||||
"`, the following attributes are supported: `#[compact]`"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __check_reserved_fn_name {
|
||||
@@ -2597,6 +2527,7 @@ macro_rules! __check_reserved_fn_name {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
metadata::*,
|
||||
traits::{
|
||||
Get, GetCallName, IntegrityTest, OnFinalize, OnIdle, OnInitialize, OnRuntimeUpgrade,
|
||||
PalletInfo,
|
||||
@@ -2623,7 +2554,7 @@ mod tests {
|
||||
type DbWeight: Get<RuntimeDbWeight>;
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, scale_info::TypeInfo)]
|
||||
pub enum RawOrigin<AccountId> {
|
||||
Root,
|
||||
Signed(AccountId),
|
||||
@@ -2679,68 +2610,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
const EXPECTED_METADATA: &'static [FunctionMetadata] = &[
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_0"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[" Hi, this is a comment."]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_1"),
|
||||
arguments: DecodeDifferent::Encode(&[FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data"),
|
||||
ty: DecodeDifferent::Encode("Compact<u32>"),
|
||||
}]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_2"),
|
||||
arguments: DecodeDifferent::Encode(&[
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data"),
|
||||
ty: DecodeDifferent::Encode("i32"),
|
||||
},
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data2"),
|
||||
ty: DecodeDifferent::Encode("String"),
|
||||
},
|
||||
]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_3"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_4"),
|
||||
arguments: DecodeDifferent::Encode(&[FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data"),
|
||||
ty: DecodeDifferent::Encode("i32"),
|
||||
}]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_5"),
|
||||
arguments: DecodeDifferent::Encode(&[
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data"),
|
||||
ty: DecodeDifferent::Encode("i32"),
|
||||
},
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data2"),
|
||||
ty: DecodeDifferent::Encode("Compact<u32>"),
|
||||
},
|
||||
]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("operational"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
];
|
||||
|
||||
#[derive(scale_info::TypeInfo)]
|
||||
pub struct TraitImpl {}
|
||||
impl Config for TraitImpl {}
|
||||
|
||||
@@ -2823,17 +2693,19 @@ mod tests {
|
||||
#[test]
|
||||
fn module_json_metadata() {
|
||||
let metadata = Module::<TraitImpl>::call_functions();
|
||||
assert_eq!(EXPECTED_METADATA, metadata);
|
||||
let expected_metadata =
|
||||
PalletCallMetadata { ty: scale_info::meta_type::<Call<TraitImpl>>() };
|
||||
assert_eq!(expected_metadata, metadata);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_attr() {
|
||||
let call: Call<TraitImpl> = Call::aux_1(1);
|
||||
let call: Call<TraitImpl> = Call::aux_1 { _data: 1 };
|
||||
let encoded = call.encode();
|
||||
assert_eq!(2, encoded.len());
|
||||
assert_eq!(vec![1, 4], encoded);
|
||||
|
||||
let call: Call<TraitImpl> = Call::aux_5(1, 2);
|
||||
let call: Call<TraitImpl> = Call::aux_5 { _data: 1, _data2: 2 };
|
||||
let encoded = call.encode();
|
||||
assert_eq!(6, encoded.len());
|
||||
assert_eq!(vec![5, 1, 0, 0, 0, 8], encoded);
|
||||
@@ -2841,13 +2713,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn encode_is_correct_and_decode_works() {
|
||||
let call: Call<TraitImpl> = Call::aux_0();
|
||||
let call: Call<TraitImpl> = Call::aux_0 {};
|
||||
let encoded = call.encode();
|
||||
assert_eq!(vec![0], encoded);
|
||||
let decoded = Call::<TraitImpl>::decode(&mut &encoded[..]).unwrap();
|
||||
assert_eq!(decoded, call);
|
||||
|
||||
let call: Call<TraitImpl> = Call::aux_2(32, "hello".into());
|
||||
let call: Call<TraitImpl> = Call::aux_2 { _data: 32, _data2: "hello".into() };
|
||||
let encoded = call.encode();
|
||||
assert_eq!(vec![2, 32, 0, 0, 0, 20, 104, 101, 108, 108, 111], encoded);
|
||||
let decoded = Call::<TraitImpl>::decode(&mut &encoded[..]).unwrap();
|
||||
@@ -2899,19 +2771,19 @@ mod tests {
|
||||
fn weight_should_attach_to_call_enum() {
|
||||
// operational.
|
||||
assert_eq!(
|
||||
Call::<TraitImpl>::operational().get_dispatch_info(),
|
||||
Call::<TraitImpl>::operational {}.get_dispatch_info(),
|
||||
DispatchInfo { weight: 5, class: DispatchClass::Operational, pays_fee: Pays::Yes },
|
||||
);
|
||||
// custom basic
|
||||
assert_eq!(
|
||||
Call::<TraitImpl>::aux_3().get_dispatch_info(),
|
||||
Call::<TraitImpl>::aux_3 {}.get_dispatch_info(),
|
||||
DispatchInfo { weight: 3, class: DispatchClass::Normal, pays_fee: Pays::Yes },
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_name() {
|
||||
let name = Call::<TraitImpl>::aux_3().get_call_name();
|
||||
let name = Call::<TraitImpl>::aux_3 {}.get_call_name();
|
||||
assert_eq!("aux_3", name);
|
||||
}
|
||||
|
||||
@@ -2929,4 +2801,9 @@ mod tests {
|
||||
fn integrity_test_should_work() {
|
||||
<Module<TraitImpl> as IntegrityTest>::integrity_test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_call_variant() {
|
||||
Call::<TraitImpl>::new_call_variant_aux_0();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
//! Macro for declaring a module error.
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use frame_metadata::{DecodeDifferent, ErrorMetadata, ModuleErrorMetadata};
|
||||
#[doc(hidden)]
|
||||
pub use sp_runtime::traits::{BadOrigin, LookupError};
|
||||
|
||||
@@ -87,10 +85,13 @@ macro_rules! decl_error {
|
||||
}
|
||||
) => {
|
||||
$(#[$attr])*
|
||||
#[derive($crate::scale_info::TypeInfo)]
|
||||
#[scale_info(skip_type_params($generic $(, $inst_generic)?), capture_docs = "always")]
|
||||
pub enum $error<$generic: $trait $(, $inst_generic: $instance)?>
|
||||
$( where $( $where_ty: $where_bound ),* )?
|
||||
{
|
||||
#[doc(hidden)]
|
||||
#[codec(skip)]
|
||||
__Ignore(
|
||||
$crate::sp_std::marker::PhantomData<($generic, $( $inst_generic)?)>,
|
||||
$crate::Never,
|
||||
@@ -159,24 +160,6 @@ macro_rules! decl_error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<$generic: $trait $(, $inst_generic: $instance)?> $crate::error::ModuleErrorMetadata
|
||||
for $error<$generic $(, $inst_generic)?>
|
||||
$( where $( $where_ty: $where_bound ),* )?
|
||||
{
|
||||
fn metadata() -> &'static [$crate::error::ErrorMetadata] {
|
||||
&[
|
||||
$(
|
||||
$crate::error::ErrorMetadata {
|
||||
name: $crate::error::DecodeDifferent::Encode(stringify!($name)),
|
||||
documentation: $crate::error::DecodeDifferent::Encode(&[
|
||||
$( $doc_attr ),*
|
||||
]),
|
||||
}
|
||||
),*
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
(@GENERATE_AS_U8
|
||||
$self:ident
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
pub use frame_metadata::{DecodeDifferent, EventMetadata, FnEncode, OuterEventMetadata};
|
||||
|
||||
/// Implement the `Event` for a module.
|
||||
///
|
||||
/// # Simple Event Example:
|
||||
@@ -129,8 +127,10 @@ macro_rules! decl_event {
|
||||
Clone, PartialEq, Eq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::scale_info::TypeInfo,
|
||||
$crate::RuntimeDebug,
|
||||
)]
|
||||
#[scale_info(capture_docs = "always")]
|
||||
/// Events for this module.
|
||||
///
|
||||
$(#[$attr])*
|
||||
@@ -142,13 +142,6 @@ macro_rules! decl_event {
|
||||
impl From<Event> for () {
|
||||
fn from(_: Event) -> () { () }
|
||||
}
|
||||
impl Event {
|
||||
#[allow(dead_code)]
|
||||
#[doc(hidden)]
|
||||
pub fn metadata() -> &'static [ $crate::event::EventMetadata ] {
|
||||
$crate::__events_to_metadata!(; $( $events )* )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,8 +265,10 @@ macro_rules! __decl_generic_event {
|
||||
Clone, PartialEq, Eq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::scale_info::TypeInfo,
|
||||
$crate::RuntimeDebug,
|
||||
)]
|
||||
#[scale_info(capture_docs = "always")]
|
||||
/// Events for this module.
|
||||
///
|
||||
$(#[$attr])*
|
||||
@@ -290,263 +285,8 @@ macro_rules! __decl_generic_event {
|
||||
impl<$( $generic_param ),* $(, $instance)? > From<RawEvent<$( $generic_param ),* $(, $instance)?>> for () {
|
||||
fn from(_: RawEvent<$( $generic_param ),* $(, $instance)?>) -> () { () }
|
||||
}
|
||||
impl<$( $generic_param ),* $(, $instance)?> RawEvent<$( $generic_param ),* $(, $instance)?> {
|
||||
#[allow(dead_code)]
|
||||
#[doc(hidden)]
|
||||
pub fn metadata() -> &'static [$crate::event::EventMetadata] {
|
||||
$crate::__events_to_metadata!(; $( $events )* )
|
||||
}
|
||||
}
|
||||
};
|
||||
(@cannot_parse $ty:ty) => {
|
||||
compile_error!(concat!("The type `", stringify!($ty), "` can't be parsed as an unnamed one, please name it `Name = ", stringify!($ty), "`"));
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __events_to_metadata {
|
||||
(
|
||||
$( $metadata:expr ),*;
|
||||
$( #[doc = $doc_attr:tt] )*
|
||||
$event:ident $( ( $( $param:path ),* $(,)? ) )*,
|
||||
$( $rest:tt )*
|
||||
) => {
|
||||
$crate::__events_to_metadata!(
|
||||
$( $metadata, )*
|
||||
$crate::event::EventMetadata {
|
||||
name: $crate::event::DecodeDifferent::Encode(stringify!($event)),
|
||||
arguments: $crate::event::DecodeDifferent::Encode(&[
|
||||
$( $( stringify!($param) ),* )*
|
||||
]),
|
||||
documentation: $crate::event::DecodeDifferent::Encode(&[
|
||||
$( $doc_attr ),*
|
||||
]),
|
||||
};
|
||||
$( $rest )*
|
||||
)
|
||||
};
|
||||
(
|
||||
$( $metadata:expr ),*;
|
||||
) => {
|
||||
&[ $( $metadata ),* ]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(dead_code)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codec::{Decode, Encode};
|
||||
use serde::Serialize;
|
||||
|
||||
mod system {
|
||||
pub trait Config: 'static {
|
||||
type Origin;
|
||||
type BlockNumber;
|
||||
type PalletInfo: crate::traits::PalletInfo;
|
||||
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
|
||||
}
|
||||
|
||||
decl_event!(
|
||||
pub enum Event {
|
||||
SystemEvent,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
mod system_renamed {
|
||||
pub trait Config: 'static {
|
||||
type Origin;
|
||||
type BlockNumber;
|
||||
type PalletInfo: crate::traits::PalletInfo;
|
||||
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
|
||||
}
|
||||
|
||||
decl_event!(
|
||||
pub enum Event {
|
||||
SystemEvent,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
mod event_module {
|
||||
use super::system;
|
||||
|
||||
pub trait Config: system::Config {
|
||||
type Balance;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
|
||||
}
|
||||
|
||||
decl_event!(
|
||||
/// Event without renaming the generic parameter `Balance` and `Origin`.
|
||||
pub enum Event<T> where <T as Config>::Balance, <T as system::Config>::Origin
|
||||
{
|
||||
/// Hi, I am a comment.
|
||||
TestEvent(Balance, Origin),
|
||||
/// Dog
|
||||
EventWithoutParams,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
mod event_module2 {
|
||||
use super::system;
|
||||
|
||||
pub trait Config: system::Config {
|
||||
type Balance;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
|
||||
}
|
||||
|
||||
decl_event!(
|
||||
/// Event with renamed generic parameter
|
||||
pub enum Event<T>
|
||||
where
|
||||
BalanceRenamed = <T as Config>::Balance,
|
||||
OriginRenamed = <T as system::Config>::Origin,
|
||||
{
|
||||
TestEvent(BalanceRenamed),
|
||||
TestOrigin(OriginRenamed),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
mod event_module3 {
|
||||
decl_event!(
|
||||
pub enum Event {
|
||||
HiEvent,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
mod event_module4 {
|
||||
use super::system;
|
||||
|
||||
pub trait Config: system::Config {
|
||||
type Balance;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
|
||||
}
|
||||
|
||||
decl_event!(
|
||||
/// Event finish formatting on an unnamed one with trailing comma
|
||||
pub enum Event<T> where
|
||||
<T as Config>::Balance,
|
||||
<T as system::Config>::Origin,
|
||||
{
|
||||
TestEvent(Balance, Origin),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
mod event_module5 {
|
||||
use super::system;
|
||||
|
||||
pub trait Config: system::Config {
|
||||
type Balance;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
|
||||
}
|
||||
|
||||
decl_event!(
|
||||
/// Event finish formatting on an named one with trailing comma
|
||||
pub enum Event<T>
|
||||
where
|
||||
BalanceRenamed = <T as Config>::Balance,
|
||||
OriginRenamed = <T as system::Config>::Origin,
|
||||
{
|
||||
TestEvent(BalanceRenamed, OriginRenamed),
|
||||
TrailingCommaInArgs(u32, u32),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize)]
|
||||
pub struct TestRuntime;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize)]
|
||||
pub struct TestRuntime2;
|
||||
|
||||
impl event_module::Config for TestRuntime {
|
||||
type Balance = u32;
|
||||
}
|
||||
|
||||
impl event_module2::Config for TestRuntime {
|
||||
type Balance = u32;
|
||||
}
|
||||
|
||||
impl system::Config for TestRuntime {
|
||||
type Origin = u32;
|
||||
type BlockNumber = u32;
|
||||
type PalletInfo = crate::tests::PanicPalletInfo;
|
||||
type DbWeight = ();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn event_metadata() {
|
||||
assert_eq!(
|
||||
system_renamed::Event::metadata(),
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("SystemEvent"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},]
|
||||
);
|
||||
assert_eq!(
|
||||
event_module::Event::<TestRuntime>::metadata(),
|
||||
&[
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Encode("TestEvent"),
|
||||
arguments: DecodeDifferent::Encode(&["Balance", "Origin"]),
|
||||
documentation: DecodeDifferent::Encode(&[" Hi, I am a comment."])
|
||||
},
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Encode("EventWithoutParams"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[" Dog"]),
|
||||
},
|
||||
]
|
||||
);
|
||||
assert_eq!(
|
||||
event_module2::Event::<TestRuntime>::metadata(),
|
||||
&[
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Encode("TestEvent"),
|
||||
arguments: DecodeDifferent::Encode(&["BalanceRenamed"]),
|
||||
documentation: DecodeDifferent::Encode(&[])
|
||||
},
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Encode("TestOrigin"),
|
||||
arguments: DecodeDifferent::Encode(&["OriginRenamed"]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
]
|
||||
);
|
||||
assert_eq!(
|
||||
event_module3::Event::metadata(),
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("HiEvent"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[])
|
||||
}],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
//! Hash utilities.
|
||||
|
||||
use crate::metadata;
|
||||
use codec::{Codec, MaxEncodedLen};
|
||||
use sp_io::hashing::{blake2_128, blake2_256, twox_128, twox_256, twox_64};
|
||||
use sp_std::prelude::Vec;
|
||||
@@ -58,7 +59,7 @@ impl<T: Codec> Hashable for T {
|
||||
|
||||
/// Hasher to use to hash keys to insert to storage.
|
||||
pub trait StorageHasher: 'static {
|
||||
const METADATA: frame_metadata::StorageHasher;
|
||||
const METADATA: metadata::StorageHasher;
|
||||
type Output: AsRef<[u8]>;
|
||||
fn hash(x: &[u8]) -> Self::Output;
|
||||
|
||||
@@ -79,7 +80,7 @@ pub trait ReversibleStorageHasher: StorageHasher {
|
||||
/// Store the key directly.
|
||||
pub struct Identity;
|
||||
impl StorageHasher for Identity {
|
||||
const METADATA: frame_metadata::StorageHasher = frame_metadata::StorageHasher::Identity;
|
||||
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Identity;
|
||||
type Output = Vec<u8>;
|
||||
fn hash(x: &[u8]) -> Vec<u8> {
|
||||
x.to_vec()
|
||||
@@ -97,7 +98,7 @@ impl ReversibleStorageHasher for Identity {
|
||||
/// Hash storage keys with `concat(twox64(key), key)`
|
||||
pub struct Twox64Concat;
|
||||
impl StorageHasher for Twox64Concat {
|
||||
const METADATA: frame_metadata::StorageHasher = frame_metadata::StorageHasher::Twox64Concat;
|
||||
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Twox64Concat;
|
||||
type Output = Vec<u8>;
|
||||
fn hash(x: &[u8]) -> Vec<u8> {
|
||||
twox_64(x).iter().chain(x.into_iter()).cloned().collect::<Vec<_>>()
|
||||
@@ -119,7 +120,7 @@ impl ReversibleStorageHasher for Twox64Concat {
|
||||
/// Hash storage keys with `concat(blake2_128(key), key)`
|
||||
pub struct Blake2_128Concat;
|
||||
impl StorageHasher for Blake2_128Concat {
|
||||
const METADATA: frame_metadata::StorageHasher = frame_metadata::StorageHasher::Blake2_128Concat;
|
||||
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Blake2_128Concat;
|
||||
type Output = Vec<u8>;
|
||||
fn hash(x: &[u8]) -> Vec<u8> {
|
||||
blake2_128(x).iter().chain(x.into_iter()).cloned().collect::<Vec<_>>()
|
||||
@@ -141,7 +142,7 @@ impl ReversibleStorageHasher for Blake2_128Concat {
|
||||
/// Hash storage keys with blake2 128
|
||||
pub struct Blake2_128;
|
||||
impl StorageHasher for Blake2_128 {
|
||||
const METADATA: frame_metadata::StorageHasher = frame_metadata::StorageHasher::Blake2_128;
|
||||
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Blake2_128;
|
||||
type Output = [u8; 16];
|
||||
fn hash(x: &[u8]) -> [u8; 16] {
|
||||
blake2_128(x)
|
||||
@@ -154,7 +155,7 @@ impl StorageHasher for Blake2_128 {
|
||||
/// Hash storage keys with blake2 256
|
||||
pub struct Blake2_256;
|
||||
impl StorageHasher for Blake2_256 {
|
||||
const METADATA: frame_metadata::StorageHasher = frame_metadata::StorageHasher::Blake2_256;
|
||||
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Blake2_256;
|
||||
type Output = [u8; 32];
|
||||
fn hash(x: &[u8]) -> [u8; 32] {
|
||||
blake2_256(x)
|
||||
@@ -167,7 +168,7 @@ impl StorageHasher for Blake2_256 {
|
||||
/// Hash storage keys with twox 128
|
||||
pub struct Twox128;
|
||||
impl StorageHasher for Twox128 {
|
||||
const METADATA: frame_metadata::StorageHasher = frame_metadata::StorageHasher::Twox128;
|
||||
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Twox128;
|
||||
type Output = [u8; 16];
|
||||
fn hash(x: &[u8]) -> [u8; 16] {
|
||||
twox_128(x)
|
||||
@@ -180,7 +181,7 @@ impl StorageHasher for Twox128 {
|
||||
/// Hash storage keys with twox 256
|
||||
pub struct Twox256;
|
||||
impl StorageHasher for Twox256 {
|
||||
const METADATA: frame_metadata::StorageHasher = frame_metadata::StorageHasher::Twox256;
|
||||
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Twox256;
|
||||
type Output = [u8; 32];
|
||||
fn hash(x: &[u8]) -> [u8; 32] {
|
||||
twox_256(x)
|
||||
|
||||
+104
-150
@@ -36,6 +36,8 @@ pub use log;
|
||||
pub use once_cell;
|
||||
#[doc(hidden)]
|
||||
pub use paste;
|
||||
#[doc(hidden)]
|
||||
pub use scale_info;
|
||||
#[cfg(feature = "std")]
|
||||
pub use serde;
|
||||
pub use sp_core::Void;
|
||||
@@ -90,17 +92,18 @@ pub use self::{
|
||||
pub use sp_runtime::{self, print, traits::Printable, ConsensusEngineId};
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::TypeId;
|
||||
|
||||
/// A unified log target for support operations.
|
||||
pub const LOG_TARGET: &'static str = "runtime::frame-support";
|
||||
|
||||
/// A type that cannot be instantiated.
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, TypeInfo)]
|
||||
pub enum Never {}
|
||||
|
||||
/// A pallet identifier. These are per pallet and should be stored in a registry somewhere.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode, TypeInfo)]
|
||||
pub struct PalletId(pub [u8; 8]);
|
||||
|
||||
impl TypeId for PalletId {
|
||||
@@ -811,13 +814,13 @@ pub use serde::{Deserialize, Serialize};
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
use codec::{Codec, EncodeLike};
|
||||
use frame_metadata::{
|
||||
DecodeDifferent, DefaultByteGetter, StorageEntryMetadata, StorageEntryModifier,
|
||||
StorageEntryType, StorageHasher, StorageMetadata,
|
||||
use crate::metadata::{
|
||||
PalletStorageMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
|
||||
StorageHasher,
|
||||
};
|
||||
use codec::{Codec, EncodeLike};
|
||||
use sp_io::TestExternalities;
|
||||
use sp_std::{marker::PhantomData, result};
|
||||
use sp_std::result;
|
||||
|
||||
/// A PalletInfo implementation which just panics.
|
||||
pub struct PanicPalletInfo;
|
||||
@@ -832,7 +835,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
pub trait Config: 'static {
|
||||
type BlockNumber: Codec + EncodeLike + Default;
|
||||
type BlockNumber: Codec + EncodeLike + Default + TypeInfo;
|
||||
type Origin;
|
||||
type PalletInfo: crate::traits::PalletInfo;
|
||||
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
|
||||
@@ -1150,132 +1153,109 @@ pub mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
const EXPECTED_METADATA: StorageMetadata = StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Test"),
|
||||
entries: DecodeDifferent::Encode(&[
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("Data"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Twox64Concat,
|
||||
key: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("u64"),
|
||||
unused: false,
|
||||
fn expected_metadata() -> PalletStorageMetadata {
|
||||
PalletStorageMetadata {
|
||||
prefix: "Test",
|
||||
entries: vec![
|
||||
StorageEntryMetadata {
|
||||
name: "Data",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Twox64Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<u64>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructData(
|
||||
PhantomData::<Test>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("OptionLinkedMap"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("u32"),
|
||||
unused: false,
|
||||
StorageEntryMetadata {
|
||||
name: "OptionLinkedMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructOptionLinkedMap(PhantomData::<Test>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GenericData"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Identity,
|
||||
key: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
value: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
unused: false,
|
||||
StorageEntryMetadata {
|
||||
name: "GenericData",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Identity],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructGenericData(
|
||||
PhantomData::<Test>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GenericData2"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
value: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
unused: false,
|
||||
StorageEntryMetadata {
|
||||
name: "GenericData2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructGenericData2(
|
||||
PhantomData::<Test>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("DataDM"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
hasher: StorageHasher::Twox64Concat,
|
||||
key1: DecodeDifferent::Encode("u32"),
|
||||
key2: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("u64"),
|
||||
key2_hasher: StorageHasher::Blake2_128Concat,
|
||||
StorageEntryMetadata {
|
||||
name: "DataDM",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Twox64Concat, StorageHasher::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<u64>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructDataDM(
|
||||
PhantomData::<Test>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GenericDataDM"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key1: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
key2: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
value: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
key2_hasher: StorageHasher::Identity,
|
||||
StorageEntryMetadata {
|
||||
name: "GenericDataDM",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat, StorageHasher::Identity],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructGenericDataDM(
|
||||
PhantomData::<Test>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GenericData2DM"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key1: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
key2: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
value: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
key2_hasher: StorageHasher::Twox64Concat,
|
||||
StorageEntryMetadata {
|
||||
name: "GenericData2DM",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat, StorageHasher::Twox64Concat],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructGenericData2DM(PhantomData::<Test>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("AppendableDM"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key1: DecodeDifferent::Encode("u32"),
|
||||
key2: DecodeDifferent::Encode("T::BlockNumber"),
|
||||
value: DecodeDifferent::Encode("Vec<u32>"),
|
||||
key2_hasher: StorageHasher::Blake2_128Concat,
|
||||
StorageEntryMetadata {
|
||||
name: "AppendableDM",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Blake2_128Concat,
|
||||
],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<Vec<u32>>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructGenericData2DM(PhantomData::<Test>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
]),
|
||||
};
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn store_metadata() {
|
||||
let metadata = Module::<Test>::storage_metadata();
|
||||
pretty_assertions::assert_eq!(EXPECTED_METADATA, metadata);
|
||||
pretty_assertions::assert_eq!(expected_metadata(), metadata);
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -1470,7 +1450,7 @@ pub mod pallet_prelude {
|
||||
/// It implements on pallet:
|
||||
/// * [`traits::GetStorageVersion`]
|
||||
/// * [`traits::OnGenesis`]: contains some logic to write pallet version into storage.
|
||||
/// * `ModuleErrorMetadata`: using error declared or no metadata.
|
||||
/// * `PalletErrorTypeInfo`: provides the type information for the pallet error, if defined.
|
||||
///
|
||||
/// It declare `type Module` type alias for `Pallet`, used by [`construct_runtime`].
|
||||
///
|
||||
@@ -1623,9 +1603,6 @@ pub mod pallet_prelude {
|
||||
/// The macro implements `From<Error<T>>` for `&'static str`.
|
||||
/// The macro implements `From<Error<T>>` for `DispatchError`.
|
||||
///
|
||||
/// The macro implements `ModuleErrorMetadata` on `Pallet` defining the `ErrorMetadata` of the
|
||||
/// pallet.
|
||||
///
|
||||
/// # Event: `#[pallet::event]` optional
|
||||
///
|
||||
/// Allow to define pallet events, pallet events are stored in the block when they deposited
|
||||
@@ -1634,7 +1611,6 @@ pub mod pallet_prelude {
|
||||
/// Item is defined as:
|
||||
/// ```ignore
|
||||
/// #[pallet::event]
|
||||
/// #[pallet::metadata($SomeType = "$Metadata", $SomeOtherType = "$Metadata", ..)] // Optional
|
||||
/// #[pallet::generate_deposit($visibility fn deposit_event)] // Optional
|
||||
/// pub enum Event<$some_generic> $optional_where_clause {
|
||||
/// /// Some doc
|
||||
@@ -1649,24 +1625,6 @@ pub mod pallet_prelude {
|
||||
/// std only).
|
||||
/// For ease of use, bound the trait `Member` available in frame_support::pallet_prelude.
|
||||
///
|
||||
/// Variant documentations and field types are put into metadata.
|
||||
/// The attribute `#[pallet::metadata(..)]` allows to specify the metadata to put for some
|
||||
/// types.
|
||||
///
|
||||
/// The metadata of a type is defined by:
|
||||
/// * if matching a type in `#[pallet::metadata(..)]`, then the corresponding metadata.
|
||||
/// * otherwise the type stringified.
|
||||
///
|
||||
/// E.g.:
|
||||
/// ```ignore
|
||||
/// #[pallet::event]
|
||||
/// #[pallet::metadata(u32 = "SpecialU32")]
|
||||
/// pub enum Event<T: Config> {
|
||||
/// Proposed(u32, T::AccountId),
|
||||
/// }
|
||||
/// ```
|
||||
/// will write in event variant metadata `"SpecialU32"` and `"T::AccountId"`.
|
||||
///
|
||||
/// The attribute `#[pallet::generate_deposit($visibility fn deposit_event)]` generate a helper
|
||||
/// function on `Pallet` to deposit event.
|
||||
///
|
||||
@@ -2027,8 +1985,6 @@ pub mod pallet_prelude {
|
||||
/// //
|
||||
/// // The macro generates event metadata, and derive Clone, Debug, Eq, PartialEq and Codec
|
||||
/// #[pallet::event]
|
||||
/// // Additional argument to specify the metadata to use for given type.
|
||||
/// #[pallet::metadata(BalanceOf<T> = "Balance", u32 = "Other")]
|
||||
/// // Generate a funciton on Pallet to deposit an event.
|
||||
/// #[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
/// pub enum Event<T: Config> {
|
||||
@@ -2192,7 +2148,6 @@ pub mod pallet_prelude {
|
||||
/// }
|
||||
///
|
||||
/// #[pallet::event]
|
||||
/// #[pallet::metadata(BalanceOf<T> = "Balance", u32 = "Other")]
|
||||
/// #[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
/// pub enum Event<T: Config<I>, I: 'static = ()> {
|
||||
/// /// doc comment put in metadata
|
||||
@@ -2342,8 +2297,7 @@ pub mod pallet_prelude {
|
||||
/// 7. **migrate event**:
|
||||
/// rewrite as a simple enum under with the attribute `#[pallet::event]`,
|
||||
/// use `#[pallet::generate_deposit($vis fn deposit_event)]` to generate deposit_event,
|
||||
/// use `#[pallet::metadata(...)]` to configure the metadata for types in order not to break
|
||||
/// them. 8. **migrate error**: rewrite it with attribute `#[pallet::error]`.
|
||||
/// 8. **migrate error**: rewrite it with attribute `#[pallet::error]`.
|
||||
/// 9. **migrate storage**:
|
||||
/// decl_storage provide an upgrade template (see 3.). All storages, genesis config, genesis
|
||||
/// build and default implementation of genesis config can be taken from it directly.
|
||||
|
||||
@@ -31,7 +31,8 @@ use sp_std::{
|
||||
///
|
||||
/// Unlike a standard `BTreeMap`, there is an enforced upper limit to the number of items in the
|
||||
/// map. All internal operations ensure this bound is respected.
|
||||
#[derive(Encode)]
|
||||
#[derive(Encode, scale_info::TypeInfo)]
|
||||
#[scale_info(skip_type_params(S))]
|
||||
pub struct BoundedBTreeMap<K, V, S>(BTreeMap<K, V>, PhantomData<S>);
|
||||
|
||||
impl<K, V, S> Decode for BoundedBTreeMap<K, V, S>
|
||||
|
||||
@@ -37,7 +37,8 @@ use sp_std::{convert::TryFrom, fmt, marker::PhantomData, prelude::*};
|
||||
///
|
||||
/// As the name suggests, the length of the queue is always bounded. All internal operations ensure
|
||||
/// this bound is respected.
|
||||
#[derive(Encode)]
|
||||
#[derive(Encode, scale_info::TypeInfo)]
|
||||
#[scale_info(skip_type_params(S))]
|
||||
pub struct BoundedVec<T, S>(Vec<T>, PhantomData<S>);
|
||||
|
||||
/// A bounded slice.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
//! Stuff to do with the runtime's storage.
|
||||
|
||||
pub use self::types::StorageEntryMetadata;
|
||||
use crate::{
|
||||
hash::{ReversibleStorageHasher, StorageHasher},
|
||||
storage::types::{
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
//! StoragePrefixedDoubleMap traits and their methods directly.
|
||||
|
||||
use crate::{
|
||||
metadata::{StorageEntryModifier, StorageEntryType},
|
||||
storage::{
|
||||
types::{OnEmptyGetter, OptionQuery, QueryKindTrait},
|
||||
types::{OptionQuery, QueryKindTrait, StorageEntryMetadata},
|
||||
StorageAppend, StorageDecodeLength, StoragePrefixedMap, StorageTryAppend,
|
||||
},
|
||||
traits::{Get, GetDefault, StorageInfo, StorageInstance},
|
||||
};
|
||||
use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen};
|
||||
use frame_metadata::{DefaultByteGetter, StorageEntryModifier};
|
||||
use sp_arithmetic::traits::SaturatedConversion;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
@@ -511,37 +511,34 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Part of storage metadata for a storage double map.
|
||||
///
|
||||
/// NOTE: Generic hashers is supported.
|
||||
pub trait StorageDoubleMapMetadata {
|
||||
const MODIFIER: StorageEntryModifier;
|
||||
const NAME: &'static str;
|
||||
const DEFAULT: DefaultByteGetter;
|
||||
const HASHER1: frame_metadata::StorageHasher;
|
||||
const HASHER2: frame_metadata::StorageHasher;
|
||||
}
|
||||
|
||||
impl<Prefix, Hasher1, Hasher2, Key1, Key2, Value, QueryKind, OnEmpty, MaxValues>
|
||||
StorageDoubleMapMetadata
|
||||
StorageEntryMetadata
|
||||
for StorageDoubleMap<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty, MaxValues>
|
||||
where
|
||||
Prefix: StorageInstance,
|
||||
Hasher1: crate::hash::StorageHasher,
|
||||
Hasher2: crate::hash::StorageHasher,
|
||||
Key1: FullCodec,
|
||||
Key2: FullCodec,
|
||||
Value: FullCodec,
|
||||
Key1: FullCodec + scale_info::StaticTypeInfo,
|
||||
Key2: FullCodec + scale_info::StaticTypeInfo,
|
||||
Value: FullCodec + scale_info::StaticTypeInfo,
|
||||
QueryKind: QueryKindTrait<Value, OnEmpty>,
|
||||
OnEmpty: Get<QueryKind::Query> + 'static,
|
||||
MaxValues: Get<Option<u32>>,
|
||||
{
|
||||
const MODIFIER: StorageEntryModifier = QueryKind::METADATA;
|
||||
const HASHER1: frame_metadata::StorageHasher = Hasher1::METADATA;
|
||||
const HASHER2: frame_metadata::StorageHasher = Hasher2::METADATA;
|
||||
const NAME: &'static str = Prefix::STORAGE_PREFIX;
|
||||
const DEFAULT: DefaultByteGetter =
|
||||
DefaultByteGetter(&OnEmptyGetter::<QueryKind::Query, OnEmpty>(core::marker::PhantomData));
|
||||
|
||||
fn ty() -> StorageEntryType {
|
||||
StorageEntryType::Map {
|
||||
hashers: vec![Hasher1::METADATA, Hasher2::METADATA],
|
||||
key: scale_info::meta_type::<(Key1, Key2)>(),
|
||||
value: scale_info::meta_type::<Value>(),
|
||||
}
|
||||
}
|
||||
|
||||
fn default() -> Vec<u8> {
|
||||
OnEmpty::get().encode()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Prefix, Hasher1, Hasher2, Key1, Key2, Value, QueryKind, OnEmpty, MaxValues>
|
||||
@@ -603,8 +600,12 @@ where
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::{hash::*, storage::types::ValueQuery};
|
||||
use frame_metadata::StorageEntryModifier;
|
||||
use crate::{
|
||||
hash::*,
|
||||
metadata::{StorageEntryModifier, StorageEntryType, StorageHasher},
|
||||
storage::types::ValueQuery,
|
||||
};
|
||||
use assert_matches::assert_matches;
|
||||
use sp_io::{hashing::twox_128, TestExternalities};
|
||||
|
||||
struct Prefix;
|
||||
@@ -768,19 +769,27 @@ mod test {
|
||||
|
||||
assert_eq!(A::MODIFIER, StorageEntryModifier::Optional);
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::MODIFIER, StorageEntryModifier::Default);
|
||||
assert_eq!(A::HASHER1, frame_metadata::StorageHasher::Blake2_128Concat);
|
||||
assert_eq!(A::HASHER2, frame_metadata::StorageHasher::Twox64Concat);
|
||||
assert_eq!(
|
||||
AValueQueryWithAnOnEmpty::HASHER1,
|
||||
frame_metadata::StorageHasher::Blake2_128Concat
|
||||
|
||||
let assert_map_hashers = |ty, expected_hashers| {
|
||||
if let StorageEntryType::Map { hashers, .. } = ty {
|
||||
assert_eq!(hashers, expected_hashers)
|
||||
} else {
|
||||
assert_matches!(ty, StorageEntryType::Map { .. })
|
||||
}
|
||||
};
|
||||
|
||||
assert_map_hashers(
|
||||
A::ty(),
|
||||
vec![StorageHasher::Blake2_128Concat, StorageHasher::Twox64Concat],
|
||||
);
|
||||
assert_eq!(
|
||||
AValueQueryWithAnOnEmpty::HASHER2,
|
||||
frame_metadata::StorageHasher::Twox64Concat
|
||||
assert_map_hashers(
|
||||
AValueQueryWithAnOnEmpty::ty(),
|
||||
vec![StorageHasher::Blake2_128Concat, StorageHasher::Twox64Concat],
|
||||
);
|
||||
|
||||
assert_eq!(A::NAME, "foo");
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::DEFAULT.0.default_byte(), 97u32.encode());
|
||||
assert_eq!(A::DEFAULT.0.default_byte(), Option::<u32>::None.encode());
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::default(), 97u32.encode());
|
||||
assert_eq!(A::default(), Option::<u32>::None.encode());
|
||||
|
||||
WithLen::remove_all(None);
|
||||
assert_eq!(WithLen::decode_len(3, 30), None);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
use crate::hash::{ReversibleStorageHasher, StorageHasher};
|
||||
use codec::{Encode, EncodeLike, FullCodec, MaxEncodedLen};
|
||||
use paste::paste;
|
||||
use scale_info::StaticTypeInfo;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// A type used exclusively by storage maps as their key type.
|
||||
@@ -35,14 +36,14 @@ pub struct Key<Hasher, KeyType>(core::marker::PhantomData<(Hasher, KeyType)>);
|
||||
|
||||
/// A trait that contains the current key as an associated type.
|
||||
pub trait KeyGenerator {
|
||||
type Key: EncodeLike<Self::Key>;
|
||||
type Key: EncodeLike<Self::Key> + StaticTypeInfo;
|
||||
type KArg: Encode;
|
||||
type HashFn: FnOnce(&[u8]) -> Vec<u8>;
|
||||
type HArg;
|
||||
|
||||
const HASHER_METADATA: &'static [frame_metadata::StorageHasher];
|
||||
const HASHER_METADATA: &'static [crate::metadata::StorageHasher];
|
||||
|
||||
/// Given a `key` tuple, calculate the final key by encoding each element individuallly and
|
||||
/// Given a `key` tuple, calculate the final key by encoding each element individually and
|
||||
/// hashing them using the corresponding hasher in the `KeyGenerator`.
|
||||
fn final_key<KArg: EncodeLikeTuple<Self::KArg> + TupleToEncodedIter>(key: KArg) -> Vec<u8>;
|
||||
/// Given a `key` tuple, migrate the keys from using the old hashers as given by `hash_fns`
|
||||
@@ -67,13 +68,13 @@ pub trait KeyGeneratorInner: KeyGenerator {
|
||||
fn final_hash(encoded: &[u8]) -> Vec<u8>;
|
||||
}
|
||||
|
||||
impl<H: StorageHasher, K: FullCodec> KeyGenerator for Key<H, K> {
|
||||
impl<H: StorageHasher, K: FullCodec + StaticTypeInfo> KeyGenerator for Key<H, K> {
|
||||
type Key = K;
|
||||
type KArg = (K,);
|
||||
type HashFn = Box<dyn FnOnce(&[u8]) -> Vec<u8>>;
|
||||
type HArg = (Self::HashFn,);
|
||||
|
||||
const HASHER_METADATA: &'static [frame_metadata::StorageHasher] = &[H::METADATA];
|
||||
const HASHER_METADATA: &'static [crate::metadata::StorageHasher] = &[H::METADATA];
|
||||
|
||||
fn final_key<KArg: EncodeLikeTuple<Self::KArg> + TupleToEncodedIter>(key: KArg) -> Vec<u8> {
|
||||
H::hash(&key.to_encoded_iter().next().expect("should have at least one element!"))
|
||||
@@ -89,13 +90,15 @@ impl<H: StorageHasher, K: FullCodec> KeyGenerator for Key<H, K> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<H: StorageHasher, K: FullCodec + MaxEncodedLen> KeyGeneratorMaxEncodedLen for Key<H, K> {
|
||||
impl<H: StorageHasher, K: FullCodec + MaxEncodedLen + StaticTypeInfo> KeyGeneratorMaxEncodedLen
|
||||
for Key<H, K>
|
||||
{
|
||||
fn key_max_encoded_len() -> usize {
|
||||
H::max_len::<K>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<H: StorageHasher, K: FullCodec> KeyGeneratorInner for Key<H, K> {
|
||||
impl<H: StorageHasher, K: FullCodec + StaticTypeInfo> KeyGeneratorInner for Key<H, K> {
|
||||
type Hasher = H;
|
||||
|
||||
fn final_hash(encoded: &[u8]) -> Vec<u8> {
|
||||
@@ -111,7 +114,7 @@ impl KeyGenerator for Tuple {
|
||||
for_tuples!( type HArg = ( #(Tuple::HashFn),* ); );
|
||||
type HashFn = Box<dyn FnOnce(&[u8]) -> Vec<u8>>;
|
||||
|
||||
const HASHER_METADATA: &'static [frame_metadata::StorageHasher] =
|
||||
const HASHER_METADATA: &'static [crate::metadata::StorageHasher] =
|
||||
&[for_tuples!( #(Tuple::Hasher::METADATA),* )];
|
||||
|
||||
fn final_key<KArg: EncodeLikeTuple<Self::KArg> + TupleToEncodedIter>(key: KArg) -> Vec<u8> {
|
||||
@@ -218,7 +221,9 @@ pub trait ReversibleKeyGenerator: KeyGenerator {
|
||||
fn decode_final_key(key_material: &[u8]) -> Result<(Self::Key, &[u8]), codec::Error>;
|
||||
}
|
||||
|
||||
impl<H: ReversibleStorageHasher, K: FullCodec> ReversibleKeyGenerator for Key<H, K> {
|
||||
impl<H: ReversibleStorageHasher, K: FullCodec + StaticTypeInfo> ReversibleKeyGenerator
|
||||
for Key<H, K>
|
||||
{
|
||||
type ReversibleHasher = H;
|
||||
|
||||
fn decode_final_key(key_material: &[u8]) -> Result<(Self::Key, &[u8]), codec::Error> {
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
//! methods directly.
|
||||
|
||||
use crate::{
|
||||
metadata::{StorageEntryModifier, StorageEntryType},
|
||||
storage::{
|
||||
types::{OnEmptyGetter, OptionQuery, QueryKindTrait},
|
||||
types::{OptionQuery, QueryKindTrait, StorageEntryMetadata},
|
||||
StorageAppend, StorageDecodeLength, StoragePrefixedMap, StorageTryAppend,
|
||||
},
|
||||
traits::{Get, GetDefault, StorageInfo, StorageInstance},
|
||||
};
|
||||
use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen};
|
||||
use frame_metadata::{DefaultByteGetter, StorageEntryModifier};
|
||||
use sp_arithmetic::traits::SaturatedConversion;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
@@ -336,32 +336,31 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Part of storage metadata for a storage map.
|
||||
///
|
||||
/// NOTE: Generic hasher is supported.
|
||||
pub trait StorageMapMetadata {
|
||||
const MODIFIER: StorageEntryModifier;
|
||||
const NAME: &'static str;
|
||||
const DEFAULT: DefaultByteGetter;
|
||||
const HASHER: frame_metadata::StorageHasher;
|
||||
}
|
||||
|
||||
impl<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues> StorageMapMetadata
|
||||
impl<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues> StorageEntryMetadata
|
||||
for StorageMap<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues>
|
||||
where
|
||||
Prefix: StorageInstance,
|
||||
Hasher: crate::hash::StorageHasher,
|
||||
Key: FullCodec,
|
||||
Value: FullCodec,
|
||||
Key: FullCodec + scale_info::StaticTypeInfo,
|
||||
Value: FullCodec + scale_info::StaticTypeInfo,
|
||||
QueryKind: QueryKindTrait<Value, OnEmpty>,
|
||||
OnEmpty: Get<QueryKind::Query> + 'static,
|
||||
MaxValues: Get<Option<u32>>,
|
||||
{
|
||||
const MODIFIER: StorageEntryModifier = QueryKind::METADATA;
|
||||
const HASHER: frame_metadata::StorageHasher = Hasher::METADATA;
|
||||
const NAME: &'static str = Prefix::STORAGE_PREFIX;
|
||||
const DEFAULT: DefaultByteGetter =
|
||||
DefaultByteGetter(&OnEmptyGetter::<QueryKind::Query, OnEmpty>(core::marker::PhantomData));
|
||||
|
||||
fn ty() -> StorageEntryType {
|
||||
StorageEntryType::Map {
|
||||
hashers: vec![Hasher::METADATA],
|
||||
key: scale_info::meta_type::<Key>(),
|
||||
value: scale_info::meta_type::<Value>(),
|
||||
}
|
||||
}
|
||||
|
||||
fn default() -> Vec<u8> {
|
||||
OnEmpty::get().encode()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues> crate::traits::StorageInfoTrait
|
||||
@@ -417,8 +416,12 @@ where
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::{hash::*, storage::types::ValueQuery};
|
||||
use frame_metadata::StorageEntryModifier;
|
||||
use crate::{
|
||||
hash::*,
|
||||
metadata::{StorageEntryModifier, StorageEntryType, StorageHasher},
|
||||
storage::types::ValueQuery,
|
||||
};
|
||||
use assert_matches::assert_matches;
|
||||
use sp_io::{hashing::twox_128, TestExternalities};
|
||||
|
||||
struct Prefix;
|
||||
@@ -572,14 +575,23 @@ mod test {
|
||||
|
||||
assert_eq!(A::MODIFIER, StorageEntryModifier::Optional);
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::MODIFIER, StorageEntryModifier::Default);
|
||||
assert_eq!(A::HASHER, frame_metadata::StorageHasher::Blake2_128Concat);
|
||||
assert_eq!(
|
||||
AValueQueryWithAnOnEmpty::HASHER,
|
||||
frame_metadata::StorageHasher::Blake2_128Concat
|
||||
|
||||
let assert_map_hashers = |ty, expected_hashers| {
|
||||
if let StorageEntryType::Map { hashers, .. } = ty {
|
||||
assert_eq!(hashers, expected_hashers)
|
||||
} else {
|
||||
assert_matches!(ty, StorageEntryType::Map { .. })
|
||||
}
|
||||
};
|
||||
|
||||
assert_map_hashers(A::ty(), vec![StorageHasher::Blake2_128Concat]);
|
||||
assert_map_hashers(
|
||||
AValueQueryWithAnOnEmpty::ty(),
|
||||
vec![StorageHasher::Blake2_128Concat],
|
||||
);
|
||||
assert_eq!(A::NAME, "foo");
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::DEFAULT.0.default_byte(), 97u32.encode());
|
||||
assert_eq!(A::DEFAULT.0.default_byte(), Option::<u32>::None.encode());
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::default(), 97u32.encode());
|
||||
assert_eq!(A::default(), Option::<u32>::None.encode());
|
||||
|
||||
WithLen::remove_all(None);
|
||||
assert_eq!(WithLen::decode_len(3), None);
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
//! Storage types to build abstraction on storage, they implements storage traits such as
|
||||
//! StorageMap and others.
|
||||
|
||||
use crate::metadata::{StorageEntryModifier, StorageEntryType};
|
||||
use codec::FullCodec;
|
||||
use frame_metadata::{DefaultByte, StorageEntryModifier};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
mod double_map;
|
||||
mod key;
|
||||
@@ -27,14 +28,14 @@ mod map;
|
||||
mod nmap;
|
||||
mod value;
|
||||
|
||||
pub use double_map::{StorageDoubleMap, StorageDoubleMapMetadata};
|
||||
pub use double_map::StorageDoubleMap;
|
||||
pub use key::{
|
||||
EncodeLikeTuple, HasKeyPrefix, HasReversibleKeyPrefix, Key, KeyGenerator,
|
||||
KeyGeneratorMaxEncodedLen, ReversibleKeyGenerator, TupleToEncodedIter,
|
||||
};
|
||||
pub use map::{StorageMap, StorageMapMetadata};
|
||||
pub use nmap::{StorageNMap, StorageNMapMetadata};
|
||||
pub use value::{StorageValue, StorageValueMetadata};
|
||||
pub use map::StorageMap;
|
||||
pub use nmap::StorageNMap;
|
||||
pub use value::StorageValue;
|
||||
|
||||
/// Trait implementing how the storage optional value is converted into the queried type.
|
||||
///
|
||||
@@ -102,14 +103,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// A helper struct which implements DefaultByte using `Get<Value>` and encode it.
|
||||
struct OnEmptyGetter<Value, OnEmpty>(core::marker::PhantomData<(Value, OnEmpty)>);
|
||||
impl<Value: FullCodec, OnEmpty: crate::traits::Get<Value>> DefaultByte
|
||||
for OnEmptyGetter<Value, OnEmpty>
|
||||
{
|
||||
fn default_byte(&self) -> sp_std::vec::Vec<u8> {
|
||||
OnEmpty::get().encode()
|
||||
}
|
||||
/// Provide metadata for a storage entry.
|
||||
///
|
||||
/// Implemented by each of the storage entry kinds: value, map, doublemap and nmap.
|
||||
pub trait StorageEntryMetadata {
|
||||
const MODIFIER: StorageEntryModifier;
|
||||
const NAME: &'static str;
|
||||
|
||||
fn ty() -> StorageEntryType;
|
||||
fn default() -> Vec<u8>;
|
||||
}
|
||||
unsafe impl<Value, OnEmpty: crate::traits::Get<Value>> Send for OnEmptyGetter<Value, OnEmpty> {}
|
||||
unsafe impl<Value, OnEmpty: crate::traits::Get<Value>> Sync for OnEmptyGetter<Value, OnEmpty> {}
|
||||
|
||||
@@ -19,17 +19,17 @@
|
||||
//! StoragePrefixedDoubleMap traits and their methods directly.
|
||||
|
||||
use crate::{
|
||||
metadata::{StorageEntryModifier, StorageEntryType},
|
||||
storage::{
|
||||
types::{
|
||||
EncodeLikeTuple, HasKeyPrefix, HasReversibleKeyPrefix, OnEmptyGetter, OptionQuery,
|
||||
QueryKindTrait, TupleToEncodedIter,
|
||||
EncodeLikeTuple, HasKeyPrefix, HasReversibleKeyPrefix, OptionQuery, QueryKindTrait,
|
||||
StorageEntryMetadata, TupleToEncodedIter,
|
||||
},
|
||||
KeyGenerator, PrefixIterator, StorageAppend, StorageDecodeLength, StoragePrefixedMap,
|
||||
},
|
||||
traits::{Get, GetDefault, StorageInfo, StorageInstance},
|
||||
};
|
||||
use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen};
|
||||
use frame_metadata::{DefaultByteGetter, StorageEntryModifier};
|
||||
use sp_runtime::SaturatedConversion;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
@@ -440,31 +440,30 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Part of storage metadata for a storage n map.
|
||||
///
|
||||
/// NOTE: Generic hashers is supported.
|
||||
pub trait StorageNMapMetadata {
|
||||
const MODIFIER: StorageEntryModifier;
|
||||
const NAME: &'static str;
|
||||
const DEFAULT: DefaultByteGetter;
|
||||
const HASHERS: &'static [frame_metadata::StorageHasher];
|
||||
}
|
||||
|
||||
impl<Prefix, Key, Value, QueryKind, OnEmpty, MaxValues> StorageNMapMetadata
|
||||
impl<Prefix, Key, Value, QueryKind, OnEmpty, MaxValues> StorageEntryMetadata
|
||||
for StorageNMap<Prefix, Key, Value, QueryKind, OnEmpty, MaxValues>
|
||||
where
|
||||
Prefix: StorageInstance,
|
||||
Key: super::key::KeyGenerator,
|
||||
Value: FullCodec,
|
||||
Value: FullCodec + scale_info::StaticTypeInfo,
|
||||
QueryKind: QueryKindTrait<Value, OnEmpty>,
|
||||
OnEmpty: Get<QueryKind::Query> + 'static,
|
||||
MaxValues: Get<Option<u32>>,
|
||||
{
|
||||
const MODIFIER: StorageEntryModifier = QueryKind::METADATA;
|
||||
const NAME: &'static str = Prefix::STORAGE_PREFIX;
|
||||
const DEFAULT: DefaultByteGetter =
|
||||
DefaultByteGetter(&OnEmptyGetter::<QueryKind::Query, OnEmpty>(core::marker::PhantomData));
|
||||
const HASHERS: &'static [frame_metadata::StorageHasher] = Key::HASHER_METADATA;
|
||||
|
||||
fn ty() -> StorageEntryType {
|
||||
StorageEntryType::Map {
|
||||
key: scale_info::meta_type::<Key::Key>(),
|
||||
hashers: Key::HASHER_METADATA.iter().cloned().collect(),
|
||||
value: scale_info::meta_type::<Value>(),
|
||||
}
|
||||
}
|
||||
|
||||
fn default() -> Vec<u8> {
|
||||
OnEmpty::get().encode()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Prefix, Key, Value, QueryKind, OnEmpty, MaxValues> crate::traits::StorageInfoTrait
|
||||
@@ -518,9 +517,9 @@ mod test {
|
||||
use super::*;
|
||||
use crate::{
|
||||
hash::*,
|
||||
metadata::StorageEntryModifier,
|
||||
storage::types::{Key, ValueQuery},
|
||||
};
|
||||
use frame_metadata::StorageEntryModifier;
|
||||
use sp_io::{hashing::twox_128, TestExternalities};
|
||||
|
||||
struct Prefix;
|
||||
@@ -688,8 +687,8 @@ mod test {
|
||||
assert_eq!(A::MODIFIER, StorageEntryModifier::Optional);
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::MODIFIER, StorageEntryModifier::Default);
|
||||
assert_eq!(A::NAME, "Foo");
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::DEFAULT.0.default_byte(), 98u32.encode());
|
||||
assert_eq!(A::DEFAULT.0.default_byte(), Option::<u32>::None.encode());
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::default(), 98u32.encode());
|
||||
assert_eq!(A::default(), Option::<u32>::None.encode());
|
||||
|
||||
WithLen::remove_all(None);
|
||||
assert_eq!(WithLen::decode_len((3,)), None);
|
||||
@@ -856,8 +855,8 @@ mod test {
|
||||
assert_eq!(A::MODIFIER, StorageEntryModifier::Optional);
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::MODIFIER, StorageEntryModifier::Default);
|
||||
assert_eq!(A::NAME, "Foo");
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::DEFAULT.0.default_byte(), 98u32.encode());
|
||||
assert_eq!(A::DEFAULT.0.default_byte(), Option::<u32>::None.encode());
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::default(), 98u32.encode());
|
||||
assert_eq!(A::default(), Option::<u32>::None.encode());
|
||||
|
||||
WithLen::remove_all(None);
|
||||
assert_eq!(WithLen::decode_len((3, 30)), None);
|
||||
@@ -1046,8 +1045,8 @@ mod test {
|
||||
assert_eq!(A::MODIFIER, StorageEntryModifier::Optional);
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::MODIFIER, StorageEntryModifier::Default);
|
||||
assert_eq!(A::NAME, "Foo");
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::DEFAULT.0.default_byte(), 98u32.encode());
|
||||
assert_eq!(A::DEFAULT.0.default_byte(), Option::<u32>::None.encode());
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::default(), 98u32.encode());
|
||||
assert_eq!(A::default(), Option::<u32>::None.encode());
|
||||
|
||||
WithLen::remove_all(None);
|
||||
assert_eq!(WithLen::decode_len((3, 30, 300)), None);
|
||||
|
||||
@@ -18,15 +18,15 @@
|
||||
//! Storage value type. Implements StorageValue trait and its method directly.
|
||||
|
||||
use crate::{
|
||||
metadata::{StorageEntryModifier, StorageEntryType},
|
||||
storage::{
|
||||
generator::StorageValue as StorageValueT,
|
||||
types::{OnEmptyGetter, OptionQuery, QueryKindTrait},
|
||||
types::{OptionQuery, QueryKindTrait, StorageEntryMetadata},
|
||||
StorageAppend, StorageDecodeLength, StorageTryAppend,
|
||||
},
|
||||
traits::{GetDefault, StorageInfo, StorageInstance},
|
||||
};
|
||||
use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen};
|
||||
use frame_metadata::{DefaultByteGetter, StorageEntryModifier};
|
||||
use sp_arithmetic::traits::SaturatedConversion;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
@@ -201,25 +201,24 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Part of storage metadata for storage value.
|
||||
pub trait StorageValueMetadata {
|
||||
const MODIFIER: StorageEntryModifier;
|
||||
const NAME: &'static str;
|
||||
const DEFAULT: DefaultByteGetter;
|
||||
}
|
||||
|
||||
impl<Prefix, Value, QueryKind, OnEmpty> StorageValueMetadata
|
||||
impl<Prefix, Value, QueryKind, OnEmpty> StorageEntryMetadata
|
||||
for StorageValue<Prefix, Value, QueryKind, OnEmpty>
|
||||
where
|
||||
Prefix: StorageInstance,
|
||||
Value: FullCodec,
|
||||
Value: FullCodec + scale_info::StaticTypeInfo,
|
||||
QueryKind: QueryKindTrait<Value, OnEmpty>,
|
||||
OnEmpty: crate::traits::Get<QueryKind::Query> + 'static,
|
||||
{
|
||||
const MODIFIER: StorageEntryModifier = QueryKind::METADATA;
|
||||
const NAME: &'static str = Prefix::STORAGE_PREFIX;
|
||||
const DEFAULT: DefaultByteGetter =
|
||||
DefaultByteGetter(&OnEmptyGetter::<QueryKind::Query, OnEmpty>(core::marker::PhantomData));
|
||||
|
||||
fn ty() -> StorageEntryType {
|
||||
StorageEntryType::Plain(scale_info::meta_type::<Value>())
|
||||
}
|
||||
|
||||
fn default() -> Vec<u8> {
|
||||
OnEmpty::get().encode()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Prefix, Value, QueryKind, OnEmpty> crate::traits::StorageInfoTrait
|
||||
@@ -264,8 +263,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::storage::types::ValueQuery;
|
||||
use frame_metadata::StorageEntryModifier;
|
||||
use crate::{metadata::StorageEntryModifier, storage::types::ValueQuery};
|
||||
use sp_io::{hashing::twox_128, TestExternalities};
|
||||
|
||||
struct Prefix;
|
||||
@@ -347,8 +345,8 @@ mod test {
|
||||
assert_eq!(A::MODIFIER, StorageEntryModifier::Optional);
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::MODIFIER, StorageEntryModifier::Default);
|
||||
assert_eq!(A::NAME, "foo");
|
||||
assert_eq!(A::DEFAULT.0.default_byte(), Option::<u32>::None.encode());
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::DEFAULT.0.default_byte(), 97u32.encode());
|
||||
assert_eq!(A::default(), Option::<u32>::None.encode());
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::default(), 97u32.encode());
|
||||
|
||||
WithLen::kill();
|
||||
assert_eq!(WithLen::decode_len(), None);
|
||||
|
||||
@@ -36,7 +36,8 @@ use sp_std::{convert::TryFrom, fmt, marker::PhantomData, prelude::*};
|
||||
///
|
||||
/// The length of the vec is not strictly bounded. Decoding a vec with more element that the bound
|
||||
/// is accepted, and some method allow to bypass the restriction with warnings.
|
||||
#[derive(Encode)]
|
||||
#[derive(Encode, scale_info::TypeInfo)]
|
||||
#[scale_info(skip_type_params(S))]
|
||||
pub struct WeakBoundedVec<T, S>(Vec<T>, PhantomData<S>);
|
||||
|
||||
impl<T: Decode, S: Get<u32>> Decode for WeakBoundedVec<T, S> {
|
||||
|
||||
@@ -116,7 +116,7 @@ pub enum ExistenceRequirement {
|
||||
}
|
||||
|
||||
/// Status of funds.
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug)]
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)]
|
||||
pub enum BalanceStatus {
|
||||
/// Funds are free, as corresponding to `free` item in Balances.
|
||||
Free,
|
||||
@@ -165,8 +165,14 @@ pub trait AssetId: FullCodec + Copy + Eq + PartialEq + Debug {}
|
||||
impl<T: FullCodec + Copy + Eq + PartialEq + Debug> AssetId for T {}
|
||||
|
||||
/// Simple amalgamation trait to collect together properties for a Balance under one roof.
|
||||
pub trait Balance: AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug {}
|
||||
impl<T: AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug> Balance for T {}
|
||||
pub trait Balance:
|
||||
AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug + scale_info::TypeInfo
|
||||
{
|
||||
}
|
||||
impl<T: AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug + scale_info::TypeInfo> Balance
|
||||
for T
|
||||
{
|
||||
}
|
||||
|
||||
/// Converts a balance value into an asset balance.
|
||||
pub trait BalanceConversion<InBalance, AssetId, OutBalance> {
|
||||
|
||||
@@ -129,6 +129,7 @@
|
||||
|
||||
use crate::dispatch::{DispatchError, DispatchErrorWithPostInfo, DispatchResultWithPostInfo};
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
@@ -201,7 +202,7 @@ pub trait PaysFee<T> {
|
||||
}
|
||||
|
||||
/// Explicit enum to denote if a transaction pays fee or not.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, RuntimeDebug, Encode, Decode)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, RuntimeDebug, Encode, Decode, TypeInfo)]
|
||||
pub enum Pays {
|
||||
/// Transactor will pay related fees.
|
||||
Yes,
|
||||
@@ -221,7 +222,7 @@ impl Default for Pays {
|
||||
/// [DispatchClass::all] and [DispatchClass::non_mandatory] helper functions.
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug)]
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||
pub enum DispatchClass {
|
||||
/// A normal dispatch.
|
||||
Normal,
|
||||
@@ -311,7 +312,7 @@ pub mod priority {
|
||||
}
|
||||
|
||||
/// A bundle of static information collected from the `#[weight = $x]` attributes.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)]
|
||||
pub struct DispatchInfo {
|
||||
/// Weight of this transaction.
|
||||
pub weight: Weight,
|
||||
@@ -338,7 +339,7 @@ impl GetDispatchInfo for () {
|
||||
|
||||
/// Weight information that is only available post dispatch.
|
||||
/// NOTE: This can only be used to reduce the weight or fee, not increase it.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)]
|
||||
pub struct PostDispatchInfo {
|
||||
/// Actual weight consumed by a call or `None` which stands for the worst case static weight.
|
||||
pub actual_weight: Option<Weight>,
|
||||
@@ -627,7 +628,7 @@ impl<Call: Encode, Extra: Encode> GetDispatchInfo for sp_runtime::testing::TestX
|
||||
}
|
||||
|
||||
/// The weight of database operations that the runtime can invoke.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)]
|
||||
pub struct RuntimeDbWeight {
|
||||
pub read: Weight,
|
||||
pub write: Weight,
|
||||
@@ -659,7 +660,7 @@ impl RuntimeDbWeight {
|
||||
///
|
||||
/// The `negative` value encodes whether the term is added or substracted from the
|
||||
/// overall polynomial result.
|
||||
#[derive(Clone, Encode, Decode)]
|
||||
#[derive(Clone, Encode, Decode, TypeInfo)]
|
||||
pub struct WeightToFeeCoefficient<Balance> {
|
||||
/// The integral part of the coefficient.
|
||||
pub coeff_integer: Balance,
|
||||
@@ -737,7 +738,7 @@ where
|
||||
}
|
||||
|
||||
/// A struct holding value for each `DispatchClass`.
|
||||
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode)]
|
||||
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)]
|
||||
pub struct PerDispatchClass<T> {
|
||||
/// Value for `Normal` extrinsics.
|
||||
normal: T,
|
||||
@@ -882,49 +883,49 @@ mod tests {
|
||||
#[test]
|
||||
fn weights_are_correct() {
|
||||
// #[weight = 1000]
|
||||
let info = Call::<TraitImpl>::f00().get_dispatch_info();
|
||||
let info = Call::<TraitImpl>::f00 {}.get_dispatch_info();
|
||||
assert_eq!(info.weight, 1000);
|
||||
assert_eq!(info.class, DispatchClass::Normal);
|
||||
assert_eq!(info.pays_fee, Pays::Yes);
|
||||
|
||||
// #[weight = (1000, DispatchClass::Mandatory)]
|
||||
let info = Call::<TraitImpl>::f01().get_dispatch_info();
|
||||
let info = Call::<TraitImpl>::f01 {}.get_dispatch_info();
|
||||
assert_eq!(info.weight, 1000);
|
||||
assert_eq!(info.class, DispatchClass::Mandatory);
|
||||
assert_eq!(info.pays_fee, Pays::Yes);
|
||||
|
||||
// #[weight = (1000, Pays::No)]
|
||||
let info = Call::<TraitImpl>::f02().get_dispatch_info();
|
||||
let info = Call::<TraitImpl>::f02 {}.get_dispatch_info();
|
||||
assert_eq!(info.weight, 1000);
|
||||
assert_eq!(info.class, DispatchClass::Normal);
|
||||
assert_eq!(info.pays_fee, Pays::No);
|
||||
|
||||
// #[weight = (1000, DispatchClass::Operational, Pays::No)]
|
||||
let info = Call::<TraitImpl>::f03().get_dispatch_info();
|
||||
let info = Call::<TraitImpl>::f03 {}.get_dispatch_info();
|
||||
assert_eq!(info.weight, 1000);
|
||||
assert_eq!(info.class, DispatchClass::Operational);
|
||||
assert_eq!(info.pays_fee, Pays::No);
|
||||
|
||||
// #[weight = ((_a * 10 + _eb * 1) as Weight, DispatchClass::Normal, Pays::Yes)]
|
||||
let info = Call::<TraitImpl>::f11(13, 20).get_dispatch_info();
|
||||
let info = Call::<TraitImpl>::f11 { _a: 13, _eb: 20 }.get_dispatch_info();
|
||||
assert_eq!(info.weight, 150); // 13*10 + 20
|
||||
assert_eq!(info.class, DispatchClass::Normal);
|
||||
assert_eq!(info.pays_fee, Pays::Yes);
|
||||
|
||||
// #[weight = (0, DispatchClass::Operational, Pays::Yes)]
|
||||
let info = Call::<TraitImpl>::f12(10, 20).get_dispatch_info();
|
||||
let info = Call::<TraitImpl>::f12 { _a: 10, _eb: 20 }.get_dispatch_info();
|
||||
assert_eq!(info.weight, 0);
|
||||
assert_eq!(info.class, DispatchClass::Operational);
|
||||
assert_eq!(info.pays_fee, Pays::Yes);
|
||||
|
||||
// #[weight = T::DbWeight::get().reads(3) + T::DbWeight::get().writes(2) + 10_000]
|
||||
let info = Call::<TraitImpl>::f20().get_dispatch_info();
|
||||
let info = Call::<TraitImpl>::f20 {}.get_dispatch_info();
|
||||
assert_eq!(info.weight, 12300); // 100*3 + 1000*2 + 10_1000
|
||||
assert_eq!(info.class, DispatchClass::Normal);
|
||||
assert_eq!(info.pays_fee, Pays::Yes);
|
||||
|
||||
// #[weight = T::DbWeight::get().reads_writes(6, 5) + 40_000]
|
||||
let info = Call::<TraitImpl>::f21().get_dispatch_info();
|
||||
let info = Call::<TraitImpl>::f21 {}.get_dispatch_info();
|
||||
assert_eq!(info.weight, 45600); // 100*6 + 1000*5 + 40_1000
|
||||
assert_eq!(info.class, DispatchClass::Normal);
|
||||
assert_eq!(info.pays_fee, Pays::Yes);
|
||||
|
||||
@@ -14,16 +14,18 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dependencies]
|
||||
serde = { version = "1.0.126", default-features = false, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
|
||||
sp-arithmetic = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/arithmetic" }
|
||||
sp-io = { version = "4.0.0-dev", path = "../../../primitives/io", default-features = false }
|
||||
sp-state-machine = { version = "0.10.0-dev", optional = true, path = "../../../primitives/state-machine" }
|
||||
frame-support = { version = "4.0.0-dev", default-features = false, path = "../" }
|
||||
sp-runtime = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/runtime" }
|
||||
sp-core = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/core" }
|
||||
sp-std = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/std" }
|
||||
sp-version = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/version" }
|
||||
trybuild = "1.0.43"
|
||||
pretty_assertions = "0.6.1"
|
||||
rustversion = "1.0.0"
|
||||
frame-metadata = { version = "14.0.0-dev", default-features = false, path = "../../metadata" }
|
||||
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" }
|
||||
# The "std" feature for this pallet is never activated on purpose, in order to test construct_runtime error message
|
||||
test-pallet = { package = "frame-support-test-pallet", default-features = false, path = "pallet" }
|
||||
@@ -33,6 +35,7 @@ default = ["std"]
|
||||
std = [
|
||||
"serde/std",
|
||||
"codec/std",
|
||||
"scale-info/std",
|
||||
"sp-io/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
|
||||
@@ -13,6 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
|
||||
frame-support = { version = "4.0.0-dev", default-features = false, path = "../../" }
|
||||
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../../system" }
|
||||
|
||||
@@ -20,6 +21,7 @@ frame-system = { version = "4.0.0-dev", default-features = false, path = "../../
|
||||
default = ["std"]
|
||||
std = [
|
||||
"codec/std",
|
||||
"scale-info/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
]
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
/// The configuration trait
|
||||
pub trait Config: 'static {
|
||||
/// The runtime origin type.
|
||||
type Origin: codec::Codec + codec::EncodeLike + Default;
|
||||
type Origin: codec::Codec + codec::EncodeLike + Default + scale_info::TypeInfo;
|
||||
/// The block number type.
|
||||
type BlockNumber: codec::Codec + codec::EncodeLike + Default;
|
||||
type BlockNumber: codec::Codec + codec::EncodeLike + Default + scale_info::TypeInfo;
|
||||
/// The information about the pallet setup in the runtime.
|
||||
type PalletInfo: frame_support::traits::PalletInfo;
|
||||
/// The db weights.
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#![recursion_limit = "128"]
|
||||
|
||||
use frame_support::traits::PalletInfo as _;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::{sr25519, H256};
|
||||
use sp_runtime::{
|
||||
generic,
|
||||
@@ -54,7 +55,7 @@ mod module1 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode)]
|
||||
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
|
||||
pub struct Origin<T, I: Instance = DefaultInstance>(pub core::marker::PhantomData<(T, I)>);
|
||||
|
||||
frame_support::decl_event! {
|
||||
@@ -96,7 +97,7 @@ mod module2 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode)]
|
||||
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
|
||||
pub struct Origin;
|
||||
|
||||
frame_support::decl_event! {
|
||||
@@ -139,7 +140,7 @@ mod nested {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode)]
|
||||
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
|
||||
pub struct Origin;
|
||||
|
||||
frame_support::decl_event! {
|
||||
@@ -195,7 +196,7 @@ pub mod module3 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode)]
|
||||
#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo)]
|
||||
pub struct Origin<T>(pub core::marker::PhantomData<T>);
|
||||
|
||||
frame_support::decl_event! {
|
||||
@@ -309,8 +310,8 @@ mod origin_test {
|
||||
|
||||
#[test]
|
||||
fn origin_default_filter() {
|
||||
let accepted_call = nested::module3::Call::fail().into();
|
||||
let rejected_call = module3::Call::fail().into();
|
||||
let accepted_call = nested::module3::Call::fail {}.into();
|
||||
let rejected_call = module3::Call::fail {}.into();
|
||||
|
||||
assert_eq!(Origin::root().filter_call(&accepted_call), true);
|
||||
assert_eq!(Origin::root().filter_call(&rejected_call), true);
|
||||
@@ -472,28 +473,28 @@ fn event_codec() {
|
||||
#[test]
|
||||
fn call_codec() {
|
||||
use codec::Encode;
|
||||
assert_eq!(Call::System(system::Call::noop()).encode()[0], 30);
|
||||
assert_eq!(Call::Module1_1(module1::Call::fail()).encode()[0], 31);
|
||||
assert_eq!(Call::Module2(module2::Call::fail()).encode()[0], 32);
|
||||
assert_eq!(Call::Module1_2(module1::Call::fail()).encode()[0], 33);
|
||||
assert_eq!(Call::NestedModule3(nested::module3::Call::fail()).encode()[0], 34);
|
||||
assert_eq!(Call::Module3(module3::Call::fail()).encode()[0], 35);
|
||||
assert_eq!(Call::Module1_4(module1::Call::fail()).encode()[0], 3);
|
||||
assert_eq!(Call::Module1_6(module1::Call::fail()).encode()[0], 1);
|
||||
assert_eq!(Call::Module1_7(module1::Call::fail()).encode()[0], 2);
|
||||
assert_eq!(Call::Module1_8(module1::Call::fail()).encode()[0], 12);
|
||||
assert_eq!(Call::Module1_9(module1::Call::fail()).encode()[0], 13);
|
||||
assert_eq!(Call::System(system::Call::noop {}).encode()[0], 30);
|
||||
assert_eq!(Call::Module1_1(module1::Call::fail {}).encode()[0], 31);
|
||||
assert_eq!(Call::Module2(module2::Call::fail {}).encode()[0], 32);
|
||||
assert_eq!(Call::Module1_2(module1::Call::fail {}).encode()[0], 33);
|
||||
assert_eq!(Call::NestedModule3(nested::module3::Call::fail {}).encode()[0], 34);
|
||||
assert_eq!(Call::Module3(module3::Call::fail {}).encode()[0], 35);
|
||||
assert_eq!(Call::Module1_4(module1::Call::fail {}).encode()[0], 3);
|
||||
assert_eq!(Call::Module1_6(module1::Call::fail {}).encode()[0], 1);
|
||||
assert_eq!(Call::Module1_7(module1::Call::fail {}).encode()[0], 2);
|
||||
assert_eq!(Call::Module1_8(module1::Call::fail {}).encode()[0], 12);
|
||||
assert_eq!(Call::Module1_9(module1::Call::fail {}).encode()[0], 13);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_compact_attr() {
|
||||
use codec::Encode;
|
||||
let call: module3::Call<Runtime> = module3::Call::aux_1(1);
|
||||
let call: module3::Call<Runtime> = module3::Call::aux_1 { _data: 1 };
|
||||
let encoded = call.encode();
|
||||
assert_eq!(2, encoded.len());
|
||||
assert_eq!(vec![1, 4], encoded);
|
||||
|
||||
let call: module3::Call<Runtime> = module3::Call::aux_2(1, 2);
|
||||
let call: module3::Call<Runtime> = module3::Call::aux_2 { _data: 1, _data2: 2 };
|
||||
let encoded = call.encode();
|
||||
assert_eq!(6, encoded.len());
|
||||
assert_eq!(vec![2, 1, 0, 0, 0, 8], encoded);
|
||||
@@ -502,13 +503,13 @@ fn call_compact_attr() {
|
||||
#[test]
|
||||
fn call_encode_is_correct_and_decode_works() {
|
||||
use codec::{Decode, Encode};
|
||||
let call: module3::Call<Runtime> = module3::Call::fail();
|
||||
let call: module3::Call<Runtime> = module3::Call::fail {};
|
||||
let encoded = call.encode();
|
||||
assert_eq!(vec![0], encoded);
|
||||
let decoded = module3::Call::<Runtime>::decode(&mut &encoded[..]).unwrap();
|
||||
assert_eq!(decoded, call);
|
||||
|
||||
let call: module3::Call<Runtime> = module3::Call::aux_3(32, "hello".into());
|
||||
let call: module3::Call<Runtime> = module3::Call::aux_3 { _data: 32, _data2: "hello".into() };
|
||||
let encoded = call.encode();
|
||||
assert_eq!(vec![3, 32, 0, 0, 0, 20, 104, 101, 108, 108, 111], encoded);
|
||||
let decoded = module3::Call::<Runtime>::decode(&mut &encoded[..]).unwrap();
|
||||
@@ -523,12 +524,12 @@ fn call_weight_should_attach_to_call_enum() {
|
||||
};
|
||||
// operational.
|
||||
assert_eq!(
|
||||
module3::Call::<Runtime>::operational().get_dispatch_info(),
|
||||
module3::Call::<Runtime>::operational {}.get_dispatch_info(),
|
||||
DispatchInfo { weight: 5, class: DispatchClass::Operational, pays_fee: Pays::Yes },
|
||||
);
|
||||
// custom basic
|
||||
assert_eq!(
|
||||
module3::Call::<Runtime>::aux_4().get_dispatch_info(),
|
||||
module3::Call::<Runtime>::aux_4 {}.get_dispatch_info(),
|
||||
DispatchInfo { weight: 3, class: DispatchClass::Normal, pays_fee: Pays::Yes },
|
||||
);
|
||||
}
|
||||
@@ -536,14 +537,14 @@ fn call_weight_should_attach_to_call_enum() {
|
||||
#[test]
|
||||
fn call_name() {
|
||||
use frame_support::dispatch::GetCallName;
|
||||
let name = module3::Call::<Runtime>::aux_4().get_call_name();
|
||||
let name = module3::Call::<Runtime>::aux_4 {}.get_call_name();
|
||||
assert_eq!("aux_4", name);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_metadata() {
|
||||
use frame_support::dispatch::{CallMetadata, GetCallMetadata};
|
||||
let call = Call::Module3(module3::Call::<Runtime>::aux_4());
|
||||
let call = Call::Module3(module3::Call::<Runtime>::aux_4 {});
|
||||
let metadata = call.get_call_metadata();
|
||||
let expected = CallMetadata { function_name: "aux_4".into(), pallet_name: "Module3".into() };
|
||||
assert_eq!(metadata, expected);
|
||||
@@ -581,10 +582,10 @@ fn get_module_names() {
|
||||
#[test]
|
||||
fn call_subtype_conversion() {
|
||||
use frame_support::{dispatch::CallableCallFor, traits::IsSubType};
|
||||
let call = Call::Module3(module3::Call::<Runtime>::fail());
|
||||
let call = Call::Module3(module3::Call::<Runtime>::fail {});
|
||||
let subcall: Option<&CallableCallFor<Module3, Runtime>> = call.is_sub_type();
|
||||
let subcall_none: Option<&CallableCallFor<Module2, Runtime>> = call.is_sub_type();
|
||||
assert_eq!(Some(&module3::Call::<Runtime>::fail()), subcall);
|
||||
assert_eq!(Some(&module3::Call::<Runtime>::fail {}), subcall);
|
||||
assert_eq!(None, subcall_none);
|
||||
|
||||
let from = Call::from(subcall.unwrap().clone());
|
||||
@@ -593,355 +594,145 @@ fn call_subtype_conversion() {
|
||||
|
||||
#[test]
|
||||
fn test_metadata() {
|
||||
use frame_metadata::*;
|
||||
let expected_metadata: RuntimeMetadataLastVersion = RuntimeMetadataLastVersion {
|
||||
modules: DecodeDifferent::Encode(&[
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("System"),
|
||||
storage: None,
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("noop"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Encode("ExtrinsicSuccess"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Encode("ExtrinsicFailed"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Encode("Ignore"),
|
||||
arguments: DecodeDifferent::Encode(&["BlockNumber"]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 30,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module1_1"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Instance1Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&["AccountId"]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 31,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module2"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 32,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module1_2"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Instance2Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&["AccountId"]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 33,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("NestedModule3"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 34,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module3"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_1"),
|
||||
arguments: DecodeDifferent::Encode(&[FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data"),
|
||||
ty: DecodeDifferent::Encode("Compact<u32>"),
|
||||
}]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_2"),
|
||||
arguments: DecodeDifferent::Encode(&[
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data"),
|
||||
ty: DecodeDifferent::Encode("i32"),
|
||||
},
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data2"),
|
||||
ty: DecodeDifferent::Encode("Compact<u32>"),
|
||||
},
|
||||
]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_3"),
|
||||
arguments: DecodeDifferent::Encode(&[
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data"),
|
||||
ty: DecodeDifferent::Encode("i32"),
|
||||
},
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Encode("_data2"),
|
||||
ty: DecodeDifferent::Encode("String"),
|
||||
},
|
||||
]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("aux_4"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("operational"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 35,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module1_3"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Instance3Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: None,
|
||||
event: None,
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 6,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module1_4"),
|
||||
storage: None,
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: None,
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 3,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module1_5"),
|
||||
storage: None,
|
||||
calls: None,
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&["AccountId"]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 4,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module1_6"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Instance6Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&["AccountId"]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 1,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module1_7"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Instance7Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&["AccountId"]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 2,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module1_8"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Instance8Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&["AccountId"]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 12,
|
||||
},
|
||||
ModuleMetadata {
|
||||
name: DecodeDifferent::Encode("Module1_9"),
|
||||
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Instance9Module"),
|
||||
entries: DecodeDifferent::Encode(&[]),
|
||||
}))),
|
||||
calls: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[FunctionMetadata {
|
||||
name: DecodeDifferent::Encode("fail"),
|
||||
arguments: DecodeDifferent::Encode(&[]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
event: Some(DecodeDifferent::Encode(FnEncode(|| {
|
||||
&[EventMetadata {
|
||||
name: DecodeDifferent::Encode("A"),
|
||||
arguments: DecodeDifferent::Encode(&["AccountId"]),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
}]
|
||||
}))),
|
||||
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
|
||||
index: 13,
|
||||
},
|
||||
]),
|
||||
extrinsic: ExtrinsicMetadata {
|
||||
version: 4,
|
||||
signed_extensions: vec![DecodeDifferent::Encode("UnitSignedExtension")],
|
||||
use frame_support::metadata::*;
|
||||
use scale_info::meta_type;
|
||||
|
||||
let pallets = vec![
|
||||
PalletMetadata {
|
||||
name: "System",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<system::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<system::Event<Runtime>>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 30,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_1",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Instance1Module", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance1>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance1>>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 31,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module2",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module", entries: vec![] }),
|
||||
calls: Some(meta_type::<module2::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<module2::Event>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 32,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_2",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Instance2Module", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance2>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance2>>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 33,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "NestedModule3",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module", entries: vec![] }),
|
||||
calls: Some(meta_type::<nested::module3::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<nested::module3::Event>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 34,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module3",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module", entries: vec![] }),
|
||||
calls: Some(meta_type::<module3::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<module3::Event>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 35,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_3",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Instance3Module", entries: vec![] }),
|
||||
calls: None,
|
||||
event: None,
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 6,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_4",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance4>>().into()),
|
||||
event: None,
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 3,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_5",
|
||||
storage: None,
|
||||
calls: None,
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance5>>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 4,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_6",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Instance6Module", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance6>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance6>>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 1,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_7",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Instance7Module", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance7>>().into()),
|
||||
event: Some(PalletEventMetadata {
|
||||
ty: meta_type::<module1::Event<Runtime, module1::Instance7>>(),
|
||||
}),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 2,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_8",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Instance8Module", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance8>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance8>>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 12,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_9",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Instance9Module", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance9>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance9>>().into()),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
index: 13,
|
||||
},
|
||||
];
|
||||
|
||||
let extrinsic = ExtrinsicMetadata {
|
||||
ty: meta_type::<UncheckedExtrinsic>(),
|
||||
version: 4,
|
||||
signed_extensions: vec![SignedExtensionMetadata {
|
||||
identifier: "UnitSignedExtension",
|
||||
ty: meta_type::<()>(),
|
||||
additional_signed: meta_type::<()>(),
|
||||
}],
|
||||
};
|
||||
pretty_assertions::assert_eq!(Runtime::metadata().1, RuntimeMetadata::V13(expected_metadata));
|
||||
|
||||
let expected_metadata: RuntimeMetadataPrefixed =
|
||||
RuntimeMetadataLastVersion::new(pallets, extrinsic, meta_type::<Runtime>()).into();
|
||||
let actual_metadata = Runtime::metadata();
|
||||
pretty_assertions::assert_eq!(actual_metadata, expected_metadata);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -36,6 +36,28 @@ help: consider importing this enum
|
||||
1 | use frame_system::RawOrigin;
|
||||
|
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared crate or module `system`
|
||||
--> $DIR/no_std_genesis_config.rs:13:1
|
||||
|
|
||||
13 | / construct_runtime! {
|
||||
14 | | pub enum Runtime where
|
||||
15 | | Block = Block,
|
||||
16 | | NodeBlock = Block,
|
||||
... |
|
||||
21 | | }
|
||||
22 | | }
|
||||
| |_^ not found in `system`
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing one of these items
|
||||
|
|
||||
1 | use frame_support_test::Pallet;
|
||||
|
|
||||
1 | use frame_system::Pallet;
|
||||
|
|
||||
1 | use test_pallet::Pallet;
|
||||
|
|
||||
|
||||
error[E0412]: cannot find type `GenesisConfig` in crate `test_pallet`
|
||||
--> $DIR/no_std_genesis_config.rs:13:1
|
||||
|
|
||||
|
||||
@@ -39,6 +39,30 @@ help: consider importing this enum
|
||||
1 | use frame_system::RawOrigin;
|
||||
|
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared crate or module `system`
|
||||
--> $DIR/undefined_call_part.rs:22:1
|
||||
|
|
||||
22 | / construct_runtime! {
|
||||
23 | | pub enum Runtime where
|
||||
24 | | Block = Block,
|
||||
25 | | NodeBlock = Block,
|
||||
... |
|
||||
30 | | }
|
||||
31 | | }
|
||||
| |_^ not found in `system`
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing one of these items
|
||||
|
|
||||
1 | use crate::pallet::Pallet;
|
||||
|
|
||||
1 | use frame_support_test::Pallet;
|
||||
|
|
||||
1 | use frame_system::Pallet;
|
||||
|
|
||||
1 | use test_pallet::Pallet;
|
||||
|
|
||||
|
||||
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
|
||||
--> $DIR/undefined_call_part.rs:20:6
|
||||
|
|
||||
|
||||
+24
-14
@@ -21,20 +21,6 @@ error[E0433]: failed to resolve: use of undeclared crate or module `system`
|
||||
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
|
||||
| ^^^^^^ use of undeclared crate or module `system`
|
||||
|
||||
error[E0433]: failed to resolve: could not find `Event` in `pallet`
|
||||
--> $DIR/undefined_event_part.rs:22:1
|
||||
|
|
||||
22 | / construct_runtime! {
|
||||
23 | | pub enum Runtime where
|
||||
24 | | Block = Block,
|
||||
25 | | NodeBlock = Block,
|
||||
... |
|
||||
30 | | }
|
||||
31 | | }
|
||||
| |_^ could not find `Event` in `pallet`
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0412]: cannot find type `Event` in module `pallet`
|
||||
--> $DIR/undefined_event_part.rs:22:1
|
||||
|
|
||||
@@ -91,6 +77,30 @@ help: consider importing this enum
|
||||
1 | use frame_system::RawOrigin;
|
||||
|
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared crate or module `system`
|
||||
--> $DIR/undefined_event_part.rs:22:1
|
||||
|
|
||||
22 | / construct_runtime! {
|
||||
23 | | pub enum Runtime where
|
||||
24 | | Block = Block,
|
||||
25 | | NodeBlock = Block,
|
||||
... |
|
||||
30 | | }
|
||||
31 | | }
|
||||
| |_^ not found in `system`
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing one of these items
|
||||
|
|
||||
1 | use crate::pallet::Pallet;
|
||||
|
|
||||
1 | use frame_support_test::Pallet;
|
||||
|
|
||||
1 | use frame_system::Pallet;
|
||||
|
|
||||
1 | use test_pallet::Pallet;
|
||||
|
|
||||
|
||||
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
|
||||
--> $DIR/undefined_event_part.rs:20:6
|
||||
|
|
||||
|
||||
+24
@@ -39,6 +39,30 @@ help: consider importing this enum
|
||||
1 | use frame_system::RawOrigin;
|
||||
|
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared crate or module `system`
|
||||
--> $DIR/undefined_genesis_config_part.rs:22:1
|
||||
|
|
||||
22 | / construct_runtime! {
|
||||
23 | | pub enum Runtime where
|
||||
24 | | Block = Block,
|
||||
25 | | NodeBlock = Block,
|
||||
... |
|
||||
30 | | }
|
||||
31 | | }
|
||||
| |_^ not found in `system`
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing one of these items
|
||||
|
|
||||
1 | use crate::pallet::Pallet;
|
||||
|
|
||||
1 | use frame_support_test::Pallet;
|
||||
|
|
||||
1 | use frame_system::Pallet;
|
||||
|
|
||||
1 | use test_pallet::Pallet;
|
||||
|
|
||||
|
||||
error[E0412]: cannot find type `GenesisConfig` in module `pallet`
|
||||
--> $DIR/undefined_genesis_config_part.rs:22:1
|
||||
|
|
||||
|
||||
+24
@@ -39,6 +39,30 @@ help: consider importing this enum
|
||||
1 | use frame_system::RawOrigin;
|
||||
|
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared crate or module `system`
|
||||
--> $DIR/undefined_inherent_part.rs:22:1
|
||||
|
|
||||
22 | / construct_runtime! {
|
||||
23 | | pub enum Runtime where
|
||||
24 | | Block = Block,
|
||||
25 | | NodeBlock = Block,
|
||||
... |
|
||||
30 | | }
|
||||
31 | | }
|
||||
| |_^ not found in `system`
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing one of these items
|
||||
|
|
||||
1 | use crate::pallet::Pallet;
|
||||
|
|
||||
1 | use frame_support_test::Pallet;
|
||||
|
|
||||
1 | use frame_system::Pallet;
|
||||
|
|
||||
1 | use test_pallet::Pallet;
|
||||
|
|
||||
|
||||
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
|
||||
--> $DIR/undefined_inherent_part.rs:20:6
|
||||
|
|
||||
|
||||
@@ -77,6 +77,30 @@ help: consider importing one of these items
|
||||
1 | use frame_system::Origin;
|
||||
|
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared crate or module `system`
|
||||
--> $DIR/undefined_origin_part.rs:22:1
|
||||
|
|
||||
22 | / construct_runtime! {
|
||||
23 | | pub enum Runtime where
|
||||
24 | | Block = Block,
|
||||
25 | | NodeBlock = Block,
|
||||
... |
|
||||
30 | | }
|
||||
31 | | }
|
||||
| |_^ not found in `system`
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing one of these items
|
||||
|
|
||||
1 | use crate::pallet::Pallet;
|
||||
|
|
||||
1 | use frame_support_test::Pallet;
|
||||
|
|
||||
1 | use frame_system::Pallet;
|
||||
|
|
||||
1 | use test_pallet::Pallet;
|
||||
|
|
||||
|
||||
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
|
||||
--> $DIR/undefined_origin_part.rs:20:6
|
||||
|
|
||||
|
||||
+24
@@ -39,6 +39,30 @@ help: consider importing this enum
|
||||
1 | use frame_system::RawOrigin;
|
||||
|
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared crate or module `system`
|
||||
--> $DIR/undefined_validate_unsigned_part.rs:22:1
|
||||
|
|
||||
22 | / construct_runtime! {
|
||||
23 | | pub enum Runtime where
|
||||
24 | | Block = Block,
|
||||
25 | | NodeBlock = Block,
|
||||
... |
|
||||
30 | | }
|
||||
31 | | }
|
||||
| |_^ not found in `system`
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing one of these items
|
||||
|
|
||||
1 | use crate::pallet::Pallet;
|
||||
|
|
||||
1 | use frame_support_test::Pallet;
|
||||
|
|
||||
1 | use frame_system::Pallet;
|
||||
|
|
||||
1 | use test_pallet::Pallet;
|
||||
|
|
||||
|
||||
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
|
||||
--> $DIR/undefined_validate_unsigned_part.rs:20:6
|
||||
|
|
||||
|
||||
@@ -21,14 +21,17 @@
|
||||
mod tests {
|
||||
use frame_support::metadata::*;
|
||||
use sp_io::TestExternalities;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
frame_support::decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
|
||||
}
|
||||
|
||||
pub trait Config: frame_support_test::Config {
|
||||
type Origin2: codec::Codec + codec::EncodeLike + Default + codec::MaxEncodedLen;
|
||||
type Origin2: codec::Codec
|
||||
+ codec::EncodeLike
|
||||
+ Default
|
||||
+ codec::MaxEncodedLen
|
||||
+ scale_info::TypeInfo;
|
||||
}
|
||||
|
||||
frame_support::decl_storage! {
|
||||
@@ -101,329 +104,265 @@ mod tests {
|
||||
type Origin2 = u32;
|
||||
}
|
||||
|
||||
const EXPECTED_METADATA: StorageMetadata = StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("TestStorage"),
|
||||
entries: DecodeDifferent::Encode(&[
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("U32"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructU32(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[" Hello, this is doc!"]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBU32"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructPUBU32(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("U32MYDEF"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructU32MYDEF(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBU32MYDEF"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructPUBU32MYDEF(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GETU32"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("T::Origin2")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructGETU32(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBGETU32"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructPUBGETU32(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GETU32WITHCONFIG"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructGETU32WITHCONFIG(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBGETU32WITHCONFIG"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructPUBGETU32WITHCONFIG(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GETU32MYDEF"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructGETU32MYDEF(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBGETU32MYDEF"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructPUBGETU32MYDEF(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GETU32WITHCONFIGMYDEF"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructGETU32WITHCONFIGMYDEF(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBGETU32WITHCONFIGMYDEF"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructPUBGETU32WITHCONFIGMYDEF(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBGETU32WITHCONFIGMYDEFOPT"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructPUBGETU32WITHCONFIGMYDEFOPT(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GetU32WithBuilder"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructGetU32WithBuilder(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GetOptU32WithBuilderSome"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructGetOptU32WithBuilderSome(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GetOptU32WithBuilderNone"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("u32")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructGetOptU32WithBuilderNone(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("MAPU32"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("[u8; 4]"),
|
||||
unused: false,
|
||||
fn expected_metadata() -> PalletStorageMetadata {
|
||||
PalletStorageMetadata {
|
||||
prefix: "TestStorage",
|
||||
entries: vec![
|
||||
StorageEntryMetadata {
|
||||
name: "U32",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![" Hello, this is doc!"],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructMAPU32(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBMAPU32"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("[u8; 4]"),
|
||||
unused: false,
|
||||
StorageEntryMetadata {
|
||||
name: "PUBU32",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructPUBMAPU32(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GETMAPU32"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("[u8; 4]"),
|
||||
unused: false,
|
||||
StorageEntryMetadata {
|
||||
name: "U32MYDEF",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructGETMAPU32(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBGETMAPU32"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("[u8; 4]"),
|
||||
unused: false,
|
||||
StorageEntryMetadata {
|
||||
name: "PUBU32MYDEF",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructPUBGETMAPU32(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("GETMAPU32MYDEF"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("[u8; 4]"),
|
||||
unused: false,
|
||||
StorageEntryMetadata {
|
||||
name: "GETU32",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructGETMAPU32MYDEF(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("PUBGETMAPU32MYDEF"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("[u8; 4]"),
|
||||
unused: false,
|
||||
StorageEntryMetadata {
|
||||
name: "PUBGETU32",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&__GetByteStructPUBGETMAPU32MYDEF(PhantomData::<TraitImpl>),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("DOUBLEMAP"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key1: DecodeDifferent::Encode("u32"),
|
||||
key2: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("[u8; 4]"),
|
||||
key2_hasher: StorageHasher::Blake2_128Concat,
|
||||
StorageEntryMetadata {
|
||||
name: "GETU32WITHCONFIG",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructDOUBLEMAP(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("DOUBLEMAP2"),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key1: DecodeDifferent::Encode("u32"),
|
||||
key2: DecodeDifferent::Encode("u32"),
|
||||
value: DecodeDifferent::Encode("[u8; 4]"),
|
||||
key2_hasher: StorageHasher::Blake2_128Concat,
|
||||
StorageEntryMetadata {
|
||||
name: "PUBGETU32WITHCONFIG",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructDOUBLEMAP2(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("COMPLEXTYPE1"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode(
|
||||
"(::std::option::Option<T::Origin2>,)",
|
||||
)),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructCOMPLEXTYPE1(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("COMPLEXTYPE2"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode(
|
||||
"([[(u16, Option<()>); 32]; 12], u32)",
|
||||
)),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructCOMPLEXTYPE2(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("COMPLEXTYPE3"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("[u32; 25]")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructCOMPLEXTYPE3(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("NMAP"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::NMap {
|
||||
keys: DecodeDifferent::Encode(&["u32", "u16"]),
|
||||
hashers: DecodeDifferent::Encode(&[
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Twox64Concat,
|
||||
]),
|
||||
value: DecodeDifferent::Encode("u8"),
|
||||
StorageEntryMetadata {
|
||||
name: "GETU32MYDEF",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructNMAP(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("NMAP2"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::NMap {
|
||||
keys: DecodeDifferent::Encode(&["u32"]),
|
||||
hashers: DecodeDifferent::Encode(&[StorageHasher::Blake2_128Concat]),
|
||||
value: DecodeDifferent::Encode("u8"),
|
||||
StorageEntryMetadata {
|
||||
name: "PUBGETU32MYDEF",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![3, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&__GetByteStructNMAP(
|
||||
PhantomData::<TraitImpl>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
]),
|
||||
};
|
||||
StorageEntryMetadata {
|
||||
name: "GETU32WITHCONFIGMYDEF",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![2, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "PUBGETU32WITHCONFIGMYDEF",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![1, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "PUBGETU32WITHCONFIGMYDEFOPT",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "GetU32WithBuilder",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "GetOptU32WithBuilderSome",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "GetOptU32WithBuilderNone",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "MAPU32",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<[u8; 4]>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "PUBMAPU32",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<[u8; 4]>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "GETMAPU32",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<[u8; 4]>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "PUBGETMAPU32",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<[u8; 4]>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "GETMAPU32MYDEF",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<[u8; 4]>(),
|
||||
},
|
||||
default: vec![109, 97, 112, 100], // "map"
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "PUBGETMAPU32MYDEF",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<[u8; 4]>(),
|
||||
},
|
||||
default: vec![112, 117, 98, 109], // "pubmap"
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "DOUBLEMAP",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Blake2_128Concat,
|
||||
],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<[u8; 4]>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "DOUBLEMAP2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Blake2_128Concat,
|
||||
],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<[u8; 4]>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "COMPLEXTYPE1",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<(Option<u32>,)>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "COMPLEXTYPE2",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<(
|
||||
[[(u16, Option<()>); 32]; 12],
|
||||
u32,
|
||||
)>()),
|
||||
default: [0u8; 1156].to_vec(),
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "COMPLEXTYPE3",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<[u32; 25]>()),
|
||||
default: [0u8; 100].to_vec(),
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "NMAP",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
key: scale_info::meta_type::<(u32, u16)>(),
|
||||
hashers: vec![StorageHasher::Blake2_128Concat, StorageHasher::Twox64Concat],
|
||||
value: scale_info::meta_type::<u8>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "NMAP2",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
value: scale_info::meta_type::<u8>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn storage_info() {
|
||||
@@ -645,7 +584,7 @@ mod tests {
|
||||
#[test]
|
||||
fn store_metadata() {
|
||||
let metadata = Module::<TraitImpl>::storage_metadata();
|
||||
pretty_assertions::assert_eq!(EXPECTED_METADATA, metadata);
|
||||
pretty_assertions::assert_eq!(expected_metadata(), metadata);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -790,7 +729,7 @@ mod test_append_and_len {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, scale_info::TypeInfo)]
|
||||
struct NoDef(u32);
|
||||
|
||||
frame_support::decl_storage! {
|
||||
|
||||
@@ -21,13 +21,14 @@ use codec::{Codec, Decode, Encode, EncodeLike};
|
||||
use frame_support::{
|
||||
inherent::{InherentData, InherentIdentifier, MakeFatalError, ProvideInherent},
|
||||
metadata::{
|
||||
DecodeDifferent, DefaultByteGetter, StorageEntryMetadata, StorageEntryModifier,
|
||||
StorageEntryType, StorageHasher, StorageMetadata,
|
||||
PalletStorageMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
|
||||
StorageHasher,
|
||||
},
|
||||
parameter_types,
|
||||
traits::Get,
|
||||
Parameter, StorageDoubleMap, StorageMap, StorageValue,
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::{sr25519, H256};
|
||||
use sp_runtime::{
|
||||
generic,
|
||||
@@ -53,7 +54,7 @@ mod module1 {
|
||||
type Event: From<Event<Self, I>> + Into<<Self as system::Config>::Event>;
|
||||
type Origin: From<Origin<Self, I>>;
|
||||
type SomeParameter: Get<u32>;
|
||||
type GenericType: Default + Clone + Codec + EncodeLike;
|
||||
type GenericType: Default + Clone + Codec + EncodeLike + TypeInfo;
|
||||
}
|
||||
|
||||
frame_support::decl_module! {
|
||||
@@ -108,7 +109,7 @@ mod module1 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode)]
|
||||
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode, TypeInfo)]
|
||||
pub enum Origin<T: Config<I>, I>
|
||||
where
|
||||
T::BlockNumber: From<u32>,
|
||||
@@ -181,7 +182,7 @@ mod module2 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode)]
|
||||
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode, TypeInfo)]
|
||||
pub enum Origin<T: Config<I>, I = DefaultInstance> {
|
||||
Members(u32),
|
||||
_Phantom(std::marker::PhantomData<(T, I)>),
|
||||
@@ -410,54 +411,45 @@ fn storage_with_instance_basic_operation() {
|
||||
});
|
||||
}
|
||||
|
||||
const EXPECTED_METADATA: StorageMetadata = StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Instance2Module2"),
|
||||
entries: DecodeDifferent::Encode(&[
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("Value"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Encode("T::Amount")),
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&module2::__GetByteStructValue(
|
||||
std::marker::PhantomData::<(Runtime, module2::Instance2)>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("Map"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hasher: StorageHasher::Identity,
|
||||
key: DecodeDifferent::Encode("u64"),
|
||||
value: DecodeDifferent::Encode("u64"),
|
||||
unused: false,
|
||||
fn expected_metadata() -> PalletStorageMetadata {
|
||||
PalletStorageMetadata {
|
||||
prefix: "Instance2Module2",
|
||||
entries: vec![
|
||||
StorageEntryMetadata {
|
||||
name: "Value",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(&module2::__GetByteStructMap(
|
||||
std::marker::PhantomData::<(Runtime, module2::Instance2)>,
|
||||
))),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Encode("DoubleMap"),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
hasher: StorageHasher::Identity,
|
||||
key2_hasher: StorageHasher::Identity,
|
||||
key1: DecodeDifferent::Encode("u64"),
|
||||
key2: DecodeDifferent::Encode("u64"),
|
||||
value: DecodeDifferent::Encode("u64"),
|
||||
StorageEntryMetadata {
|
||||
name: "Map",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Identity],
|
||||
key: scale_info::meta_type::<u64>(),
|
||||
value: scale_info::meta_type::<u64>(),
|
||||
},
|
||||
default: [0u8; 8].to_vec(),
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Encode(DefaultByteGetter(
|
||||
&module2::__GetByteStructDoubleMap(
|
||||
std::marker::PhantomData::<(Runtime, module2::Instance2)>,
|
||||
),
|
||||
)),
|
||||
documentation: DecodeDifferent::Encode(&[]),
|
||||
},
|
||||
]),
|
||||
};
|
||||
StorageEntryMetadata {
|
||||
name: "DoubleMap",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
hashers: vec![StorageHasher::Identity, StorageHasher::Identity],
|
||||
key: scale_info::meta_type::<(u64, u64)>(),
|
||||
value: scale_info::meta_type::<u64>(),
|
||||
},
|
||||
default: [0u8; 8].to_vec(),
|
||||
docs: vec![],
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_instance_storage_metadata() {
|
||||
let metadata = Module2_2::storage_metadata();
|
||||
pretty_assertions::assert_eq!(EXPECTED_METADATA, metadata);
|
||||
pretty_assertions::assert_eq!(expected_metadata(), metadata);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
use frame_support::{
|
||||
codec::{Decode, Encode},
|
||||
scale_info::TypeInfo,
|
||||
sp_runtime::{
|
||||
generic,
|
||||
traits::{BlakeTwo256, Verify},
|
||||
@@ -34,12 +35,12 @@ mod module {
|
||||
(<T as system::Config>::AccountId, Role, <T as system::Config>::BlockNumber);
|
||||
pub type Requests<T> = Vec<Request<T>>;
|
||||
|
||||
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Debug)]
|
||||
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Debug, TypeInfo)]
|
||||
pub enum Role {
|
||||
Storage,
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Debug)]
|
||||
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Debug, TypeInfo)]
|
||||
pub struct RoleParameters<T: Config> {
|
||||
// minimum actors to maintain - if role is unstaking
|
||||
// and remaining actors would be less that this value - prevent or punish for unstaking
|
||||
@@ -82,7 +83,7 @@ mod module {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Config: system::Config {}
|
||||
pub trait Config: system::Config + TypeInfo {}
|
||||
|
||||
frame_support::decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
|
||||
|
||||
@@ -24,6 +24,7 @@ use frame_support::{
|
||||
},
|
||||
weights::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays, RuntimeDbWeight},
|
||||
};
|
||||
use scale_info::{meta_type, TypeInfo};
|
||||
use sp_io::{
|
||||
hashing::{blake2_128, twox_128, twox_64},
|
||||
TestExternalities,
|
||||
@@ -80,14 +81,14 @@ impl From<SomeType7> for u64 {
|
||||
}
|
||||
|
||||
pub trait SomeAssociation1 {
|
||||
type _1: Parameter + codec::MaxEncodedLen;
|
||||
type _1: Parameter + codec::MaxEncodedLen + TypeInfo;
|
||||
}
|
||||
impl SomeAssociation1 for u64 {
|
||||
type _1 = u64;
|
||||
}
|
||||
|
||||
pub trait SomeAssociation2 {
|
||||
type _2: Parameter + codec::MaxEncodedLen;
|
||||
type _2: Parameter + codec::MaxEncodedLen + TypeInfo;
|
||||
}
|
||||
impl SomeAssociation2 for u64 {
|
||||
type _2 = u64;
|
||||
@@ -101,6 +102,7 @@ pub mod pallet {
|
||||
};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use scale_info::TypeInfo;
|
||||
|
||||
type BalanceOf<T> = <T as Config>::Balance;
|
||||
|
||||
@@ -124,7 +126,7 @@ pub mod pallet {
|
||||
#[pallet::constant]
|
||||
type MyGetParam3: Get<<Self::AccountId as SomeAssociation1>::_1>;
|
||||
|
||||
type Balance: Parameter + Default;
|
||||
type Balance: Parameter + Default + TypeInfo;
|
||||
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
}
|
||||
@@ -228,7 +230,6 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::metadata(BalanceOf<T> = "Balance", u32 = "Other")]
|
||||
#[pallet::generate_deposit(fn deposit_event)]
|
||||
pub enum Event<T: Config>
|
||||
where
|
||||
@@ -340,7 +341,9 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::origin]
|
||||
#[derive(EqNoBound, RuntimeDebugNoBound, CloneNoBound, PartialEqNoBound, Encode, Decode)]
|
||||
#[derive(
|
||||
EqNoBound, RuntimeDebugNoBound, CloneNoBound, PartialEqNoBound, Encode, Decode, TypeInfo,
|
||||
)]
|
||||
pub struct Origin<T>(PhantomData<T>);
|
||||
|
||||
#[pallet::validate_unsigned]
|
||||
@@ -352,7 +355,7 @@ pub mod pallet {
|
||||
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
|
||||
T::AccountId::from(SomeType1); // Test for where clause
|
||||
T::AccountId::from(SomeType5); // Test for where clause
|
||||
if matches!(call, Call::foo_transactional(_)) {
|
||||
if matches!(call, Call::foo_transactional { .. }) {
|
||||
return Ok(ValidTransaction::default())
|
||||
}
|
||||
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
|
||||
@@ -372,18 +375,18 @@ pub mod pallet {
|
||||
fn create_inherent(_data: &InherentData) -> Option<Self::Call> {
|
||||
T::AccountId::from(SomeType1); // Test for where clause
|
||||
T::AccountId::from(SomeType6); // Test for where clause
|
||||
Some(Call::foo_no_post_info())
|
||||
Some(Call::foo_no_post_info {})
|
||||
}
|
||||
|
||||
fn is_inherent(call: &Self::Call) -> bool {
|
||||
matches!(call, Call::foo_no_post_info() | Call::foo(..))
|
||||
matches!(call, Call::foo_no_post_info {} | Call::foo { .. })
|
||||
}
|
||||
|
||||
fn check_inherent(call: &Self::Call, _: &InherentData) -> Result<(), Self::Error> {
|
||||
match call {
|
||||
Call::foo_no_post_info() => Ok(()),
|
||||
Call::foo(0, 0) => Err(InherentError::Fatal),
|
||||
Call::foo(..) => Ok(()),
|
||||
Call::foo_no_post_info {} => Ok(()),
|
||||
Call::foo { foo: 0, bar: 0 } => Err(InherentError::Fatal),
|
||||
Call::foo { .. } => Ok(()),
|
||||
_ => unreachable!("other calls are not inherents"),
|
||||
}
|
||||
}
|
||||
@@ -550,13 +553,13 @@ fn transactional_works() {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
frame_system::Pallet::<Runtime>::set_block_number(1);
|
||||
|
||||
pallet::Call::<Runtime>::foo_transactional(0)
|
||||
pallet::Call::<Runtime>::foo_transactional { foo: 0 }
|
||||
.dispatch_bypass_filter(None.into())
|
||||
.err()
|
||||
.unwrap();
|
||||
assert!(frame_system::Pallet::<Runtime>::events().is_empty());
|
||||
|
||||
pallet::Call::<Runtime>::foo_transactional(1)
|
||||
pallet::Call::<Runtime>::foo_transactional { foo: 1 }
|
||||
.dispatch_bypass_filter(None.into())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
@@ -571,7 +574,7 @@ fn transactional_works() {
|
||||
|
||||
#[test]
|
||||
fn call_expand() {
|
||||
let call_foo = pallet::Call::<Runtime>::foo(3, 0);
|
||||
let call_foo = pallet::Call::<Runtime>::foo { foo: 3, bar: 0 };
|
||||
assert_eq!(
|
||||
call_foo.get_dispatch_info(),
|
||||
DispatchInfo { weight: 3, class: DispatchClass::Normal, pays_fee: Pays::Yes }
|
||||
@@ -620,7 +623,7 @@ fn inherent_expand() {
|
||||
let inherents = InherentData::new().create_extrinsics();
|
||||
|
||||
let expected = vec![UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo_no_post_info()),
|
||||
function: Call::Example(pallet::Call::foo_no_post_info {}),
|
||||
signature: None,
|
||||
}];
|
||||
assert_eq!(expected, inherents);
|
||||
@@ -635,11 +638,11 @@ fn inherent_expand() {
|
||||
),
|
||||
vec![
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo_no_post_info()),
|
||||
function: Call::Example(pallet::Call::foo_no_post_info {}),
|
||||
signature: None,
|
||||
},
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo(1, 0)),
|
||||
function: Call::Example(pallet::Call::foo { foo: 1, bar: 0 }),
|
||||
signature: None,
|
||||
},
|
||||
],
|
||||
@@ -657,11 +660,11 @@ fn inherent_expand() {
|
||||
),
|
||||
vec![
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo_no_post_info()),
|
||||
function: Call::Example(pallet::Call::foo_no_post_info {}),
|
||||
signature: None,
|
||||
},
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo(0, 0)),
|
||||
function: Call::Example(pallet::Call::foo { foo: 0, bar: 0 }),
|
||||
signature: None,
|
||||
},
|
||||
],
|
||||
@@ -678,7 +681,7 @@ fn inherent_expand() {
|
||||
Digest::default(),
|
||||
),
|
||||
vec![UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo_transactional(0)),
|
||||
function: Call::Example(pallet::Call::foo_transactional { foo: 0 }),
|
||||
signature: None,
|
||||
}],
|
||||
);
|
||||
@@ -696,7 +699,7 @@ fn inherent_expand() {
|
||||
Digest::default(),
|
||||
),
|
||||
vec![UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo_no_post_info()),
|
||||
function: Call::Example(pallet::Call::foo_no_post_info {}),
|
||||
signature: Some((1, (), ())),
|
||||
}],
|
||||
);
|
||||
@@ -715,11 +718,11 @@ fn inherent_expand() {
|
||||
),
|
||||
vec![
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo(1, 1)),
|
||||
function: Call::Example(pallet::Call::foo { foo: 1, bar: 1 }),
|
||||
signature: None,
|
||||
},
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo_transactional(0)),
|
||||
function: Call::Example(pallet::Call::foo_transactional { foo: 0 }),
|
||||
signature: None,
|
||||
},
|
||||
],
|
||||
@@ -737,15 +740,15 @@ fn inherent_expand() {
|
||||
),
|
||||
vec![
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo(1, 1)),
|
||||
function: Call::Example(pallet::Call::foo { foo: 1, bar: 1 }),
|
||||
signature: None,
|
||||
},
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo_transactional(0)),
|
||||
function: Call::Example(pallet::Call::foo_transactional { foo: 0 }),
|
||||
signature: None,
|
||||
},
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo_no_post_info()),
|
||||
function: Call::Example(pallet::Call::foo_no_post_info {}),
|
||||
signature: None,
|
||||
},
|
||||
],
|
||||
@@ -763,15 +766,15 @@ fn inherent_expand() {
|
||||
),
|
||||
vec![
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo(1, 1)),
|
||||
function: Call::Example(pallet::Call::foo { foo: 1, bar: 1 }),
|
||||
signature: None,
|
||||
},
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo(1, 0)),
|
||||
function: Call::Example(pallet::Call::foo { foo: 1, bar: 0 }),
|
||||
signature: Some((1, (), ())),
|
||||
},
|
||||
UncheckedExtrinsic {
|
||||
function: Call::Example(pallet::Call::foo_no_post_info()),
|
||||
function: Call::Example(pallet::Call::foo_no_post_info {}),
|
||||
signature: None,
|
||||
},
|
||||
],
|
||||
@@ -786,12 +789,12 @@ fn validate_unsigned_expand() {
|
||||
InvalidTransaction, TransactionSource, TransactionValidityError, ValidTransaction,
|
||||
ValidateUnsigned,
|
||||
};
|
||||
let call = pallet::Call::<Runtime>::foo_no_post_info();
|
||||
let call = pallet::Call::<Runtime>::foo_no_post_info {};
|
||||
|
||||
let validity = pallet::Pallet::validate_unsigned(TransactionSource::Local, &call).unwrap_err();
|
||||
assert_eq!(validity, TransactionValidityError::Invalid(InvalidTransaction::Call));
|
||||
|
||||
let call = pallet::Call::<Runtime>::foo_transactional(0);
|
||||
let call = pallet::Call::<Runtime>::foo_transactional { foo: 0 };
|
||||
|
||||
let validity = pallet::Pallet::validate_unsigned(TransactionSource::External, &call).unwrap();
|
||||
assert_eq!(validity, ValidTransaction::default());
|
||||
@@ -810,7 +813,9 @@ fn trait_store_expand() {
|
||||
fn pallet_expand_deposit_event() {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
frame_system::Pallet::<Runtime>::set_block_number(1);
|
||||
pallet::Call::<Runtime>::foo(3, 0).dispatch_bypass_filter(None.into()).unwrap();
|
||||
pallet::Call::<Runtime>::foo { foo: 3, bar: 0 }
|
||||
.dispatch_bypass_filter(None.into())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
frame_system::Pallet::<Runtime>::events()[0].event,
|
||||
Event::Example(pallet::Event::Something(3)),
|
||||
@@ -818,6 +823,11 @@ fn pallet_expand_deposit_event() {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pallet_new_call_variant() {
|
||||
Call::Example(pallet::Call::new_call_variant_foo(3, 4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn storage_expand() {
|
||||
use frame_support::{pallet_prelude::*, storage::StoragePrefixedMap};
|
||||
@@ -969,288 +979,478 @@ fn migrate_from_pallet_version_to_storage_version() {
|
||||
|
||||
#[test]
|
||||
fn metadata() {
|
||||
use codec::{Decode, Encode};
|
||||
use frame_metadata::*;
|
||||
use frame_support::metadata::*;
|
||||
|
||||
let expected_pallet_metadata = ModuleMetadata {
|
||||
index: 1,
|
||||
name: DecodeDifferent::Decoded("Example".to_string()),
|
||||
storage: Some(DecodeDifferent::Decoded(StorageMetadata {
|
||||
prefix: DecodeDifferent::Decoded("Example".to_string()),
|
||||
entries: DecodeDifferent::Decoded(vec![
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("ValueWhereClause".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Decoded(
|
||||
"<T::AccountId as SomeAssociation2>::_2".to_string(),
|
||||
)),
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
let pallets = vec![
|
||||
PalletMetadata {
|
||||
index: 0,
|
||||
name: "System",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<frame_system::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<frame_system::Event<Runtime>>().into()),
|
||||
constants: vec![
|
||||
PalletConstantMetadata {
|
||||
name: "BlockWeights",
|
||||
ty: meta_type::<frame_system::limits::BlockWeights>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("Value".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Decoded("u32".to_string())),
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
PalletConstantMetadata {
|
||||
name: "BlockLength",
|
||||
ty: meta_type::<frame_system::limits::BlockLength>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("Value2".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Decoded("u64".to_string())),
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
PalletConstantMetadata {
|
||||
name: "BlockHashCount",
|
||||
ty: meta_type::<u32>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("Map".to_string()),
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
key: DecodeDifferent::Decoded("u8".to_string()),
|
||||
value: DecodeDifferent::Decoded("u16".to_string()),
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
unused: false,
|
||||
PalletConstantMetadata {
|
||||
name: "DbWeight",
|
||||
ty: meta_type::<frame_support::weights::RuntimeDbWeight>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "Version",
|
||||
ty: meta_type::<sp_version::RuntimeVersion>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "SS58Prefix",
|
||||
ty: meta_type::<u16>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
],
|
||||
error: Some(meta_type::<frame_system::Error<Runtime>>().into()),
|
||||
},
|
||||
PalletMetadata {
|
||||
index: 1,
|
||||
name: "Example",
|
||||
storage: Some(PalletStorageMetadata {
|
||||
prefix: "Example",
|
||||
entries: vec![
|
||||
StorageEntryMetadata {
|
||||
name: "ValueWhereClause",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(meta_type::<u64>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![4, 0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
StorageEntryMetadata {
|
||||
name: "Value",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "Value2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(meta_type::<u64>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "Map",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<u8>(),
|
||||
value: meta_type::<u16>(),
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
},
|
||||
default: vec![4, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "Map2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<u16>(),
|
||||
value: meta_type::<u32>(),
|
||||
hashers: vec![StorageHasher::Twox64Concat],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "DoubleMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
value: meta_type::<u32>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Twox64Concat,
|
||||
],
|
||||
key: meta_type::<(u8, u16)>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "DoubleMap2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
value: meta_type::<u64>(),
|
||||
key: meta_type::<(u16, u32)>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Twox64Concat,
|
||||
StorageHasher::Blake2_128Concat,
|
||||
],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "NMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<u8>(),
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
value: meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "NMap2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<(u16, u32)>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Twox64Concat,
|
||||
StorageHasher::Blake2_128Concat,
|
||||
],
|
||||
value: meta_type::<u64>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: "ConditionalValue",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: "ConditionalMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<u16>(),
|
||||
value: meta_type::<u32>(),
|
||||
hashers: vec![StorageHasher::Twox64Concat],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: "ConditionalDoubleMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
value: meta_type::<u32>(),
|
||||
key: meta_type::<(u8, u16)>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Twox64Concat,
|
||||
],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: "ConditionalNMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<(u8, u16)>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Twox64Concat,
|
||||
],
|
||||
value: meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
],
|
||||
}),
|
||||
calls: Some(meta_type::<pallet::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<pallet::Event<Runtime>>().into()),
|
||||
constants: vec![
|
||||
PalletConstantMetadata {
|
||||
name: "MyGetParam",
|
||||
ty: meta_type::<u32>(),
|
||||
value: vec![10, 0, 0, 0],
|
||||
docs: vec![" Some comment", " Some comment"],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("Map2".to_string()),
|
||||
PalletConstantMetadata {
|
||||
name: "MyGetParam2",
|
||||
ty: meta_type::<u32>(),
|
||||
value: vec![11, 0, 0, 0],
|
||||
docs: vec![" Some comment", " Some comment"],
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "MyGetParam3",
|
||||
ty: meta_type::<u64>(),
|
||||
value: vec![12, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "some_extra",
|
||||
ty: meta_type::<u64>(),
|
||||
value: vec![100, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![" Some doc", " Some doc"],
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "some_extra_extra",
|
||||
ty: meta_type::<u64>(),
|
||||
value: vec![0, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![" Some doc"],
|
||||
},
|
||||
],
|
||||
error: Some(PalletErrorMetadata { ty: meta_type::<pallet::Error<Runtime>>() }),
|
||||
},
|
||||
PalletMetadata {
|
||||
index: 1,
|
||||
name: "Example",
|
||||
storage: Some(PalletStorageMetadata {
|
||||
prefix: "Example",
|
||||
entries: vec![
|
||||
StorageEntryMetadata {
|
||||
name: "ValueWhereClause",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(meta_type::<u64>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "Value",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "Value2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(meta_type::<u64>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "Map",
|
||||
modifier: StorageEntryModifier::Default,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<u8>(),
|
||||
value: meta_type::<u16>(),
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
},
|
||||
default: vec![4, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "Map2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<u16>(),
|
||||
value: meta_type::<u32>(),
|
||||
hashers: vec![StorageHasher::Twox64Concat],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "DoubleMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
value: meta_type::<u32>(),
|
||||
key: meta_type::<(u8, u16)>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Twox64Concat,
|
||||
],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "DoubleMap2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
value: meta_type::<u64>(),
|
||||
key: meta_type::<(u16, u32)>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Twox64Concat,
|
||||
StorageHasher::Blake2_128Concat,
|
||||
],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "NMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<u8>(),
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
value: meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "NMap2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<(u16, u32)>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Twox64Concat,
|
||||
StorageHasher::Blake2_128Concat,
|
||||
],
|
||||
value: meta_type::<u64>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: "ConditionalValue",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: "ConditionalMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<u16>(),
|
||||
value: meta_type::<u32>(),
|
||||
hashers: vec![StorageHasher::Twox64Concat],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: "ConditionalDoubleMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
value: meta_type::<u32>(),
|
||||
key: meta_type::<(u8, u16)>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Twox64Concat,
|
||||
],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: "ConditionalNMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: meta_type::<(u8, u16)>(),
|
||||
hashers: vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Twox64Concat,
|
||||
],
|
||||
value: meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
],
|
||||
}),
|
||||
calls: Some(meta_type::<pallet::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<pallet::Event<Runtime>>().into()),
|
||||
constants: vec![
|
||||
PalletConstantMetadata {
|
||||
name: "MyGetParam",
|
||||
ty: meta_type::<u32>(),
|
||||
value: vec![10, 0, 0, 0],
|
||||
docs: vec![" Some comment", " Some comment"],
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "MyGetParam2",
|
||||
ty: meta_type::<u32>(),
|
||||
value: vec![11, 0, 0, 0],
|
||||
docs: vec![" Some comment", " Some comment"],
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "MyGetParam3",
|
||||
ty: meta_type::<u64>(),
|
||||
value: vec![12, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "some_extra",
|
||||
ty: meta_type::<u64>(),
|
||||
value: vec![100, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![" Some doc", " Some doc"],
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "some_extra_extra",
|
||||
ty: meta_type::<u64>(),
|
||||
value: vec![0, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![" Some doc"],
|
||||
},
|
||||
],
|
||||
error: Some(PalletErrorMetadata { ty: meta_type::<pallet::Error<Runtime>>() }),
|
||||
},
|
||||
PalletMetadata {
|
||||
index: 2,
|
||||
name: "Example2",
|
||||
storage: Some(PalletStorageMetadata {
|
||||
prefix: "Example2",
|
||||
entries: vec![StorageEntryMetadata {
|
||||
name: "SomeValue",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: DecodeDifferent::Decoded("u16".to_string()),
|
||||
value: DecodeDifferent::Decoded("u32".to_string()),
|
||||
hasher: StorageHasher::Twox64Concat,
|
||||
unused: false,
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("DoubleMap".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
value: DecodeDifferent::Decoded("u32".to_string()),
|
||||
key1: DecodeDifferent::Decoded("u8".to_string()),
|
||||
key2: DecodeDifferent::Decoded("u16".to_string()),
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key2_hasher: StorageHasher::Twox64Concat,
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("DoubleMap2".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
value: DecodeDifferent::Decoded("u64".to_string()),
|
||||
key1: DecodeDifferent::Decoded("u16".to_string()),
|
||||
key2: DecodeDifferent::Decoded("u32".to_string()),
|
||||
hasher: StorageHasher::Twox64Concat,
|
||||
key2_hasher: StorageHasher::Blake2_128Concat,
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("NMap".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::NMap {
|
||||
keys: DecodeDifferent::Decoded(vec!["u8".to_string()]),
|
||||
hashers: DecodeDifferent::Decoded(vec![StorageHasher::Blake2_128Concat]),
|
||||
value: DecodeDifferent::Decoded("u32".to_string()),
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("NMap2".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::NMap {
|
||||
keys: DecodeDifferent::Decoded(vec!["u16".to_string(), "u32".to_string()]),
|
||||
hashers: DecodeDifferent::Decoded(vec![
|
||||
StorageHasher::Twox64Concat,
|
||||
StorageHasher::Blake2_128Concat,
|
||||
]),
|
||||
value: DecodeDifferent::Decoded("u64".to_string()),
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("ConditionalValue".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Decoded("u32".to_string())),
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("ConditionalMap".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: DecodeDifferent::Decoded("u16".to_string()),
|
||||
value: DecodeDifferent::Decoded("u32".to_string()),
|
||||
hasher: StorageHasher::Twox64Concat,
|
||||
unused: false,
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("ConditionalDoubleMap".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
value: DecodeDifferent::Decoded("u32".to_string()),
|
||||
key1: DecodeDifferent::Decoded("u8".to_string()),
|
||||
key2: DecodeDifferent::Decoded("u16".to_string()),
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key2_hasher: StorageHasher::Twox64Concat,
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
#[cfg(feature = "conditional-storage")]
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("ConditionalNMap".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::NMap {
|
||||
keys: DecodeDifferent::Decoded(vec!["u8".to_string(), "u16".to_string()]),
|
||||
hashers: DecodeDifferent::Decoded(vec![
|
||||
StorageHasher::Blake2_128Concat,
|
||||
StorageHasher::Twox64Concat,
|
||||
]),
|
||||
value: DecodeDifferent::Decoded("u32".to_string()),
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
]),
|
||||
})),
|
||||
calls: Some(DecodeDifferent::Decoded(vec![
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Decoded("foo".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec![
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Decoded("_foo".to_string()),
|
||||
ty: DecodeDifferent::Decoded("Compact<u32>".to_string()),
|
||||
},
|
||||
FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Decoded("_bar".to_string()),
|
||||
ty: DecodeDifferent::Decoded("u32".to_string()),
|
||||
},
|
||||
]),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" Doc comment put in metadata".to_string()
|
||||
]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Decoded("foo_transactional".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec![FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Decoded("foo".to_string()),
|
||||
ty: DecodeDifferent::Decoded("Compact<u32>".to_string()),
|
||||
}]),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" Doc comment put in metadata".to_string()
|
||||
]),
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Decoded("foo_no_post_info".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec![]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
])),
|
||||
event: Some(DecodeDifferent::Decoded(vec![
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Decoded("Proposed".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec![
|
||||
"<T as frame_system::Config>::AccountId".to_string()
|
||||
]),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" doc comment put in metadata".to_string()
|
||||
]),
|
||||
},
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Decoded("Spending".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec!["Balance".to_string()]),
|
||||
documentation: DecodeDifferent::Decoded(vec![" doc".to_string()]),
|
||||
},
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Decoded("Something".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec!["Other".to_string()]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Decoded("SomethingElse".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec![
|
||||
"<T::AccountId as SomeAssociation1>::_1".to_string()
|
||||
]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
])),
|
||||
constants: DecodeDifferent::Decoded(vec![
|
||||
ModuleConstantMetadata {
|
||||
name: DecodeDifferent::Decoded("MyGetParam".to_string()),
|
||||
ty: DecodeDifferent::Decoded("u32".to_string()),
|
||||
value: DecodeDifferent::Decoded(vec![10, 0, 0, 0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" Some comment".to_string(),
|
||||
" Some comment".to_string(),
|
||||
]),
|
||||
},
|
||||
ModuleConstantMetadata {
|
||||
name: DecodeDifferent::Decoded("MyGetParam2".to_string()),
|
||||
ty: DecodeDifferent::Decoded("u32".to_string()),
|
||||
value: DecodeDifferent::Decoded(vec![11, 0, 0, 0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" Some comment".to_string(),
|
||||
" Some comment".to_string(),
|
||||
]),
|
||||
},
|
||||
ModuleConstantMetadata {
|
||||
name: DecodeDifferent::Decoded("MyGetParam3".to_string()),
|
||||
ty: DecodeDifferent::Decoded("<T::AccountId as SomeAssociation1>::_1".to_string()),
|
||||
value: DecodeDifferent::Decoded(vec![12, 0, 0, 0, 0, 0, 0, 0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
ModuleConstantMetadata {
|
||||
name: DecodeDifferent::Decoded("some_extra".to_string()),
|
||||
ty: DecodeDifferent::Decoded("T::AccountId".to_string()),
|
||||
value: DecodeDifferent::Decoded(vec![100, 0, 0, 0, 0, 0, 0, 0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" Some doc".to_string(),
|
||||
" Some doc".to_string(),
|
||||
]),
|
||||
},
|
||||
ModuleConstantMetadata {
|
||||
name: DecodeDifferent::Decoded("some_extra_extra".to_string()),
|
||||
ty: DecodeDifferent::Decoded("T::AccountId".to_string()),
|
||||
value: DecodeDifferent::Decoded(vec![0, 0, 0, 0, 0, 0, 0, 0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![" Some doc".to_string()]),
|
||||
},
|
||||
]),
|
||||
errors: DecodeDifferent::Decoded(vec![ErrorMetadata {
|
||||
name: DecodeDifferent::Decoded("InsufficientProposersBalance".to_string()),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" doc comment put into metadata".to_string()
|
||||
]),
|
||||
}]),
|
||||
ty: StorageEntryType::Plain(meta_type::<Vec<u32>>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
}],
|
||||
}),
|
||||
calls: Some(meta_type::<pallet2::Call<Runtime>>().into()),
|
||||
event: Some(PalletEventMetadata { ty: meta_type::<pallet2::Event>() }),
|
||||
constants: vec![],
|
||||
error: None,
|
||||
},
|
||||
];
|
||||
|
||||
let extrinsic = ExtrinsicMetadata {
|
||||
ty: meta_type::<UncheckedExtrinsic>(),
|
||||
version: 4,
|
||||
signed_extensions: vec![SignedExtensionMetadata {
|
||||
identifier: "UnitSignedExtension",
|
||||
ty: meta_type::<()>(),
|
||||
additional_signed: meta_type::<()>(),
|
||||
}],
|
||||
};
|
||||
|
||||
let metadata = match Runtime::metadata().1 {
|
||||
RuntimeMetadata::V13(metadata) => metadata,
|
||||
_ => panic!("metadata has been bump, test needs to be updated"),
|
||||
let expected_metadata: RuntimeMetadataPrefixed =
|
||||
RuntimeMetadataLastVersion::new(pallets, extrinsic, meta_type::<Runtime>()).into();
|
||||
let expected_metadata = match expected_metadata.1 {
|
||||
RuntimeMetadata::V14(metadata) => metadata,
|
||||
_ => panic!("metadata has been bumped, test needs to be updated"),
|
||||
};
|
||||
|
||||
let modules_metadata = match metadata.modules {
|
||||
DecodeDifferent::Encode(modules_metadata) => modules_metadata,
|
||||
_ => unreachable!(),
|
||||
let actual_metadata = match Runtime::metadata().1 {
|
||||
RuntimeMetadata::V14(metadata) => metadata,
|
||||
_ => panic!("metadata has been bumped, test needs to be updated"),
|
||||
};
|
||||
|
||||
let pallet_metadata = ModuleMetadata::decode(&mut &modules_metadata[1].encode()[..]).unwrap();
|
||||
|
||||
pretty_assertions::assert_eq!(pallet_metadata, expected_pallet_metadata);
|
||||
pretty_assertions::assert_eq!(actual_metadata.pallets[1], expected_metadata.pallets[1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -99,7 +99,7 @@ mod pallet_old {
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::SomeAssociation;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_support::{pallet_prelude::*, scale_info};
|
||||
use frame_system::{ensure_root, pallet_prelude::*};
|
||||
|
||||
#[pallet::config]
|
||||
@@ -110,7 +110,8 @@ pub mod pallet {
|
||||
+ Into<Weight>
|
||||
+ Default
|
||||
+ MaybeSerializeDeserialize
|
||||
+ SomeAssociation;
|
||||
+ SomeAssociation
|
||||
+ scale_info::StaticTypeInfo;
|
||||
#[pallet::constant]
|
||||
type SomeConst: Get<Self::Balance>;
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
@@ -155,7 +156,6 @@ pub mod pallet {
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(fn deposit_event)]
|
||||
#[pallet::metadata(T::Balance = "Balance")]
|
||||
pub enum Event<T: Config> {
|
||||
/// Dummy event, just here so there's a generic type that's used.
|
||||
Dummy(T::Balance),
|
||||
@@ -279,22 +279,71 @@ frame_support::construct_runtime!(
|
||||
mod test {
|
||||
use super::{pallet, pallet_old, Runtime};
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::{form::PortableForm, Variant};
|
||||
|
||||
#[test]
|
||||
fn metadata() {
|
||||
let metadata = Runtime::metadata();
|
||||
let modules = match metadata.1 {
|
||||
frame_metadata::RuntimeMetadata::V13(frame_metadata::RuntimeMetadataV13 {
|
||||
modules: frame_metadata::DecodeDifferent::Encode(m),
|
||||
..
|
||||
}) => m,
|
||||
let (pallets, types) = match metadata.1 {
|
||||
frame_support::metadata::RuntimeMetadata::V14(metadata) =>
|
||||
(metadata.pallets, metadata.types),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
pretty_assertions::assert_eq!(modules[1].storage, modules[2].storage);
|
||||
pretty_assertions::assert_eq!(modules[1].calls, modules[2].calls);
|
||||
pretty_assertions::assert_eq!(modules[1].event, modules[2].event);
|
||||
pretty_assertions::assert_eq!(modules[1].constants, modules[2].constants);
|
||||
pretty_assertions::assert_eq!(modules[1].errors, modules[2].errors);
|
||||
|
||||
let assert_meta_types = |ty_id1, ty_id2| {
|
||||
let ty1 = types.resolve(ty_id1).map(|ty| ty.type_def());
|
||||
let ty2 = types.resolve(ty_id2).map(|ty| ty.type_def());
|
||||
pretty_assertions::assert_eq!(ty1, ty2);
|
||||
};
|
||||
|
||||
let get_enum_variants = |ty_id| match types.resolve(ty_id).map(|ty| ty.type_def()) {
|
||||
Some(ty) => match ty {
|
||||
scale_info::TypeDef::Variant(var) => var.variants(),
|
||||
_ => panic!("Expected variant type"),
|
||||
},
|
||||
_ => panic!("No type found"),
|
||||
};
|
||||
|
||||
let assert_enum_variants = |vs1: &[Variant<PortableForm>],
|
||||
vs2: &[Variant<PortableForm>]| {
|
||||
assert_eq!(vs1.len(), vs2.len());
|
||||
for i in 0..vs1.len() {
|
||||
let v1 = &vs2[i];
|
||||
let v2 = &vs2[i];
|
||||
assert_eq!(v1.fields().len(), v2.fields().len());
|
||||
for f in 0..v1.fields().len() {
|
||||
let f1 = &v1.fields()[f];
|
||||
let f2 = &v2.fields()[f];
|
||||
pretty_assertions::assert_eq!(f1.name(), f2.name());
|
||||
pretty_assertions::assert_eq!(f1.ty(), f2.ty());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pretty_assertions::assert_eq!(pallets[1].storage, pallets[2].storage);
|
||||
|
||||
let calls1 = pallets[1].calls.as_ref().unwrap();
|
||||
let calls2 = pallets[2].calls.as_ref().unwrap();
|
||||
assert_meta_types(calls1.ty.id(), calls2.ty.id());
|
||||
|
||||
// event: check variants and fields but ignore the type name which will be different
|
||||
let event1_variants = get_enum_variants(pallets[1].event.as_ref().unwrap().ty.id());
|
||||
let event2_variants = get_enum_variants(pallets[2].event.as_ref().unwrap().ty.id());
|
||||
assert_enum_variants(event1_variants, event2_variants);
|
||||
|
||||
let err1 = get_enum_variants(pallets[1].error.as_ref().unwrap().ty.id())
|
||||
.iter()
|
||||
.filter(|v| v.name() == "__Ignore")
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let err2 = get_enum_variants(pallets[2].error.as_ref().unwrap().ty.id())
|
||||
.iter()
|
||||
.filter(|v| v.name() == "__Ignore")
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
assert_enum_variants(&err1, &err2);
|
||||
|
||||
pretty_assertions::assert_eq!(pallets[1].constants, pallets[2].constants);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -309,10 +358,10 @@ mod test {
|
||||
|
||||
assert_eq!(
|
||||
pallet_old::Call::<Runtime>::decode(
|
||||
&mut &pallet::Call::<Runtime>::set_dummy(10).encode()[..]
|
||||
&mut &pallet::Call::<Runtime>::set_dummy { new_value: 10 }.encode()[..]
|
||||
)
|
||||
.unwrap(),
|
||||
pallet_old::Call::<Runtime>::set_dummy(10),
|
||||
pallet_old::Call::<Runtime>::set_dummy { new_value: 10 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ mod pallet_old {
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_support::{pallet_prelude::*, scale_info};
|
||||
use frame_system::{ensure_root, pallet_prelude::*};
|
||||
|
||||
#[pallet::config]
|
||||
@@ -95,7 +95,8 @@ pub mod pallet {
|
||||
+ From<u32>
|
||||
+ Into<Weight>
|
||||
+ Default
|
||||
+ MaybeSerializeDeserialize;
|
||||
+ MaybeSerializeDeserialize
|
||||
+ scale_info::StaticTypeInfo;
|
||||
#[pallet::constant]
|
||||
type SomeConst: Get<Self::Balance>;
|
||||
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
@@ -140,7 +141,6 @@ pub mod pallet {
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(fn deposit_event)]
|
||||
#[pallet::metadata(T::Balance = "Balance")]
|
||||
pub enum Event<T: Config<I>, I: 'static = ()> {
|
||||
/// Dummy event, just here so there's a generic type that's used.
|
||||
Dummy(T::Balance),
|
||||
@@ -282,23 +282,66 @@ frame_support::construct_runtime!(
|
||||
mod test {
|
||||
use super::{pallet, pallet_old, Runtime};
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::{form::PortableForm, Variant};
|
||||
|
||||
#[test]
|
||||
fn metadata() {
|
||||
let metadata = Runtime::metadata();
|
||||
let modules = match metadata.1 {
|
||||
frame_metadata::RuntimeMetadata::V13(frame_metadata::RuntimeMetadataV13 {
|
||||
modules: frame_metadata::DecodeDifferent::Encode(m),
|
||||
..
|
||||
}) => m,
|
||||
let (pallets, types) = match metadata.1 {
|
||||
frame_support::metadata::RuntimeMetadata::V14(metadata) =>
|
||||
(metadata.pallets, metadata.types),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let get_enum_variants = |ty_id| match types.resolve(ty_id).map(|ty| ty.type_def()) {
|
||||
Some(ty) => match ty {
|
||||
scale_info::TypeDef::Variant(var) => var.variants(),
|
||||
_ => panic!("Expected variant type"),
|
||||
},
|
||||
_ => panic!("No type found"),
|
||||
};
|
||||
|
||||
let assert_enum_variants = |vs1: &[Variant<PortableForm>],
|
||||
vs2: &[Variant<PortableForm>]| {
|
||||
assert_eq!(vs1.len(), vs2.len());
|
||||
for i in 0..vs1.len() {
|
||||
let v1 = &vs2[i];
|
||||
let v2 = &vs2[i];
|
||||
assert_eq!(v1.fields().len(), v2.fields().len());
|
||||
for f in 0..v1.fields().len() {
|
||||
let f1 = &v1.fields()[f];
|
||||
let f2 = &v2.fields()[f];
|
||||
pretty_assertions::assert_eq!(f1.name(), f2.name());
|
||||
pretty_assertions::assert_eq!(f1.ty(), f2.ty());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for i in vec![1, 3, 5].into_iter() {
|
||||
pretty_assertions::assert_eq!(modules[i].storage, modules[i + 1].storage);
|
||||
pretty_assertions::assert_eq!(modules[i].calls, modules[i + 1].calls);
|
||||
pretty_assertions::assert_eq!(modules[i].event, modules[i + 1].event);
|
||||
pretty_assertions::assert_eq!(modules[i].constants, modules[i + 1].constants);
|
||||
pretty_assertions::assert_eq!(modules[i].errors, modules[i + 1].errors);
|
||||
pretty_assertions::assert_eq!(pallets[i].storage, pallets[i + 1].storage);
|
||||
|
||||
let call1_variants = get_enum_variants(pallets[i].calls.as_ref().unwrap().ty.id());
|
||||
let call2_variants = get_enum_variants(pallets[i + 1].calls.as_ref().unwrap().ty.id());
|
||||
assert_enum_variants(call1_variants, call2_variants);
|
||||
|
||||
// event: check variants and fields but ignore the type name which will be different
|
||||
let event1_variants = get_enum_variants(pallets[i].event.as_ref().unwrap().ty.id());
|
||||
let event2_variants = get_enum_variants(pallets[i + 1].event.as_ref().unwrap().ty.id());
|
||||
assert_enum_variants(event1_variants, event2_variants);
|
||||
|
||||
let err1 = get_enum_variants(pallets[i].error.as_ref().unwrap().ty.id())
|
||||
.iter()
|
||||
.filter(|v| v.name() == "__Ignore")
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let err2 = get_enum_variants(pallets[i + 1].error.as_ref().unwrap().ty.id())
|
||||
.iter()
|
||||
.filter(|v| v.name() == "__Ignore")
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
assert_enum_variants(&err1, &err2);
|
||||
|
||||
pretty_assertions::assert_eq!(pallets[i].constants, pallets[i + 1].constants);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,10 +357,10 @@ mod test {
|
||||
|
||||
assert_eq!(
|
||||
pallet_old::Call::<Runtime>::decode(
|
||||
&mut &pallet::Call::<Runtime>::set_dummy(10).encode()[..]
|
||||
&mut &pallet::Call::<Runtime>::set_dummy { new_value: 10 }.encode()[..]
|
||||
)
|
||||
.unwrap(),
|
||||
pallet_old::Call::<Runtime>::set_dummy(10),
|
||||
pallet_old::Call::<Runtime>::set_dummy { new_value: 10 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ use sp_runtime::DispatchError;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_support::{pallet_prelude::*, scale_info};
|
||||
use frame_system::pallet_prelude::*;
|
||||
use sp_std::any::TypeId;
|
||||
|
||||
@@ -39,7 +39,7 @@ pub mod pallet {
|
||||
pub trait Config<I: 'static = ()>: frame_system::Config {
|
||||
#[pallet::constant]
|
||||
type MyGetParam: Get<u32>;
|
||||
type Balance: Parameter + Default;
|
||||
type Balance: Parameter + Default + scale_info::StaticTypeInfo;
|
||||
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,6 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::metadata(BalanceOf<T, I> = "Balance", u32 = "Other")]
|
||||
#[pallet::generate_deposit(fn deposit_event)]
|
||||
pub enum Event<T: Config<I>, I: 'static = ()> {
|
||||
/// doc comment put in metadata
|
||||
@@ -157,7 +156,16 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::origin]
|
||||
#[derive(EqNoBound, RuntimeDebugNoBound, CloneNoBound, PartialEqNoBound, Encode, Decode)]
|
||||
#[derive(
|
||||
EqNoBound,
|
||||
RuntimeDebugNoBound,
|
||||
CloneNoBound,
|
||||
PartialEqNoBound,
|
||||
Encode,
|
||||
Decode,
|
||||
scale_info::TypeInfo,
|
||||
)]
|
||||
#[scale_info(skip_type_params(T, I))]
|
||||
pub struct Origin<T, I = ()>(PhantomData<(T, I)>);
|
||||
|
||||
#[pallet::validate_unsigned]
|
||||
@@ -306,7 +314,7 @@ frame_support::construct_runtime!(
|
||||
|
||||
#[test]
|
||||
fn call_expand() {
|
||||
let call_foo = pallet::Call::<Runtime>::foo(3);
|
||||
let call_foo = pallet::Call::<Runtime>::foo { foo: 3 };
|
||||
assert_eq!(
|
||||
call_foo.get_dispatch_info(),
|
||||
DispatchInfo { weight: 3, class: DispatchClass::Normal, pays_fee: Pays::Yes }
|
||||
@@ -314,7 +322,7 @@ fn call_expand() {
|
||||
assert_eq!(call_foo.get_call_name(), "foo");
|
||||
assert_eq!(pallet::Call::<Runtime>::get_call_names(), &["foo", "foo_transactional"]);
|
||||
|
||||
let call_foo = pallet::Call::<Runtime, pallet::Instance1>::foo(3);
|
||||
let call_foo = pallet::Call::<Runtime, pallet::Instance1>::foo { foo: 3 };
|
||||
assert_eq!(
|
||||
call_foo.get_dispatch_info(),
|
||||
DispatchInfo { weight: 3, class: DispatchClass::Normal, pays_fee: Pays::Yes }
|
||||
@@ -369,7 +377,9 @@ fn instance_expand() {
|
||||
fn pallet_expand_deposit_event() {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
frame_system::Pallet::<Runtime>::set_block_number(1);
|
||||
pallet::Call::<Runtime>::foo(3).dispatch_bypass_filter(None.into()).unwrap();
|
||||
pallet::Call::<Runtime>::foo { foo: 3 }
|
||||
.dispatch_bypass_filter(None.into())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
frame_system::Pallet::<Runtime>::events()[0].event,
|
||||
Event::Example(pallet::Event::Something(3)),
|
||||
@@ -378,7 +388,7 @@ fn pallet_expand_deposit_event() {
|
||||
|
||||
TestExternalities::default().execute_with(|| {
|
||||
frame_system::Pallet::<Runtime>::set_block_number(1);
|
||||
pallet::Call::<Runtime, pallet::Instance1>::foo(3)
|
||||
pallet::Call::<Runtime, pallet::Instance1>::foo { foo: 3 }
|
||||
.dispatch_bypass_filter(None.into())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
@@ -544,183 +554,207 @@ fn pallet_on_genesis() {
|
||||
|
||||
#[test]
|
||||
fn metadata() {
|
||||
use codec::{Decode, Encode};
|
||||
use frame_metadata::*;
|
||||
use frame_support::metadata::*;
|
||||
|
||||
let expected_pallet_metadata = ModuleMetadata {
|
||||
index: 1,
|
||||
name: DecodeDifferent::Decoded("Example".to_string()),
|
||||
storage: Some(DecodeDifferent::Decoded(StorageMetadata {
|
||||
prefix: DecodeDifferent::Decoded("Example".to_string()),
|
||||
entries: DecodeDifferent::Decoded(vec![
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("Value".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(DecodeDifferent::Decoded("u32".to_string())),
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("Map".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: DecodeDifferent::Decoded("u8".to_string()),
|
||||
value: DecodeDifferent::Decoded("u16".to_string()),
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
unused: false,
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("Map2".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: DecodeDifferent::Decoded("u16".to_string()),
|
||||
value: DecodeDifferent::Decoded("u32".to_string()),
|
||||
hasher: StorageHasher::Twox64Concat,
|
||||
unused: false,
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("DoubleMap".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
value: DecodeDifferent::Decoded("u32".to_string()),
|
||||
key1: DecodeDifferent::Decoded("u8".to_string()),
|
||||
key2: DecodeDifferent::Decoded("u16".to_string()),
|
||||
hasher: StorageHasher::Blake2_128Concat,
|
||||
key2_hasher: StorageHasher::Twox64Concat,
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("DoubleMap2".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::DoubleMap {
|
||||
value: DecodeDifferent::Decoded("u64".to_string()),
|
||||
key1: DecodeDifferent::Decoded("u16".to_string()),
|
||||
key2: DecodeDifferent::Decoded("u32".to_string()),
|
||||
hasher: StorageHasher::Twox64Concat,
|
||||
key2_hasher: StorageHasher::Blake2_128Concat,
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("NMap".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::NMap {
|
||||
keys: DecodeDifferent::Decoded(vec!["u8".to_string()]),
|
||||
hashers: DecodeDifferent::Decoded(vec![StorageHasher::Blake2_128Concat]),
|
||||
value: DecodeDifferent::Decoded("u32".to_string()),
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: DecodeDifferent::Decoded("NMap2".to_string()),
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::NMap {
|
||||
keys: DecodeDifferent::Decoded(vec!["u16".to_string(), "u32".to_string()]),
|
||||
hashers: DecodeDifferent::Decoded(vec![
|
||||
StorageHasher::Twox64Concat,
|
||||
StorageHasher::Blake2_128Concat,
|
||||
]),
|
||||
value: DecodeDifferent::Decoded("u64".to_string()),
|
||||
},
|
||||
default: DecodeDifferent::Decoded(vec![0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
},
|
||||
]),
|
||||
})),
|
||||
calls: Some(DecodeDifferent::Decoded(vec![
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Decoded("foo".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec![FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Decoded("_foo".to_string()),
|
||||
ty: DecodeDifferent::Decoded("Compact<u32>".to_string()),
|
||||
}]),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" Doc comment put in metadata".to_string()
|
||||
]),
|
||||
let system_pallet_metadata = PalletMetadata {
|
||||
index: 0,
|
||||
name: "System",
|
||||
storage: None,
|
||||
calls: Some(scale_info::meta_type::<frame_system::Call<Runtime>>().into()),
|
||||
event: Some(PalletEventMetadata {
|
||||
ty: scale_info::meta_type::<frame_system::Event<Runtime>>(),
|
||||
}),
|
||||
constants: vec![
|
||||
PalletConstantMetadata {
|
||||
name: "BlockWeights",
|
||||
ty: scale_info::meta_type::<frame_system::limits::BlockWeights>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
FunctionMetadata {
|
||||
name: DecodeDifferent::Decoded("foo_transactional".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec![FunctionArgumentMetadata {
|
||||
name: DecodeDifferent::Decoded("_foo".to_string()),
|
||||
ty: DecodeDifferent::Decoded("Compact<u32>".to_string()),
|
||||
}]),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" Doc comment put in metadata".to_string()
|
||||
]),
|
||||
PalletConstantMetadata {
|
||||
name: "BlockLength",
|
||||
ty: scale_info::meta_type::<frame_system::limits::BlockLength>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
])),
|
||||
event: Some(DecodeDifferent::Decoded(vec![
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Decoded("Proposed".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec![
|
||||
"<T as frame_system::Config>::AccountId".to_string()
|
||||
]),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" doc comment put in metadata".to_string()
|
||||
]),
|
||||
PalletConstantMetadata {
|
||||
name: "BlockHashCount",
|
||||
ty: scale_info::meta_type::<u32>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Decoded("Spending".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec!["Balance".to_string()]),
|
||||
documentation: DecodeDifferent::Decoded(vec![" doc".to_string()]),
|
||||
PalletConstantMetadata {
|
||||
name: "DbWeight",
|
||||
ty: scale_info::meta_type::<frame_support::weights::RuntimeDbWeight>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
EventMetadata {
|
||||
name: DecodeDifferent::Decoded("Something".to_string()),
|
||||
arguments: DecodeDifferent::Decoded(vec!["Other".to_string()]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
PalletConstantMetadata {
|
||||
name: "Version",
|
||||
ty: scale_info::meta_type::<sp_version::RuntimeVersion>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
])),
|
||||
constants: DecodeDifferent::Decoded(vec![ModuleConstantMetadata {
|
||||
name: DecodeDifferent::Decoded("MyGetParam".to_string()),
|
||||
ty: DecodeDifferent::Decoded("u32".to_string()),
|
||||
value: DecodeDifferent::Decoded(vec![10, 0, 0, 0]),
|
||||
documentation: DecodeDifferent::Decoded(vec![]),
|
||||
}]),
|
||||
errors: DecodeDifferent::Decoded(vec![ErrorMetadata {
|
||||
name: DecodeDifferent::Decoded("InsufficientProposersBalance".to_string()),
|
||||
documentation: DecodeDifferent::Decoded(vec![
|
||||
" doc comment put into metadata".to_string()
|
||||
]),
|
||||
}]),
|
||||
PalletConstantMetadata {
|
||||
name: "SS58Prefix",
|
||||
ty: scale_info::meta_type::<u16>(),
|
||||
value: vec![],
|
||||
docs: vec![],
|
||||
},
|
||||
],
|
||||
error: Some(PalletErrorMetadata {
|
||||
ty: scale_info::meta_type::<frame_system::Error<Runtime>>(),
|
||||
}),
|
||||
};
|
||||
|
||||
let mut expected_pallet_instance1_metadata = expected_pallet_metadata.clone();
|
||||
expected_pallet_instance1_metadata.name =
|
||||
DecodeDifferent::Decoded("Instance1Example".to_string());
|
||||
expected_pallet_instance1_metadata.index = 2;
|
||||
match expected_pallet_instance1_metadata.storage {
|
||||
Some(DecodeDifferent::Decoded(ref mut storage_meta)) => {
|
||||
storage_meta.prefix = DecodeDifferent::Decoded("Instance1Example".to_string());
|
||||
let example_pallet_metadata = PalletMetadata {
|
||||
index: 1,
|
||||
name: "Example",
|
||||
storage: Some(PalletStorageMetadata {
|
||||
prefix: "Example",
|
||||
entries: vec![
|
||||
StorageEntryMetadata {
|
||||
name: "Value",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Plain(scale_info::meta_type::<u32>()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "Map",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: scale_info::meta_type::<u8>(),
|
||||
value: scale_info::meta_type::<u16>(),
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "Map2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: scale_info::meta_type::<u16>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
hashers: vec![StorageHasher::Twox64Concat],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "DoubleMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
key: scale_info::meta_type::<(u8, u16)>(),
|
||||
hashers: vec![StorageHasher::Blake2_128Concat, StorageHasher::Twox64Concat],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "DoubleMap2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
value: scale_info::meta_type::<u64>(),
|
||||
key: scale_info::meta_type::<(u16, u32)>(),
|
||||
hashers: vec![StorageHasher::Twox64Concat, StorageHasher::Blake2_128Concat],
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "NMap",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: scale_info::meta_type::<u8>(),
|
||||
hashers: vec![StorageHasher::Blake2_128Concat],
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadata {
|
||||
name: "NMap2",
|
||||
modifier: StorageEntryModifier::Optional,
|
||||
ty: StorageEntryType::Map {
|
||||
key: scale_info::meta_type::<(u16, u32)>(),
|
||||
hashers: vec![StorageHasher::Twox64Concat, StorageHasher::Blake2_128Concat],
|
||||
value: scale_info::meta_type::<u64>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
],
|
||||
}),
|
||||
calls: Some(scale_info::meta_type::<pallet::Call<Runtime>>().into()),
|
||||
event: Some(PalletEventMetadata { ty: scale_info::meta_type::<pallet::Event<Runtime>>() }),
|
||||
constants: vec![PalletConstantMetadata {
|
||||
name: "MyGetParam",
|
||||
ty: scale_info::meta_type::<u32>(),
|
||||
value: vec![10, 0, 0, 0],
|
||||
docs: vec![],
|
||||
}],
|
||||
error: Some(PalletErrorMetadata { ty: scale_info::meta_type::<pallet::Error<Runtime>>() }),
|
||||
};
|
||||
|
||||
let mut example_pallet_instance1_metadata = example_pallet_metadata.clone();
|
||||
example_pallet_instance1_metadata.name = "Instance1Example";
|
||||
example_pallet_instance1_metadata.index = 2;
|
||||
match example_pallet_instance1_metadata.calls {
|
||||
Some(ref mut calls_meta) => {
|
||||
calls_meta.ty = scale_info::meta_type::<pallet::Call<Runtime, pallet::Instance1>>();
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
match example_pallet_instance1_metadata.event {
|
||||
Some(ref mut event_meta) => {
|
||||
event_meta.ty = scale_info::meta_type::<pallet::Event<Runtime, pallet::Instance1>>();
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
match example_pallet_instance1_metadata.error {
|
||||
Some(ref mut error_meta) => {
|
||||
error_meta.ty = scale_info::meta_type::<pallet::Error<Runtime, pallet::Instance1>>();
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
match example_pallet_instance1_metadata.storage {
|
||||
Some(ref mut storage_meta) => {
|
||||
storage_meta.prefix = "Instance1Example";
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let metadata = match Runtime::metadata().1 {
|
||||
RuntimeMetadata::V13(metadata) => metadata,
|
||||
_ => panic!("metadata has been bump, test needs to be updated"),
|
||||
let pallets =
|
||||
vec![system_pallet_metadata, example_pallet_metadata, example_pallet_instance1_metadata];
|
||||
|
||||
let extrinsic = ExtrinsicMetadata {
|
||||
ty: scale_info::meta_type::<UncheckedExtrinsic>(),
|
||||
version: 4,
|
||||
signed_extensions: vec![SignedExtensionMetadata {
|
||||
identifier: "UnitSignedExtension",
|
||||
ty: scale_info::meta_type::<()>(),
|
||||
additional_signed: scale_info::meta_type::<()>(),
|
||||
}],
|
||||
};
|
||||
|
||||
let modules_metadata = match metadata.modules {
|
||||
DecodeDifferent::Encode(modules_metadata) => modules_metadata,
|
||||
_ => unreachable!(),
|
||||
let expected_metadata: RuntimeMetadataPrefixed =
|
||||
RuntimeMetadataLastVersion::new(pallets, extrinsic, scale_info::meta_type::<Runtime>())
|
||||
.into();
|
||||
let expected_metadata = match expected_metadata.1 {
|
||||
RuntimeMetadata::V14(metadata) => metadata,
|
||||
_ => panic!("metadata has been bumped, test needs to be updated"),
|
||||
};
|
||||
|
||||
let pallet_metadata = ModuleMetadata::decode(&mut &modules_metadata[1].encode()[..]).unwrap();
|
||||
let pallet_instance1_metadata =
|
||||
ModuleMetadata::decode(&mut &modules_metadata[2].encode()[..]).unwrap();
|
||||
let actual_metadata = match Runtime::metadata().1 {
|
||||
RuntimeMetadata::V14(metadata) => metadata,
|
||||
_ => panic!("metadata has been bumped, test needs to be updated"),
|
||||
};
|
||||
|
||||
pretty_assertions::assert_eq!(pallet_metadata, expected_pallet_metadata);
|
||||
pretty_assertions::assert_eq!(pallet_instance1_metadata, expected_pallet_instance1_metadata);
|
||||
pretty_assertions::assert_eq!(actual_metadata.pallets[1], expected_metadata.pallets[1]);
|
||||
pretty_assertions::assert_eq!(actual_metadata.pallets[2], expected_metadata.pallets[2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -5,7 +5,7 @@ mod pallet {
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
type Bar: codec::Codec;
|
||||
type Bar: codec::Codec + scale_info::TypeInfo;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:41
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:36
|
||||
|
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
||||
| ^^^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
||||
|
|
||||
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
|
||||
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&<T as pallet::Config>::Bar`
|
||||
= note: required for the cast to the object type `dyn std::fmt::Debug`
|
||||
|
||||
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:41
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:36
|
||||
|
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
||||
| ^^^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
||||
|
|
||||
= note: required by `clone`
|
||||
|
||||
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:41
|
||||
--> $DIR/call_argument_invalid_bound.rs:20:36
|
||||
|
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^
|
||||
| ^^^
|
||||
|
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
|
||||
@@ -5,7 +5,7 @@ mod pallet {
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
type Bar;
|
||||
type Bar: scale_info::TypeInfo;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:36
|
||||
|
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
||||
| ^^^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
||||
|
|
||||
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
|
||||
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&<T as pallet::Config>::Bar`
|
||||
= note: required for the cast to the object type `dyn std::fmt::Debug`
|
||||
|
||||
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:36
|
||||
|
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
||||
| ^^^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
||||
|
|
||||
= note: required by `clone`
|
||||
|
||||
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:36
|
||||
|
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^
|
||||
| ^^^
|
||||
|
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
@@ -28,23 +28,23 @@ help: consider further restricting this bound
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeEncode` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:36
|
||||
|
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `WrapperTypeEncode` is not implemented for `<T as pallet::Config>::Bar`
|
||||
| ^^^ the trait `WrapperTypeEncode` is not implemented for `<T as pallet::Config>::Bar`
|
||||
|
|
||||
::: $CARGO/parity-scale-codec-2.2.0/src/codec.rs
|
||||
|
|
||||
| fn encode_to<T: Output + ?Sized>(&self, dest: &mut T) {
|
||||
| ------ required by this bound in `encode_to`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `<T as pallet::Config>::Bar`
|
||||
= note: required because of the requirements on the impl of `Encode` for `<T as pallet::Config>::Bar`
|
||||
|
||||
error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeDecode` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:41
|
||||
--> $DIR/call_argument_invalid_bound_2.rs:20:36
|
||||
|
|
||||
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
|
||||
| ^ the trait `WrapperTypeDecode` is not implemented for `<T as pallet::Config>::Bar`
|
||||
| ^^^ the trait `WrapperTypeDecode` is not implemented for `<T as pallet::Config>::Bar`
|
||||
|
|
||||
::: $CARGO/parity-scale-codec-2.2.0/src/codec.rs
|
||||
|
|
||||
|
||||
@@ -13,7 +13,7 @@ mod pallet {
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
#[derive(Encode, Decode)]
|
||||
#[derive(Encode, Decode, scale_info::TypeInfo)]
|
||||
struct Bar;
|
||||
|
||||
#[pallet::call]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error[E0277]: `Bar` doesn't implement `std::fmt::Debug`
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:41
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:36
|
||||
|
|
||||
22 | pub fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
| ^^^ `Bar` cannot be formatted using `{:?}`
|
||||
| ^^^ `Bar` cannot be formatted using `{:?}`
|
||||
|
|
||||
= help: the trait `std::fmt::Debug` is not implemented for `Bar`
|
||||
= note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
|
||||
@@ -10,17 +10,17 @@ error[E0277]: `Bar` doesn't implement `std::fmt::Debug`
|
||||
= note: required for the cast to the object type `dyn std::fmt::Debug`
|
||||
|
||||
error[E0277]: the trait bound `Bar: Clone` is not satisfied
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:41
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:36
|
||||
|
|
||||
22 | pub fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
| ^^^ the trait `Clone` is not implemented for `Bar`
|
||||
| ^^^ the trait `Clone` is not implemented for `Bar`
|
||||
|
|
||||
= note: required by `clone`
|
||||
|
||||
error[E0369]: binary operation `==` cannot be applied to type `&Bar`
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:41
|
||||
--> $DIR/call_argument_invalid_bound_3.rs:22:36
|
||||
|
|
||||
22 | pub fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
|
||||
| ^^^
|
||||
| ^^^
|
||||
|
|
||||
= note: an implementation of `std::cmp::PartialEq` might be missing for `&Bar`
|
||||
|
||||
+18
-8
@@ -1,3 +1,13 @@
|
||||
error[E0277]: the trait bound `Bar: TypeInfo` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12
|
||||
|
|
||||
20 | #[pallet::storage]
|
||||
| ^^^^^^^ the trait `TypeInfo` is not implemented for `Bar`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `StaticTypeInfo` for `Bar`
|
||||
= note: required because of the requirements on the impl of `frame_support::storage::StorageEntryMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `NAME`
|
||||
|
||||
error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12
|
||||
|
|
||||
@@ -6,8 +16,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Decode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
|
||||
= note: required because of the requirements on the impl of `StorageValueMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `frame_support::storage::types::StorageValueMetadata::NAME`
|
||||
= note: required because of the requirements on the impl of `frame_support::storage::StorageEntryMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `NAME`
|
||||
|
||||
error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12
|
||||
@@ -17,8 +27,8 @@ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied
|
||||
|
|
||||
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
|
||||
= note: required because of the requirements on the impl of `StorageValueMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `frame_support::storage::types::StorageValueMetadata::NAME`
|
||||
= note: required because of the requirements on the impl of `frame_support::storage::StorageEntryMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `NAME`
|
||||
|
||||
error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12
|
||||
@@ -26,11 +36,11 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
|
||||
20 | #[pallet::storage]
|
||||
| ^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `Encode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
|
||||
= note: required because of the requirements on the impl of `StorageValueMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `frame_support::storage::types::StorageValueMetadata::NAME`
|
||||
= note: required because of the requirements on the impl of `frame_support::storage::StorageEntryMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `NAME`
|
||||
|
||||
error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12
|
||||
@@ -60,7 +70,7 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
|
||||
9 | #[pallet::pallet]
|
||||
| ^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `Encode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
|
||||
= note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
|
||||
+18
-8
@@ -1,3 +1,13 @@
|
||||
error[E0277]: the trait bound `Bar: TypeInfo` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12
|
||||
|
|
||||
20 | #[pallet::storage]
|
||||
| ^^^^^^^ the trait `TypeInfo` is not implemented for `Bar`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `StaticTypeInfo` for `Bar`
|
||||
= note: required because of the requirements on the impl of `frame_support::storage::StorageEntryMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `NAME`
|
||||
|
||||
error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12
|
||||
|
|
||||
@@ -6,8 +16,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Decode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
|
||||
= note: required because of the requirements on the impl of `StorageValueMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `frame_support::storage::types::StorageValueMetadata::NAME`
|
||||
= note: required because of the requirements on the impl of `frame_support::storage::StorageEntryMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `NAME`
|
||||
|
||||
error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12
|
||||
@@ -17,8 +27,8 @@ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied
|
||||
|
|
||||
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
|
||||
= note: required because of the requirements on the impl of `StorageValueMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `frame_support::storage::types::StorageValueMetadata::NAME`
|
||||
= note: required because of the requirements on the impl of `frame_support::storage::StorageEntryMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `NAME`
|
||||
|
||||
error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12
|
||||
@@ -26,11 +36,11 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
|
||||
20 | #[pallet::storage]
|
||||
| ^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `Encode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
|
||||
= note: required because of the requirements on the impl of `StorageValueMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `frame_support::storage::types::StorageValueMetadata::NAME`
|
||||
= note: required because of the requirements on the impl of `frame_support::storage::StorageEntryMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
= note: required by `NAME`
|
||||
|
||||
error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
||||
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12
|
||||
@@ -60,7 +70,7 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
|
||||
9 | #[pallet::pallet]
|
||||
| ^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `Encode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
|
||||
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
|
||||
= note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
|
||||
|
||||
@@ -16,7 +16,7 @@ mod pallet {
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
|
||||
#[derive(codec::Encode, codec::Decode)]
|
||||
#[derive(codec::Encode, codec::Decode, scale_info::TypeInfo)]
|
||||
struct Bar;
|
||||
|
||||
#[pallet::storage]
|
||||
|
||||
@@ -16,7 +16,7 @@ mod pallet {
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
|
||||
#[derive(codec::Encode, codec::Decode)]
|
||||
#[derive(codec::Encode, codec::Decode, scale_info::TypeInfo)]
|
||||
struct Bar;
|
||||
|
||||
#[pallet::storage]
|
||||
|
||||
@@ -4,6 +4,6 @@ error[E0277]: the trait bound `Bar: MaxEncodedLen` is not satisfied
|
||||
10 | #[pallet::generate_storage_info]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the trait `MaxEncodedLen` is not implemented for `Bar`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `KeyGeneratorMaxEncodedLen` for `Key<frame_support::Twox64Concat, Bar>`
|
||||
= note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageNMap<_GeneratedPrefixForStorageFoo<T>, Key<frame_support::Twox64Concat, Bar>, u32>`
|
||||
= note: required because of the requirements on the impl of `KeyGeneratorMaxEncodedLen` for `NMapKey<frame_support::Twox64Concat, Bar>`
|
||||
= note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageNMap<_GeneratedPrefixForStorageFoo<T>, NMapKey<frame_support::Twox64Concat, Bar>, u32>`
|
||||
= note: required by `storage_info`
|
||||
|
||||
@@ -26,9 +26,9 @@ pub trait Config: 'static + Eq + Clone {
|
||||
+ From<RawOrigin<Self::AccountId>>;
|
||||
|
||||
type BaseCallFilter: frame_support::traits::Contains<Self::Call>;
|
||||
type BlockNumber: Decode + Encode + EncodeLike + Clone + Default;
|
||||
type BlockNumber: Decode + Encode + EncodeLike + Clone + Default + scale_info::TypeInfo;
|
||||
type Hash;
|
||||
type AccountId: Encode + EncodeLike + Decode;
|
||||
type AccountId: Encode + EncodeLike + Decode + scale_info::TypeInfo;
|
||||
type Call;
|
||||
type Event: From<Event<Self>>;
|
||||
type PalletInfo: frame_support::traits::PalletInfo;
|
||||
@@ -68,7 +68,7 @@ frame_support::decl_error! {
|
||||
}
|
||||
|
||||
/// Origin for the system module.
|
||||
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode)]
|
||||
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode, scale_info::TypeInfo)]
|
||||
pub enum RawOrigin<AccountId> {
|
||||
Root,
|
||||
Signed(AccountId),
|
||||
|
||||
Reference in New Issue
Block a user