mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 14:41:02 +00:00
Reformat types string for decl_storage (#1298)
* Clean space from types when converting to string * Missing cases. * Add unit test for complex type, complete clean fn.
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
// end::description[]
|
// end::description[]
|
||||||
|
|
||||||
use srml_support_procedural_tools::syn_ext as ext;
|
use srml_support_procedural_tools::syn_ext as ext;
|
||||||
use srml_support_procedural_tools::{generate_crate_access, generate_hidden_includes};
|
use srml_support_procedural_tools::{generate_crate_access, generate_hidden_includes, clean_type_string};
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
@@ -577,7 +577,7 @@ fn store_functions_to_metadata (
|
|||||||
let is_option = extracted_opt.is_some();
|
let is_option = extracted_opt.is_some();
|
||||||
let typ = extracted_opt.unwrap_or(quote!( #gettype ));
|
let typ = extracted_opt.unwrap_or(quote!( #gettype ));
|
||||||
let stype = if is_simple {
|
let stype = if is_simple {
|
||||||
let styp = typ.to_string();
|
let styp = clean_type_string(&typ.to_string());
|
||||||
quote!{
|
quote!{
|
||||||
#scrate::storage::generator::StorageFunctionType::Plain(
|
#scrate::storage::generator::StorageFunctionType::Plain(
|
||||||
#scrate::storage::generator::DecodeDifferent::Encode(#styp),
|
#scrate::storage::generator::DecodeDifferent::Encode(#styp),
|
||||||
@@ -585,8 +585,8 @@ fn store_functions_to_metadata (
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let kty = stk.expect("is not simple; qed");
|
let kty = stk.expect("is not simple; qed");
|
||||||
let kty = quote!(#kty).to_string();
|
let kty = clean_type_string("e!(#kty).to_string());
|
||||||
let styp = typ.to_string();
|
let styp = clean_type_string(&typ.to_string());
|
||||||
quote!{
|
quote!{
|
||||||
#scrate::storage::generator::StorageFunctionType::Map {
|
#scrate::storage::generator::StorageFunctionType::Map {
|
||||||
key: #scrate::storage::generator::DecodeDifferent::Encode(#kty),
|
key: #scrate::storage::generator::DecodeDifferent::Encode(#kty),
|
||||||
|
|||||||
@@ -92,3 +92,22 @@ pub fn generate_hidden_includes(unique_id: &str, def_crate: &str, crate_id: &str
|
|||||||
)
|
)
|
||||||
}.into()
|
}.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fn to remove white spaces arount string types
|
||||||
|
// (basically whitespaces arount tokens)
|
||||||
|
pub fn clean_type_string(input: &str) -> String {
|
||||||
|
input
|
||||||
|
.replace(" ::", "::")
|
||||||
|
.replace(":: ", "::")
|
||||||
|
.replace(" ,", ",")
|
||||||
|
.replace(" ;", ";")
|
||||||
|
.replace(" [", "[")
|
||||||
|
.replace("[ ", "[")
|
||||||
|
.replace(" ]", "]")
|
||||||
|
.replace(" (", "(")
|
||||||
|
.replace("( ", "(")
|
||||||
|
.replace(" )", ")")
|
||||||
|
.replace(" <", "<")
|
||||||
|
.replace("< ", "<")
|
||||||
|
.replace(" >", ">")
|
||||||
|
}
|
||||||
|
|||||||
@@ -633,6 +633,10 @@ mod tests {
|
|||||||
|
|
||||||
GETMAPU32MYDEF get(map_u32_getter_mydef): map u32 => String = "map".into();
|
GETMAPU32MYDEF get(map_u32_getter_mydef): map u32 => String = "map".into();
|
||||||
pub PUBGETMAPU32MYDEF get(pub_map_u32_getter_mydef): map u32 => String = "pubmap".into();
|
pub PUBGETMAPU32MYDEF get(pub_map_u32_getter_mydef): map u32 => String = "pubmap".into();
|
||||||
|
|
||||||
|
COMPLEX_TYPE1: ::std::vec::Vec<<T as Trait>::Origin>;
|
||||||
|
COMPLEX_TYPE2: (Vec<Vec<(u16,Box<( )>)>>, u32);
|
||||||
|
COMPLEX_TYPE3: ([u32;25]);
|
||||||
}
|
}
|
||||||
add_extra_genesis {
|
add_extra_genesis {
|
||||||
build(|_, _, _| {});
|
build(|_, _, _| {});
|
||||||
@@ -677,7 +681,7 @@ mod tests {
|
|||||||
StorageFunctionMetadata {
|
StorageFunctionMetadata {
|
||||||
name: DecodeDifferent::Encode("GETU32"),
|
name: DecodeDifferent::Encode("GETU32"),
|
||||||
modifier: StorageFunctionModifier::Default,
|
modifier: StorageFunctionModifier::Default,
|
||||||
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("T :: Origin")),
|
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("T::Origin")),
|
||||||
documentation: DecodeDifferent::Encode(&[]),
|
documentation: DecodeDifferent::Encode(&[]),
|
||||||
},
|
},
|
||||||
StorageFunctionMetadata {
|
StorageFunctionMetadata {
|
||||||
@@ -796,6 +800,24 @@ mod tests {
|
|||||||
},
|
},
|
||||||
documentation: DecodeDifferent::Encode(&[]),
|
documentation: DecodeDifferent::Encode(&[]),
|
||||||
},
|
},
|
||||||
|
StorageFunctionMetadata {
|
||||||
|
name: DecodeDifferent::Encode("COMPLEX_TYPE1"),
|
||||||
|
modifier: StorageFunctionModifier::Default,
|
||||||
|
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("::std::vec::Vec<<T as Trait>::Origin>")),
|
||||||
|
documentation: DecodeDifferent::Encode(&[]),
|
||||||
|
},
|
||||||
|
StorageFunctionMetadata {
|
||||||
|
name: DecodeDifferent::Encode("COMPLEX_TYPE2"),
|
||||||
|
modifier: StorageFunctionModifier::Default,
|
||||||
|
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("(Vec<Vec<(u16, Box<()>)>>, u32)")),
|
||||||
|
documentation: DecodeDifferent::Encode(&[]),
|
||||||
|
},
|
||||||
|
StorageFunctionMetadata {
|
||||||
|
name: DecodeDifferent::Encode("COMPLEX_TYPE3"),
|
||||||
|
modifier: StorageFunctionModifier::Default,
|
||||||
|
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("([u32; 25])")),
|
||||||
|
documentation: DecodeDifferent::Encode(&[]),
|
||||||
|
},
|
||||||
])
|
])
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -816,6 +838,7 @@ mod tests {
|
|||||||
assert_eq!(config.pub_u32_getter_with_config_mydef, 1u32);
|
assert_eq!(config.pub_u32_getter_with_config_mydef, 1u32);
|
||||||
assert_eq!(config.pub_u32_getter_with_config_mydef_opt, 100u32);
|
assert_eq!(config.pub_u32_getter_with_config_mydef_opt, 100u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user