mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 01:41:09 +00:00
Apply some clippy lints (#11154)
* Apply some clippy hints * Revert clippy ci changes * Update client/cli/src/commands/generate.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/cli/src/commands/inspect_key.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/transactions.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/protocol.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Revert due to missing `or_default` function. * Fix compilation and simplify code * Undo change that corrupts benchmark. * fix clippy * Update client/service/test/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs remove leftovers! * Update client/tracing/src/logging/directives.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/fork-tree/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * added needed ref * Update frame/referenda/src/benchmarking.rs * Simplify byte-vec creation * let's just not overlap the ranges * Correction * cargo fmt * Update utils/frame/benchmarking-cli/src/shared/stats.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a990473cf9
commit
b581604aa7
@@ -43,12 +43,8 @@ pub fn expand_outer_config(
|
||||
|
||||
types.extend(expand_config_types(runtime, decl, &config, part_is_generic));
|
||||
fields.extend(quote!(pub #field_name: #config,));
|
||||
build_storage_calls.extend(expand_config_build_storage_call(
|
||||
scrate,
|
||||
runtime,
|
||||
decl,
|
||||
&field_name,
|
||||
));
|
||||
build_storage_calls
|
||||
.extend(expand_config_build_storage_call(scrate, runtime, decl, field_name));
|
||||
query_genesis_config_part_macros.push(quote! {
|
||||
#path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name);
|
||||
#[cfg(feature = "std")]
|
||||
|
||||
@@ -201,7 +201,7 @@ fn construct_runtime_intermediary_expansion(
|
||||
);
|
||||
}
|
||||
|
||||
Ok(expansion.into())
|
||||
Ok(expansion)
|
||||
}
|
||||
|
||||
/// All pallets have explicit definition of parts, this will expand to the runtime declaration.
|
||||
@@ -225,16 +225,16 @@ fn construct_runtime_final_expansion(
|
||||
})?;
|
||||
|
||||
let hidden_crate_name = "construct_runtime";
|
||||
let scrate = generate_crate_access(&hidden_crate_name, "frame-support");
|
||||
let scrate_decl = generate_hidden_includes(&hidden_crate_name, "frame-support");
|
||||
let scrate = generate_crate_access(hidden_crate_name, "frame-support");
|
||||
let scrate_decl = generate_hidden_includes(hidden_crate_name, "frame-support");
|
||||
|
||||
let outer_event = expand::expand_outer_event(&name, &pallets, &scrate)?;
|
||||
|
||||
let outer_origin = expand::expand_outer_origin(&name, &system_pallet, &pallets, &scrate)?;
|
||||
let outer_origin = expand::expand_outer_origin(&name, system_pallet, &pallets, &scrate)?;
|
||||
let all_pallets = decl_all_pallets(&name, pallets.iter());
|
||||
let pallet_to_index = decl_pallet_runtime_setup(&name, &pallets, &scrate);
|
||||
|
||||
let dispatch = expand::expand_outer_dispatch(&name, &system_pallet, &pallets, &scrate);
|
||||
let dispatch = expand::expand_outer_dispatch(&name, system_pallet, &pallets, &scrate);
|
||||
let metadata = expand::expand_runtime_metadata(&name, &pallets, &scrate, &unchecked_extrinsic);
|
||||
let outer_config = expand::expand_outer_config(&name, &pallets, &scrate);
|
||||
let inherent =
|
||||
|
||||
@@ -68,7 +68,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
.args
|
||||
.iter()
|
||||
.map(|(_, name, _)| {
|
||||
syn::Ident::new(&name.to_string().trim_start_matches('_'), name.span())
|
||||
syn::Ident::new(name.to_string().trim_start_matches('_'), name.span())
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
|
||||
@@ -85,7 +85,7 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
syn::Item::Enum(syn::ItemEnum { attrs, .. }) |
|
||||
syn::Item::Struct(syn::ItemStruct { attrs, .. }) |
|
||||
syn::Item::Type(syn::ItemType { attrs, .. }) => {
|
||||
if get_doc_literals(&attrs).is_empty() {
|
||||
if get_doc_literals(attrs).is_empty() {
|
||||
attrs.push(syn::parse_quote!(
|
||||
#[doc = r"
|
||||
Can be used to configure the
|
||||
|
||||
@@ -74,9 +74,7 @@ fn check_prefix_duplicates(
|
||||
),
|
||||
);
|
||||
|
||||
if let Some(other_dup_err) =
|
||||
used_prefixes.insert(counter_prefix.clone(), counter_dup_err.clone())
|
||||
{
|
||||
if let Some(other_dup_err) = used_prefixes.insert(counter_prefix, counter_dup_err.clone()) {
|
||||
let mut err = counter_dup_err;
|
||||
err.combine(other_dup_err);
|
||||
return Err(err)
|
||||
@@ -113,7 +111,7 @@ pub fn process_generics(def: &mut Def) -> syn::Result<()> {
|
||||
_ => unreachable!("Checked by def"),
|
||||
};
|
||||
|
||||
let prefix_ident = prefix_ident(&storage_def);
|
||||
let prefix_ident = prefix_ident(storage_def);
|
||||
let type_use_gen = if def.config.has_instance {
|
||||
quote::quote_spanned!(storage_def.attr_span => T, I)
|
||||
} else {
|
||||
@@ -215,7 +213,7 @@ pub fn process_generics(def: &mut Def) -> syn::Result<()> {
|
||||
/// * generate metadatas
|
||||
pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
if let Err(e) = process_generics(def) {
|
||||
return e.into_compile_error().into()
|
||||
return e.into_compile_error()
|
||||
}
|
||||
|
||||
// Check for duplicate prefixes
|
||||
@@ -393,7 +391,7 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
let prefix_structs = def.storages.iter().map(|storage_def| {
|
||||
let type_impl_gen = &def.type_impl_generics(storage_def.attr_span);
|
||||
let type_use_gen = &def.type_use_generics(storage_def.attr_span);
|
||||
let prefix_struct_ident = prefix_ident(&storage_def);
|
||||
let prefix_struct_ident = prefix_ident(storage_def);
|
||||
let prefix_struct_vis = &storage_def.vis;
|
||||
let prefix_struct_const = storage_def.prefix();
|
||||
let config_where_clause = &def.config.where_clause;
|
||||
|
||||
@@ -133,9 +133,10 @@ impl CallDef {
|
||||
return Err(syn::Error::new(item.span(), "Invalid pallet::call, expected item impl"))
|
||||
};
|
||||
|
||||
let mut instances = vec![];
|
||||
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
|
||||
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
|
||||
let instances = vec![
|
||||
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
|
||||
helper::check_pallet_struct_usage(&item.self_ty)?,
|
||||
];
|
||||
|
||||
if let Some((_, _, for_)) = item.trait_ {
|
||||
let msg = "Invalid pallet::call, expected no trait ident as in \
|
||||
|
||||
@@ -373,9 +373,10 @@ impl ConfigDef {
|
||||
let found = if item.supertraits.is_empty() {
|
||||
"none".to_string()
|
||||
} else {
|
||||
let mut found = item.supertraits.iter().fold(String::new(), |acc, s| {
|
||||
format!("{}`{}`, ", acc, quote::quote!(#s).to_string())
|
||||
});
|
||||
let mut found = item
|
||||
.supertraits
|
||||
.iter()
|
||||
.fold(String::new(), |acc, s| format!("{}`{}`, ", acc, quote::quote!(#s)));
|
||||
found.pop();
|
||||
found.pop();
|
||||
found
|
||||
|
||||
@@ -62,8 +62,8 @@ impl ErrorDef {
|
||||
return Err(syn::Error::new(item.span(), msg))
|
||||
}
|
||||
|
||||
let mut instances = vec![];
|
||||
instances.push(helper::check_type_def_gen_no_bounds(&item.generics, item.ident.span())?);
|
||||
let instances =
|
||||
vec![helper::check_type_def_gen_no_bounds(&item.generics, item.ident.span())?];
|
||||
|
||||
if item.generics.where_clause.is_some() {
|
||||
let msg = "Invalid pallet::error, where clause is not allowed on pallet error item";
|
||||
|
||||
@@ -87,9 +87,10 @@ impl ExtraConstantsDef {
|
||||
))
|
||||
};
|
||||
|
||||
let mut instances = vec![];
|
||||
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
|
||||
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
|
||||
let instances = vec![
|
||||
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
|
||||
helper::check_pallet_struct_usage(&item.self_ty)?,
|
||||
];
|
||||
|
||||
if let Some((_, _, for_)) = item.trait_ {
|
||||
let msg = "Invalid pallet::call, expected no trait ident as in \
|
||||
|
||||
@@ -53,8 +53,7 @@ impl GenesisBuildDef {
|
||||
})?
|
||||
.1;
|
||||
|
||||
let mut instances = vec![];
|
||||
instances.push(helper::check_genesis_builder_usage(&item_trait)?);
|
||||
let instances = vec![helper::check_genesis_builder_usage(item_trait)?];
|
||||
|
||||
Ok(Self { attr_span, index, instances, where_clause: item.generics.where_clause.clone() })
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ impl GenesisConfigDef {
|
||||
let mut instances = vec![];
|
||||
// NOTE: GenesisConfig is not allowed to be only generic on I because it is not supported
|
||||
// by construct_runtime.
|
||||
if let Some(u) = helper::check_type_def_optional_gen(&generics, ident.span())? {
|
||||
if let Some(u) = helper::check_type_def_optional_gen(generics, ident.span())? {
|
||||
instances.push(u);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,10 @@ impl HooksDef {
|
||||
return Err(syn::Error::new(item.span(), msg))
|
||||
};
|
||||
|
||||
let mut instances = vec![];
|
||||
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
|
||||
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
|
||||
let instances = vec![
|
||||
helper::check_pallet_struct_usage(&item.self_ty)?,
|
||||
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
|
||||
];
|
||||
|
||||
let item_trait = &item
|
||||
.trait_
|
||||
|
||||
@@ -50,9 +50,10 @@ impl InherentDef {
|
||||
return Err(syn::Error::new(item.span(), msg))
|
||||
}
|
||||
|
||||
let mut instances = vec![];
|
||||
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
|
||||
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
|
||||
let instances = vec![
|
||||
helper::check_pallet_struct_usage(&item.self_ty)?,
|
||||
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
|
||||
];
|
||||
|
||||
Ok(InherentDef { index, instances })
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ impl OriginDef {
|
||||
let is_generic = !generics.params.is_empty();
|
||||
|
||||
let mut instances = vec![];
|
||||
if let Some(u) = helper::check_type_def_optional_gen(&generics, item.span())? {
|
||||
if let Some(u) = helper::check_type_def_optional_gen(generics, item.span())? {
|
||||
instances.push(u);
|
||||
} else {
|
||||
// construct_runtime only allow generic event for instantiable pallet.
|
||||
|
||||
@@ -155,8 +155,8 @@ impl PalletStructDef {
|
||||
return Err(syn::Error::new(item.generics.where_clause.span(), msg))
|
||||
}
|
||||
|
||||
let mut instances = vec![];
|
||||
instances.push(helper::check_type_def_gen_no_bounds(&item.generics, item.ident.span())?);
|
||||
let instances =
|
||||
vec![helper::check_type_def_gen_no_bounds(&item.generics, item.ident.span())?];
|
||||
|
||||
Ok(Self {
|
||||
index,
|
||||
|
||||
@@ -272,7 +272,7 @@ fn check_generics(
|
||||
);
|
||||
e.pop();
|
||||
e.pop();
|
||||
e.push_str(".");
|
||||
e.push('.');
|
||||
e
|
||||
};
|
||||
|
||||
@@ -550,7 +550,7 @@ fn process_generics(
|
||||
let args_span = segment.arguments.span();
|
||||
|
||||
let args = match &segment.arguments {
|
||||
syn::PathArguments::AngleBracketed(args) if args.args.len() != 0 => args,
|
||||
syn::PathArguments::AngleBracketed(args) if !args.args.is_empty() => args,
|
||||
_ => {
|
||||
let msg = "Invalid pallet::storage, invalid number of generic generic arguments, \
|
||||
expect more that 0 generic arguments.";
|
||||
@@ -646,13 +646,16 @@ impl StorageDef {
|
||||
self.rename_as
|
||||
.as_ref()
|
||||
.map(syn::LitStr::value)
|
||||
.unwrap_or(self.ident.to_string())
|
||||
.unwrap_or_else(|| self.ident.to_string())
|
||||
}
|
||||
|
||||
/// Return either the span of the ident or the span of the literal in the
|
||||
/// #[storage_prefix] attribute
|
||||
pub fn prefix_span(&self) -> proc_macro2::Span {
|
||||
self.rename_as.as_ref().map(syn::LitStr::span).unwrap_or(self.ident.span())
|
||||
self.rename_as
|
||||
.as_ref()
|
||||
.map(syn::LitStr::span)
|
||||
.unwrap_or_else(|| self.ident.span())
|
||||
}
|
||||
|
||||
pub fn try_from(
|
||||
@@ -672,8 +675,7 @@ impl StorageDef {
|
||||
|
||||
let cfg_attrs = helper::get_item_cfg_attrs(&item.attrs);
|
||||
|
||||
let mut instances = vec![];
|
||||
instances.push(helper::check_type_def_gen(&item.generics, item.ident.span())?);
|
||||
let instances = vec![helper::check_type_def_gen(&item.generics, item.ident.span())?];
|
||||
|
||||
let where_clause = item.generics.where_clause.clone();
|
||||
let docs = get_doc_literals(&item.attrs);
|
||||
|
||||
@@ -52,9 +52,10 @@ impl ValidateUnsignedDef {
|
||||
return Err(syn::Error::new(item.span(), msg))
|
||||
}
|
||||
|
||||
let mut instances = vec![];
|
||||
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
|
||||
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
|
||||
let instances = vec![
|
||||
helper::check_pallet_struct_usage(&item.self_ty)?,
|
||||
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
|
||||
];
|
||||
|
||||
Ok(ValidateUnsignedDef { index, instances })
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ impl BuilderDef {
|
||||
let mut data = None;
|
||||
|
||||
if let Some(builder) = &line.build {
|
||||
is_generic |= ext::expr_contains_ident(&builder, &def.module_runtime_generic);
|
||||
is_generic |= ext::expr_contains_ident(builder, &def.module_runtime_generic);
|
||||
is_generic |= line.is_generic;
|
||||
|
||||
data = Some(match &line.storage_type {
|
||||
@@ -138,7 +138,7 @@ impl BuilderDef {
|
||||
}
|
||||
|
||||
if let Some(builder) = def.extra_genesis_build.as_ref() {
|
||||
is_generic |= ext::expr_contains_ident(&builder, &def.module_runtime_generic);
|
||||
is_generic |= ext::expr_contains_ident(builder, &def.module_runtime_generic);
|
||||
|
||||
blocks.push(quote_spanned! { builder.span() =>
|
||||
let extra_genesis_builder: fn(&Self) = #builder;
|
||||
|
||||
@@ -116,7 +116,7 @@ fn create_and_impl_instance_struct(
|
||||
let instance_trait = quote!( #scrate::traits::Instance );
|
||||
|
||||
let instance_struct = &instance_def.instance_struct;
|
||||
let prefix = format!("{}{}", instance_def.prefix, def.crate_name.to_string());
|
||||
let prefix = format!("{}{}", instance_def.prefix, def.crate_name);
|
||||
let doc = &instance_def.doc;
|
||||
let index = instance_def.index;
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ impl StorageLineDefExt {
|
||||
) -> Self {
|
||||
let is_generic = match &storage_def.storage_type {
|
||||
StorageLineTypeDef::Simple(value) =>
|
||||
ext::type_contains_ident(&value, &def.module_runtime_generic),
|
||||
ext::type_contains_ident(value, &def.module_runtime_generic),
|
||||
StorageLineTypeDef::Map(map) =>
|
||||
ext::type_contains_ident(&map.key, &def.module_runtime_generic) ||
|
||||
ext::type_contains_ident(&map.value, &def.module_runtime_generic),
|
||||
|
||||
@@ -101,7 +101,7 @@ impl StorageHasher for 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<_>>()
|
||||
twox_64(x).iter().chain(x.iter()).cloned().collect::<Vec<_>>()
|
||||
}
|
||||
fn max_len<K: MaxEncodedLen>() -> usize {
|
||||
K::max_encoded_len().saturating_add(8)
|
||||
@@ -123,7 +123,7 @@ impl StorageHasher for 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<_>>()
|
||||
blake2_128(x).iter().chain(x.iter()).cloned().collect::<Vec<_>>()
|
||||
}
|
||||
fn max_len<K: MaxEncodedLen>() -> usize {
|
||||
K::max_encoded_len().saturating_add(16)
|
||||
|
||||
@@ -105,7 +105,7 @@ use scale_info::TypeInfo;
|
||||
use sp_runtime::TypeId;
|
||||
|
||||
/// A unified log target for support operations.
|
||||
pub const LOG_TARGET: &'static str = "runtime::frame-support";
|
||||
pub const LOG_TARGET: &str = "runtime::frame-support";
|
||||
|
||||
/// A type that cannot be instantiated.
|
||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
|
||||
|
||||
@@ -50,7 +50,7 @@ pub fn get<T: Decode + Sized>(child_info: &ChildInfo, key: &[u8]) -> Option<T> {
|
||||
/// Return the value of the item in storage under `key`, or the type's default if there is no
|
||||
/// explicit entry.
|
||||
pub fn get_or_default<T: Decode + Sized + Default>(child_info: &ChildInfo, key: &[u8]) -> T {
|
||||
get(child_info, key).unwrap_or_else(Default::default)
|
||||
get(child_info, key).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `default_value` if there is no
|
||||
@@ -90,7 +90,7 @@ pub fn take<T: Decode + Sized>(child_info: &ChildInfo, key: &[u8]) -> Option<T>
|
||||
/// Remove `key` from storage, returning its value, or, if there was no explicit entry in storage,
|
||||
/// the default for its type.
|
||||
pub fn take_or_default<T: Codec + Sized + Default>(child_info: &ChildInfo, key: &[u8]) -> T {
|
||||
take(child_info, key).unwrap_or_else(Default::default)
|
||||
take(child_info, key).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `default_value` if there is no
|
||||
|
||||
@@ -461,7 +461,7 @@ where
|
||||
},
|
||||
};
|
||||
|
||||
let mut key2_material = G::Hasher2::reverse(&key_material);
|
||||
let mut key2_material = G::Hasher2::reverse(key_material);
|
||||
let key2 = match K2::decode(&mut key2_material) {
|
||||
Ok(key2) => key2,
|
||||
Err(_) => {
|
||||
|
||||
@@ -28,7 +28,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::get(&hash(key).as_ref())
|
||||
unhashed::get(hash(key).as_ref())
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or the type's default if there is no
|
||||
@@ -39,7 +39,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::get_or_default(&hash(key).as_ref())
|
||||
unhashed::get_or_default(hash(key).as_ref())
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `default_value` if there is no
|
||||
@@ -50,7 +50,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::get_or(&hash(key).as_ref(), default_value)
|
||||
unhashed::get_or(hash(key).as_ref(), default_value)
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `default_value()` if there is no
|
||||
@@ -62,7 +62,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::get_or_else(&hash(key).as_ref(), default_value)
|
||||
unhashed::get_or_else(hash(key).as_ref(), default_value)
|
||||
}
|
||||
|
||||
/// Put `value` in storage under `key`.
|
||||
@@ -72,7 +72,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::put(&hash(key).as_ref(), value)
|
||||
unhashed::put(hash(key).as_ref(), value)
|
||||
}
|
||||
|
||||
/// Remove `key` from storage, returning its value if it had an explicit entry or `None` otherwise.
|
||||
@@ -82,7 +82,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::take(&hash(key).as_ref())
|
||||
unhashed::take(hash(key).as_ref())
|
||||
}
|
||||
|
||||
/// Remove `key` from storage, returning its value, or, if there was no explicit entry in storage,
|
||||
@@ -93,7 +93,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::take_or_default(&hash(key).as_ref())
|
||||
unhashed::take_or_default(hash(key).as_ref())
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `default_value` if there is no
|
||||
@@ -104,7 +104,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::take_or(&hash(key).as_ref(), default_value)
|
||||
unhashed::take_or(hash(key).as_ref(), default_value)
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `default_value()` if there is no
|
||||
@@ -116,7 +116,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::take_or_else(&hash(key).as_ref(), default_value)
|
||||
unhashed::take_or_else(hash(key).as_ref(), default_value)
|
||||
}
|
||||
|
||||
/// Check to see if `key` has an explicit entry in storage.
|
||||
@@ -125,7 +125,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::exists(&hash(key).as_ref())
|
||||
unhashed::exists(hash(key).as_ref())
|
||||
}
|
||||
|
||||
/// Ensure `key` has no explicit entry in storage.
|
||||
@@ -134,7 +134,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::kill(&hash(key).as_ref())
|
||||
unhashed::kill(hash(key).as_ref())
|
||||
}
|
||||
|
||||
/// Get a Vec of bytes from storage.
|
||||
@@ -143,7 +143,7 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::get_raw(&hash(key).as_ref())
|
||||
unhashed::get_raw(hash(key).as_ref())
|
||||
}
|
||||
|
||||
/// Put a raw byte slice into storage.
|
||||
@@ -152,5 +152,5 @@ where
|
||||
HashFn: Fn(&[u8]) -> R,
|
||||
R: AsRef<[u8]>,
|
||||
{
|
||||
unhashed::put_raw(&hash(key).as_ref(), value)
|
||||
unhashed::put_raw(hash(key).as_ref(), value)
|
||||
}
|
||||
|
||||
@@ -1038,7 +1038,7 @@ impl<T> Iterator for ChildTriePrefixIterator<T> {
|
||||
Some(self.previous_key.clone())
|
||||
} else {
|
||||
sp_io::default_child_storage::next_key(
|
||||
&self.child_info.storage_key(),
|
||||
self.child_info.storage_key(),
|
||||
&self.previous_key,
|
||||
)
|
||||
.filter(|n| n.starts_with(&self.prefix))
|
||||
|
||||
@@ -217,8 +217,7 @@ where
|
||||
|
||||
/// Take the value under a key.
|
||||
pub fn take<KeyArg: EncodeLike<Key> + Clone>(key: KeyArg) -> QueryKind::Query {
|
||||
let removed_value =
|
||||
<Self as MapWrapper>::Map::mutate_exists(key, |value| core::mem::replace(value, None));
|
||||
let removed_value = <Self as MapWrapper>::Map::mutate_exists(key, |value| value.take());
|
||||
if removed_value.is_some() {
|
||||
CounterFor::<Prefix>::mutate(|value| value.saturating_dec());
|
||||
}
|
||||
@@ -429,7 +428,7 @@ where
|
||||
if cfg!(feature = "no-metadata-docs") {
|
||||
vec![]
|
||||
} else {
|
||||
vec![&"Counter for the related counted storage map"]
|
||||
vec!["Counter for the related counted storage map"]
|
||||
},
|
||||
entries,
|
||||
);
|
||||
|
||||
@@ -481,7 +481,7 @@ where
|
||||
modifier: QueryKind::METADATA,
|
||||
ty: StorageEntryType::Map {
|
||||
key: scale_info::meta_type::<Key::Key>(),
|
||||
hashers: Key::HASHER_METADATA.iter().cloned().collect(),
|
||||
hashers: Key::HASHER_METADATA.to_vec(),
|
||||
value: scale_info::meta_type::<Value>(),
|
||||
},
|
||||
default: OnEmpty::get().encode(),
|
||||
|
||||
@@ -38,7 +38,7 @@ pub fn get<T: Decode + Sized>(key: &[u8]) -> Option<T> {
|
||||
/// Return the value of the item in storage under `key`, or the type's default if there is no
|
||||
/// explicit entry.
|
||||
pub fn get_or_default<T: Decode + Sized + Default>(key: &[u8]) -> T {
|
||||
get(key).unwrap_or_else(Default::default)
|
||||
get(key).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `default_value` if there is no
|
||||
@@ -70,7 +70,7 @@ pub fn take<T: Decode + Sized>(key: &[u8]) -> Option<T> {
|
||||
/// Remove `key` from storage, returning its value, or, if there was no explicit entry in storage,
|
||||
/// the default for its type.
|
||||
pub fn take_or_default<T: Decode + Sized + Default>(key: &[u8]) -> T {
|
||||
take(key).unwrap_or_else(Default::default)
|
||||
take(key).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `default_value` if there is no
|
||||
|
||||
@@ -157,7 +157,7 @@ impl<OuterOrigin, L: EnsureOrigin<OuterOrigin>, R: EnsureOrigin<OuterOrigin>>
|
||||
type Success = Either<L::Success, R::Success>;
|
||||
fn try_origin(o: OuterOrigin) -> Result<Self::Success, OuterOrigin> {
|
||||
L::try_origin(o)
|
||||
.map_or_else(|o| R::try_origin(o).map(|o| Either::Right(o)), |o| Ok(Either::Left(o)))
|
||||
.map_or_else(|o| R::try_origin(o).map(Either::Right), |o| Ok(Either::Left(o)))
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
@@ -299,7 +299,7 @@ pub trait ChangeMembers<AccountId: Clone + Ord> {
|
||||
/// This resets any previous value of prime.
|
||||
fn set_members_sorted(new_members: &[AccountId], old_members: &[AccountId]) {
|
||||
let (incoming, outgoing) = Self::compute_members_diff_sorted(new_members, old_members);
|
||||
Self::change_members_sorted(&incoming[..], &outgoing[..], &new_members);
|
||||
Self::change_members_sorted(&incoming[..], &outgoing[..], new_members);
|
||||
}
|
||||
|
||||
/// Compute diff between new and old members; they **must already be sorted**.
|
||||
|
||||
@@ -161,7 +161,7 @@ impl sp_std::cmp::Ord for CrateVersion {
|
||||
|
||||
impl sp_std::cmp::PartialOrd for CrateVersion {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<sp_std::cmp::Ordering> {
|
||||
Some(<Self as Ord>::cmp(&self, other))
|
||||
Some(<Self as Ord>::cmp(self, other))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ use sp_runtime::{traits::Block as BlockT, DispatchError};
|
||||
use sp_std::{cmp::Ordering, prelude::*};
|
||||
|
||||
#[doc(hidden)]
|
||||
pub const DEFENSIVE_OP_PUBLIC_ERROR: &'static str = "a defensive failure has been triggered; please report the block number at https://github.com/paritytech/substrate/issues";
|
||||
pub const DEFENSIVE_OP_PUBLIC_ERROR: &str = "a defensive failure has been triggered; please report the block number at https://github.com/paritytech/substrate/issues";
|
||||
#[doc(hidden)]
|
||||
pub const DEFENSIVE_OP_INTERNAL_ERROR: &'static str = "Defensive failure has been triggered!";
|
||||
pub const DEFENSIVE_OP_INTERNAL_ERROR: &str = "Defensive failure has been triggered!";
|
||||
|
||||
/// Generic function to mark an execution path as ONLY defensive.
|
||||
///
|
||||
|
||||
@@ -101,7 +101,7 @@ impl<
|
||||
}
|
||||
fn remove(k: &K) -> Result<(), DispatchError> {
|
||||
if S::contains_key(&k) {
|
||||
L::killed(&k)?;
|
||||
L::killed(k)?;
|
||||
S::remove(k);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -83,7 +83,7 @@ pub trait Currency<AccountId> {
|
||||
/// This is just the same as burning and issuing the same amount and has no effect on the
|
||||
/// total issuance.
|
||||
fn pair(amount: Self::Balance) -> (Self::PositiveImbalance, Self::NegativeImbalance) {
|
||||
(Self::burn(amount.clone()), Self::issue(amount))
|
||||
(Self::burn(amount), Self::issue(amount))
|
||||
}
|
||||
|
||||
/// The 'free' balance of a given account.
|
||||
|
||||
@@ -92,7 +92,7 @@ pub trait Mutate<AccountId>: Inspect<AccountId> {
|
||||
let extra = Self::can_withdraw(&source, amount).into_result()?;
|
||||
// As we first burn and then mint, we don't need to check if `mint` fits into the supply.
|
||||
// If we can withdraw/burn it, we can also mint it again.
|
||||
Self::can_deposit(&dest, amount.saturating_add(extra), false).into_result()?;
|
||||
Self::can_deposit(dest, amount.saturating_add(extra), false).into_result()?;
|
||||
let actual = Self::burn_from(source, amount)?;
|
||||
debug_assert!(
|
||||
actual == amount.saturating_add(extra),
|
||||
|
||||
@@ -165,7 +165,7 @@ pub trait Unbalanced<AccountId>: Inspect<AccountId> {
|
||||
) -> Result<Self::Balance, DispatchError> {
|
||||
let old_balance = Self::balance(who);
|
||||
let (mut new_balance, mut amount) = if old_balance < amount {
|
||||
Err(TokenError::NoFunds)?
|
||||
return Err(TokenError::NoFunds.into())
|
||||
} else {
|
||||
(old_balance - amount, amount)
|
||||
};
|
||||
@@ -225,7 +225,7 @@ pub trait Unbalanced<AccountId>: Inspect<AccountId> {
|
||||
let old_balance = Self::balance(who);
|
||||
let new_balance = old_balance.checked_add(&amount).ok_or(ArithmeticError::Overflow)?;
|
||||
if new_balance < Self::minimum_balance() {
|
||||
Err(TokenError::BelowMinimum)?
|
||||
return Err(TokenError::BelowMinimum.into())
|
||||
}
|
||||
if old_balance != new_balance {
|
||||
Self::set_balance(who, new_balance)?;
|
||||
|
||||
@@ -145,7 +145,7 @@ pub trait Mutate<AccountId>: Inspect<AccountId> {
|
||||
let extra = Self::can_withdraw(asset, &source, amount).into_result()?;
|
||||
// As we first burn and then mint, we don't need to check if `mint` fits into the supply.
|
||||
// If we can withdraw/burn it, we can also mint it again.
|
||||
Self::can_deposit(asset, &dest, amount.saturating_add(extra), false).into_result()?;
|
||||
Self::can_deposit(asset, dest, amount.saturating_add(extra), false).into_result()?;
|
||||
let actual = Self::burn_from(asset, source, amount)?;
|
||||
debug_assert!(
|
||||
actual == amount.saturating_add(extra),
|
||||
|
||||
@@ -186,7 +186,7 @@ pub trait Unbalanced<AccountId>: Inspect<AccountId> {
|
||||
) -> Result<Self::Balance, DispatchError> {
|
||||
let old_balance = Self::balance(asset, who);
|
||||
let (mut new_balance, mut amount) = if old_balance < amount {
|
||||
Err(TokenError::NoFunds)?
|
||||
return Err(TokenError::NoFunds.into())
|
||||
} else {
|
||||
(old_balance - amount, amount)
|
||||
};
|
||||
@@ -251,7 +251,7 @@ pub trait Unbalanced<AccountId>: Inspect<AccountId> {
|
||||
let old_balance = Self::balance(asset, who);
|
||||
let new_balance = old_balance.checked_add(&amount).ok_or(ArithmeticError::Overflow)?;
|
||||
if new_balance < Self::minimum_balance(asset) {
|
||||
Err(TokenError::BelowMinimum)?
|
||||
return Err(TokenError::BelowMinimum.into())
|
||||
}
|
||||
if old_balance != new_balance {
|
||||
Self::set_balance(asset, who, new_balance)?;
|
||||
|
||||
@@ -355,7 +355,7 @@ impl PostDispatchInfo {
|
||||
/// Extract the actual weight from a dispatch result if any or fall back to the default weight.
|
||||
pub fn extract_actual_weight(result: &DispatchResultWithPostInfo, info: &DispatchInfo) -> Weight {
|
||||
match result {
|
||||
Ok(post_info) => &post_info,
|
||||
Ok(post_info) => post_info,
|
||||
Err(err) => &err.post_info,
|
||||
}
|
||||
.calc_actual_weight(info)
|
||||
@@ -432,7 +432,7 @@ where
|
||||
|
||||
impl<T> WeighData<T> for Weight {
|
||||
fn weigh_data(&self, _: T) -> Weight {
|
||||
return *self
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,7 +450,7 @@ impl<T> PaysFee<T> for Weight {
|
||||
|
||||
impl<T> WeighData<T> for (Weight, DispatchClass, Pays) {
|
||||
fn weigh_data(&self, _: T) -> Weight {
|
||||
return self.0
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ impl<T> PaysFee<T> for (Weight, DispatchClass, Pays) {
|
||||
|
||||
impl<T> WeighData<T> for (Weight, DispatchClass) {
|
||||
fn weigh_data(&self, _: T) -> Weight {
|
||||
return self.0
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ impl<T> PaysFee<T> for (Weight, DispatchClass) {
|
||||
|
||||
impl<T> WeighData<T> for (Weight, Pays) {
|
||||
fn weigh_data(&self, _: T) -> Weight {
|
||||
return self.0
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user