mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 02:21:03 +00:00
Improve fees module (#1821)
* remove amount associated * make a new trait to bound some arithmetics to balances or assets: It also remove arithmetic bounds of srml-support::traits::Currency. To update your code then use srml_support::traits::ArithmeticType like: `type Currency: ArithmeticType + Currency<Self::AccountId, Balance=BalanceOf<Self>>; ` with `type BalanceOf<T> = <<T as Trait>::Currency as ArithmeticType>::Type; ` * improve decl_storage when it explicit serde bound: basically don't try to be smarter than rust and just use where clause.
This commit is contained in:
@@ -192,13 +192,10 @@ fn decl_store_extra_genesis(
|
||||
is_trait_needed = true;
|
||||
has_trait_field = true;
|
||||
}
|
||||
for t in ext::get_non_bound_serde_derive_types(type_infos.value_type, &traitinstance) {
|
||||
serde_complete_bound.insert(t);
|
||||
}
|
||||
|
||||
serde_complete_bound.insert(type_infos.value_type);
|
||||
if let DeclStorageTypeInfosKind::Map { key_type, .. } = type_infos.kind {
|
||||
for t in ext::get_non_bound_serde_derive_types(key_type, &traitinstance) {
|
||||
serde_complete_bound.insert(t);
|
||||
}
|
||||
serde_complete_bound.insert(key_type);
|
||||
}
|
||||
let storage_type = type_infos.typ.clone();
|
||||
config_field.extend(match type_infos.kind {
|
||||
@@ -285,9 +282,7 @@ fn decl_store_extra_genesis(
|
||||
has_trait_field = true;
|
||||
}
|
||||
|
||||
for t in ext::get_non_bound_serde_derive_types(extra_type, &traitinstance).into_iter() {
|
||||
serde_complete_bound.insert(t);
|
||||
}
|
||||
serde_complete_bound.insert(extra_type);
|
||||
|
||||
let extrafield = &extra_field.content;
|
||||
genesis_extrafields.extend(quote!{
|
||||
@@ -315,6 +310,7 @@ fn decl_store_extra_genesis(
|
||||
let serde_bug_bound = if !serde_complete_bound.is_empty() {
|
||||
let mut b_ser = String::new();
|
||||
let mut b_dser = String::new();
|
||||
// panic!("{:#?}", serde_complete_bound);
|
||||
serde_complete_bound.into_iter().for_each(|bound| {
|
||||
let stype = quote!(#bound);
|
||||
b_ser.push_str(&format!("{} : {}::serde::Serialize, ", stype, scrate));
|
||||
|
||||
@@ -327,57 +327,3 @@ pub fn has_parametric_type_def(typ: &syn::Type, ident: &Ident, default: bool) ->
|
||||
pub fn has_parametric_type(typ: &syn::Type, ident: &Ident) -> bool {
|
||||
has_parametric_type_def(typ, ident, true)
|
||||
}
|
||||
|
||||
/// Get case where serde does not include bound with serde_derive macros:
|
||||
/// see https://github.com/serde-rs/serde/issues/1454
|
||||
pub fn get_non_bound_serde_derive_types(typ: &syn::Type, t: &syn::Ident) -> Vec<syn::Type> {
|
||||
let mut result = Vec::new();
|
||||
get_non_bound_serde_derive_types_inner(typ, t, &mut result);
|
||||
result
|
||||
}
|
||||
|
||||
fn get_non_bound_serde_derive_types_inner(typ: &syn::Type, t: &syn::Ident, result: &mut Vec<syn::Type>) {
|
||||
match *typ {
|
||||
syn::Type::Path(ref path) => {
|
||||
if heuristic_is_associated_path(&path.path,t) {
|
||||
result.push(typ.clone());
|
||||
}
|
||||
for p in path.path.segments.iter() {
|
||||
if let syn::PathArguments::AngleBracketed(ref args) = p.arguments {
|
||||
for a in args.args.iter() {
|
||||
if let syn::GenericArgument::Type(ref ty) = a {
|
||||
get_non_bound_serde_derive_types_inner(ty, t, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
syn::Type::Slice(ref inner) => get_non_bound_serde_derive_types_inner(&inner.elem, t, result),
|
||||
syn::Type::Array(ref inner) => get_non_bound_serde_derive_types_inner(&inner.elem, t, result),
|
||||
syn::Type::Ptr(ref inner) => get_non_bound_serde_derive_types_inner(&inner.elem, t, result),
|
||||
syn::Type::Reference(ref inner) => get_non_bound_serde_derive_types_inner(&inner.elem, t, result),
|
||||
syn::Type::BareFn(..) => (),
|
||||
syn::Type::Never(..) => (),
|
||||
syn::Type::Tuple(ref inner) => for e in inner.elems.iter() {
|
||||
get_non_bound_serde_derive_types_inner(e, t, result)
|
||||
},
|
||||
syn::Type::TraitObject(..) => (),
|
||||
syn::Type::ImplTrait(..) => (),
|
||||
syn::Type::Paren(ref inner) => get_non_bound_serde_derive_types_inner(&inner.elem, t, result),
|
||||
syn::Type::Group(ref inner) => get_non_bound_serde_derive_types_inner(&inner.elem, t, result),
|
||||
syn::Type::Infer(..) => (),
|
||||
syn::Type::Macro(..) => (),
|
||||
syn::Type::Verbatim(..) => (),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn heuristic_is_associated_path(path: &syn::Path,t: &syn::Ident) -> bool {
|
||||
|
||||
if let Some(syn::punctuated::Pair::Punctuated(s,_)) = path.segments.first() {
|
||||
&s.ident == t
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,10 +79,14 @@ pub enum UpdateBalanceOutcome {
|
||||
AccountKilled,
|
||||
}
|
||||
|
||||
pub trait ArithmeticType {
|
||||
type Type: SimpleArithmetic + As<usize> + As<u64> + Codec + Copy + MaybeSerializeDebug + Default;
|
||||
}
|
||||
|
||||
/// Abstraction over a fungible assets system.
|
||||
pub trait Currency<AccountId> {
|
||||
/// The balance of an account.
|
||||
type Balance: SimpleArithmetic + As<usize> + As<u64> + Codec + Copy + MaybeSerializeDebug + Default;
|
||||
type Balance;
|
||||
|
||||
// PUBLIC IMMUTABLES
|
||||
|
||||
|
||||
Reference in New Issue
Block a user