mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 13:25:44 +00:00
Update scale-info to 2.5.0 (#896)
* Upodate scale-info to 2.5.0 * A couple more clippy fixes * more deprecation things that appeared
This commit is contained in:
Generated
+4
-4
@@ -2623,9 +2623,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scale-info"
|
name = "scale-info"
|
||||||
version = "2.4.0"
|
version = "2.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61471dff9096de1d8b2319efed7162081e96793f5ebb147e50db10d50d648a4d"
|
checksum = "0cfdffd972d76b22f3d7f81c8be34b2296afd3a25e0a547bd9abe340a4dbbe97"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
@@ -2637,9 +2637,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scale-info-derive"
|
name = "scale-info-derive"
|
||||||
version = "2.4.0"
|
version = "2.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "219580e803a66b3f05761fd06f1f879a872444e49ce23f73694d26e5a954c7e6"
|
checksum = "61fa974aea2d63dd18a4ec3a49d59af9f34178c73a4f56d2f18205628d00681e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-crate",
|
"proc-macro-crate",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
|
|||||||
+2
-2
@@ -20,7 +20,7 @@ heck = "0.4.1"
|
|||||||
proc-macro2 = "1.0.55"
|
proc-macro2 = "1.0.55"
|
||||||
quote = "1.0.8"
|
quote = "1.0.8"
|
||||||
syn = "1.0.109"
|
syn = "1.0.109"
|
||||||
scale-info = "2.4.0"
|
scale-info = "2.5.0"
|
||||||
subxt-metadata = { version = "0.27.1", path = "../metadata" }
|
subxt-metadata = { version = "0.27.1", path = "../metadata" }
|
||||||
jsonrpsee = { version = "0.16.0", features = ["async-client", "client-ws-transport", "http-client"] }
|
jsonrpsee = { version = "0.16.0", features = ["async-client", "client-ws-transport", "http-client"] }
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
@@ -29,5 +29,5 @@ thiserror = "1.0.40"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
|
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
|
||||||
scale-info = { version = "2.4.0", features = ["bit-vec"] }
|
scale-info = { version = "2.5.0", features = ["bit-vec"] }
|
||||||
pretty_assertions = "1.0.0"
|
pretty_assertions = "1.0.0"
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ pub fn generate_calls(
|
|||||||
|
|
||||||
let mut struct_defs = super::generate_structs_from_variants(
|
let mut struct_defs = super::generate_structs_from_variants(
|
||||||
type_gen,
|
type_gen,
|
||||||
call.ty.id(),
|
call.ty.id,
|
||||||
|name| name.to_upper_camel_case().into(),
|
|name| name.to_upper_camel_case().into(),
|
||||||
"Call",
|
"Call",
|
||||||
crate_path,
|
crate_path,
|
||||||
@@ -61,7 +61,7 @@ pub fn generate_calls(
|
|||||||
.unzip(),
|
.unzip(),
|
||||||
CompositeDefFields::NoFields => Default::default(),
|
CompositeDefFields::NoFields => Default::default(),
|
||||||
CompositeDefFields::Unnamed(_) => {
|
CompositeDefFields::Unnamed(_) => {
|
||||||
return Err(CodegenError::InvalidCallVariant(call.ty.id()))
|
return Err(CodegenError::InvalidCallVariant(call.ty.id))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,8 +106,8 @@ pub fn generate_calls(
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.unzip();
|
.unzip();
|
||||||
|
|
||||||
let call_ty = type_gen.resolve_type(call.ty.id());
|
let call_ty = type_gen.resolve_type(call.ty.id);
|
||||||
let docs = call_ty.docs();
|
let docs = &call_ty.docs;
|
||||||
let docs = should_gen_docs
|
let docs = should_gen_docs
|
||||||
.then_some(quote! { #( #[doc = #docs ] )* })
|
.then_some(quote! { #( #[doc = #docs ] )* })
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ pub fn generate_constants(
|
|||||||
return Err(CodegenError::MissingConstantMetadata(constant_name.into(), pallet_name.into()));
|
return Err(CodegenError::MissingConstantMetadata(constant_name.into(), pallet_name.into()));
|
||||||
};
|
};
|
||||||
|
|
||||||
let return_ty = type_gen.resolve_type_path(constant.ty.id());
|
let return_ty = type_gen.resolve_type_path(constant.ty.id);
|
||||||
let docs = &constant.docs;
|
let docs = &constant.docs;
|
||||||
let docs = should_gen_docs
|
let docs = should_gen_docs
|
||||||
.then_some(quote! { #( #[doc = #docs ] )* })
|
.then_some(quote! { #( #[doc = #docs ] )* })
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ pub fn generate_events(
|
|||||||
|
|
||||||
let struct_defs = super::generate_structs_from_variants(
|
let struct_defs = super::generate_structs_from_variants(
|
||||||
type_gen,
|
type_gen,
|
||||||
event.ty.id(),
|
event.ty.id,
|
||||||
|name| name.into(),
|
|name| name.into(),
|
||||||
"Event",
|
"Event",
|
||||||
crate_path,
|
crate_path,
|
||||||
@@ -74,9 +74,9 @@ pub fn generate_events(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let event_type = type_gen.resolve_type_path(event.ty.id());
|
let event_type = type_gen.resolve_type_path(event.ty.id);
|
||||||
let event_ty = type_gen.resolve_type(event.ty.id());
|
let event_ty = type_gen.resolve_type(event.ty.id);
|
||||||
let docs = event_ty.docs();
|
let docs = &event_ty.docs;
|
||||||
let docs = should_gen_docs
|
let docs = should_gen_docs
|
||||||
.then_some(quote! { #( #[doc = #docs ] )* })
|
.then_some(quote! { #( #[doc = #docs ] )* })
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|||||||
@@ -260,13 +260,13 @@ impl RuntimeGenerator {
|
|||||||
|
|
||||||
// Get the path to the `Runtime` struct. We assume that the same path contains
|
// Get the path to the `Runtime` struct. We assume that the same path contains
|
||||||
// RuntimeCall and RuntimeEvent.
|
// RuntimeCall and RuntimeEvent.
|
||||||
let runtime_type_id = self.metadata.ty.id();
|
let runtime_type_id = self.metadata.ty.id;
|
||||||
let runtime_path_segments = self
|
let runtime_path_segments = self
|
||||||
.metadata
|
.metadata
|
||||||
.types
|
.types
|
||||||
.resolve(runtime_type_id)
|
.resolve(runtime_type_id)
|
||||||
.ok_or(CodegenError::TypeNotFound(runtime_type_id))?
|
.ok_or(CodegenError::TypeNotFound(runtime_type_id))?
|
||||||
.path()
|
.path
|
||||||
.namespace()
|
.namespace()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|part| syn::PathSegment::from(format_ident!("{}", part)));
|
.map(|part| syn::PathSegment::from(format_ident!("{}", part)));
|
||||||
@@ -489,24 +489,24 @@ where
|
|||||||
{
|
{
|
||||||
let ty = type_gen.resolve_type(type_id);
|
let ty = type_gen.resolve_type(type_id);
|
||||||
|
|
||||||
let scale_info::TypeDef::Variant(variant) = ty.type_def() else {
|
let scale_info::TypeDef::Variant(variant) = &ty.type_def else {
|
||||||
return Err(CodegenError::InvalidType(error_message_type_name.into()))
|
return Err(CodegenError::InvalidType(error_message_type_name.into()))
|
||||||
};
|
};
|
||||||
|
|
||||||
variant
|
variant
|
||||||
.variants()
|
.variants
|
||||||
.iter()
|
.iter()
|
||||||
.map(|var| {
|
.map(|var| {
|
||||||
let struct_name = variant_to_struct_name(var.name());
|
let struct_name = variant_to_struct_name(&var.name);
|
||||||
|
|
||||||
let fields = CompositeDefFields::from_scale_info_fields(
|
let fields = CompositeDefFields::from_scale_info_fields(
|
||||||
struct_name.as_ref(),
|
struct_name.as_ref(),
|
||||||
var.fields(),
|
&var.fields,
|
||||||
&[],
|
&[],
|
||||||
type_gen,
|
type_gen,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let docs = should_gen_docs.then_some(var.docs()).unwrap_or_default();
|
let docs = should_gen_docs.then_some(&*var.docs).unwrap_or_default();
|
||||||
let struct_def = CompositeDef::struct_def(
|
let struct_def = CompositeDef::struct_def(
|
||||||
&ty,
|
&ty,
|
||||||
struct_name.as_ref(),
|
struct_name.as_ref(),
|
||||||
|
|||||||
@@ -74,17 +74,17 @@ fn generate_storage_entry_fns(
|
|||||||
let (fields, key_impl) = match &storage_entry.ty {
|
let (fields, key_impl) = match &storage_entry.ty {
|
||||||
StorageEntryType::Plain(_) => (vec![], quote!(vec![])),
|
StorageEntryType::Plain(_) => (vec![], quote!(vec![])),
|
||||||
StorageEntryType::Map { key, .. } => {
|
StorageEntryType::Map { key, .. } => {
|
||||||
let key_ty = type_gen.resolve_type(key.id());
|
let key_ty = type_gen.resolve_type(key.id);
|
||||||
match key_ty.type_def() {
|
match &key_ty.type_def {
|
||||||
// An N-map; return each of the keys separately.
|
// An N-map; return each of the keys separately.
|
||||||
TypeDef::Tuple(tuple) => {
|
TypeDef::Tuple(tuple) => {
|
||||||
let fields = tuple
|
let fields = tuple
|
||||||
.fields()
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, f)| {
|
.map(|(i, f)| {
|
||||||
let field_name = format_ident!("_{}", syn::Index::from(i));
|
let field_name = format_ident!("_{}", syn::Index::from(i));
|
||||||
let field_type = type_gen.resolve_type_path(f.id());
|
let field_type = type_gen.resolve_type_path(f.id);
|
||||||
(field_name, field_type)
|
(field_name, field_type)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@@ -102,7 +102,7 @@ fn generate_storage_entry_fns(
|
|||||||
}
|
}
|
||||||
// A map with a single key; return the single key.
|
// A map with a single key; return the single key.
|
||||||
_ => {
|
_ => {
|
||||||
let ty_path = type_gen.resolve_type_path(key.id());
|
let ty_path = type_gen.resolve_type_path(key.id);
|
||||||
let fields = vec![(format_ident!("_0"), ty_path)];
|
let fields = vec![(format_ident!("_0"), ty_path)];
|
||||||
let key_impl = quote! {
|
let key_impl = quote! {
|
||||||
vec![ #crate_path::storage::address::make_static_storage_map_key(_0.borrow()) ]
|
vec![ #crate_path::storage::address::make_static_storage_map_key(_0.borrow()) ]
|
||||||
@@ -125,7 +125,7 @@ fn generate_storage_entry_fns(
|
|||||||
StorageEntryType::Plain(ref ty) => ty,
|
StorageEntryType::Plain(ref ty) => ty,
|
||||||
StorageEntryType::Map { ref value, .. } => value,
|
StorageEntryType::Map { ref value, .. } => value,
|
||||||
};
|
};
|
||||||
let storage_entry_value_ty = type_gen.resolve_type_path(storage_entry_ty.id());
|
let storage_entry_value_ty = type_gen.resolve_type_path(storage_entry_ty.id);
|
||||||
|
|
||||||
let docs = &storage_entry.docs;
|
let docs = &storage_entry.docs;
|
||||||
let docs = should_gen_docs
|
let docs = should_gen_docs
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ impl CompositeDef {
|
|||||||
{
|
{
|
||||||
let ty = type_gen.resolve_type(field.type_id);
|
let ty = type_gen.resolve_type(field.type_id);
|
||||||
if matches!(
|
if matches!(
|
||||||
ty.type_def(),
|
ty.type_def,
|
||||||
TypeDef::Primitive(
|
TypeDef::Primitive(
|
||||||
TypeDefPrimitive::U8
|
TypeDefPrimitive::U8
|
||||||
| TypeDefPrimitive::U16
|
| TypeDefPrimitive::U16
|
||||||
@@ -173,11 +173,11 @@ impl CompositeDefFields {
|
|||||||
let mut unnamed_fields = Vec::new();
|
let mut unnamed_fields = Vec::new();
|
||||||
|
|
||||||
for field in fields {
|
for field in fields {
|
||||||
let type_path = type_gen.resolve_field_type_path(field.ty().id(), parent_type_params);
|
let type_path = type_gen.resolve_field_type_path(field.ty.id, parent_type_params);
|
||||||
let field_type =
|
let field_type =
|
||||||
CompositeDefFieldType::new(field.ty().id(), type_path, field.type_name().cloned());
|
CompositeDefFieldType::new(field.ty.id, type_path, field.type_name.clone());
|
||||||
|
|
||||||
if let Some(name) = field.name() {
|
if let Some(name) = &field.name {
|
||||||
let field_name = format_ident!("{}", name);
|
let field_name = format_ident!("{}", name);
|
||||||
named_fields.push((field_name, field_type))
|
named_fields.push((field_name, field_type))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+21
-26
@@ -73,8 +73,8 @@ impl<'a> TypeGenerator<'a> {
|
|||||||
let root_mod_ident = &self.types_mod_ident;
|
let root_mod_ident = &self.types_mod_ident;
|
||||||
let mut root_mod = Module::new(root_mod_ident.clone(), root_mod_ident.clone());
|
let mut root_mod = Module::new(root_mod_ident.clone(), root_mod_ident.clone());
|
||||||
|
|
||||||
for ty in self.type_registry.types() {
|
for ty in &self.type_registry.types {
|
||||||
let path = ty.ty().path();
|
let path = &ty.ty.path;
|
||||||
// Don't generate a type if it was substituted - the target type might
|
// Don't generate a type if it was substituted - the target type might
|
||||||
// not be in the type registry + our resolution already performs the substitution.
|
// not be in the type registry + our resolution already performs the substitution.
|
||||||
if self.type_substitutes.contains(path) {
|
if self.type_substitutes.contains(path) {
|
||||||
@@ -101,7 +101,7 @@ impl<'a> TypeGenerator<'a> {
|
|||||||
|
|
||||||
innermost_module.types.insert(
|
innermost_module.types.insert(
|
||||||
path.clone(),
|
path.clone(),
|
||||||
TypeDefGen::from_type(ty.ty(), self, &self.crate_path, self.should_gen_docs)?,
|
TypeDefGen::from_type(&ty.ty, self, &self.crate_path, self.should_gen_docs)?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,67 +169,62 @@ impl<'a> TypeGenerator<'a> {
|
|||||||
|
|
||||||
let mut ty = self.resolve_type(id);
|
let mut ty = self.resolve_type(id);
|
||||||
|
|
||||||
if ty.path().ident() == Some("Cow".to_string()) {
|
if ty.path.ident() == Some("Cow".to_string()) {
|
||||||
ty = self.resolve_type(
|
ty = self.resolve_type(
|
||||||
ty.type_params()[0]
|
ty.type_params[0]
|
||||||
.ty()
|
.ty
|
||||||
.expect("type parameters to Cow are not expected to be skipped; qed")
|
.expect("type parameters to Cow are not expected to be skipped; qed")
|
||||||
.id(),
|
.id,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let params: Vec<_> = ty
|
let params: Vec<_> = ty
|
||||||
.type_params()
|
.type_params
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|f| {
|
.filter_map(|f| {
|
||||||
f.ty()
|
f.ty.map(|f| self.resolve_type_path_recurse(f.id, false, parent_type_params))
|
||||||
.map(|f| self.resolve_type_path_recurse(f.id(), false, parent_type_params))
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let ty = match ty.type_def() {
|
let ty = match &ty.type_def {
|
||||||
TypeDef::Composite(_) | TypeDef::Variant(_) => {
|
TypeDef::Composite(_) | TypeDef::Variant(_) => {
|
||||||
if let Some(ty) = self
|
if let Some(ty) = self
|
||||||
.type_substitutes
|
.type_substitutes
|
||||||
.for_path_with_params(ty.path(), ¶ms)
|
.for_path_with_params(&ty.path, ¶ms)
|
||||||
{
|
{
|
||||||
ty
|
ty
|
||||||
} else {
|
} else {
|
||||||
TypePathType::from_type_def_path(
|
TypePathType::from_type_def_path(&ty.path, self.types_mod_ident.clone(), params)
|
||||||
ty.path(),
|
|
||||||
self.types_mod_ident.clone(),
|
|
||||||
params,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypeDef::Primitive(primitive) => TypePathType::Primitive {
|
TypeDef::Primitive(primitive) => TypePathType::Primitive {
|
||||||
def: primitive.clone(),
|
def: primitive.clone(),
|
||||||
},
|
},
|
||||||
TypeDef::Array(arr) => TypePathType::Array {
|
TypeDef::Array(arr) => TypePathType::Array {
|
||||||
len: arr.len() as usize,
|
len: arr.len as usize,
|
||||||
of: Box::new(self.resolve_type_path_recurse(
|
of: Box::new(self.resolve_type_path_recurse(
|
||||||
arr.type_param().id(),
|
arr.type_param.id,
|
||||||
false,
|
false,
|
||||||
parent_type_params,
|
parent_type_params,
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
TypeDef::Sequence(seq) => TypePathType::Vec {
|
TypeDef::Sequence(seq) => TypePathType::Vec {
|
||||||
of: Box::new(self.resolve_type_path_recurse(
|
of: Box::new(self.resolve_type_path_recurse(
|
||||||
seq.type_param().id(),
|
seq.type_param.id,
|
||||||
false,
|
false,
|
||||||
parent_type_params,
|
parent_type_params,
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
TypeDef::Tuple(tuple) => TypePathType::Tuple {
|
TypeDef::Tuple(tuple) => TypePathType::Tuple {
|
||||||
elements: tuple
|
elements: tuple
|
||||||
.fields()
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|f| self.resolve_type_path_recurse(f.id(), false, parent_type_params))
|
.map(|f| self.resolve_type_path_recurse(f.id, false, parent_type_params))
|
||||||
.collect(),
|
.collect(),
|
||||||
},
|
},
|
||||||
TypeDef::Compact(compact) => TypePathType::Compact {
|
TypeDef::Compact(compact) => TypePathType::Compact {
|
||||||
inner: Box::new(self.resolve_type_path_recurse(
|
inner: Box::new(self.resolve_type_path_recurse(
|
||||||
compact.type_param().id(),
|
compact.type_param.id,
|
||||||
false,
|
false,
|
||||||
parent_type_params,
|
parent_type_params,
|
||||||
)),
|
)),
|
||||||
@@ -238,12 +233,12 @@ impl<'a> TypeGenerator<'a> {
|
|||||||
},
|
},
|
||||||
TypeDef::BitSequence(bitseq) => TypePathType::BitVec {
|
TypeDef::BitSequence(bitseq) => TypePathType::BitVec {
|
||||||
bit_order_type: Box::new(self.resolve_type_path_recurse(
|
bit_order_type: Box::new(self.resolve_type_path_recurse(
|
||||||
bitseq.bit_order_type().id(),
|
bitseq.bit_order_type.id,
|
||||||
false,
|
false,
|
||||||
parent_type_params,
|
parent_type_params,
|
||||||
)),
|
)),
|
||||||
bit_store_type: Box::new(self.resolve_type_path_recurse(
|
bit_store_type: Box::new(self.resolve_type_path_recurse(
|
||||||
bitseq.bit_store_type().id(),
|
bitseq.bit_store_type.id,
|
||||||
false,
|
false,
|
||||||
parent_type_params,
|
parent_type_params,
|
||||||
)),
|
)),
|
||||||
@@ -261,7 +256,7 @@ impl<'a> TypeGenerator<'a> {
|
|||||||
|
|
||||||
/// Returns the derives to be applied to a generated type.
|
/// Returns the derives to be applied to a generated type.
|
||||||
pub fn type_derives(&self, ty: &Type<PortableForm>) -> Result<Derives, CodegenError> {
|
pub fn type_derives(&self, ty: &Type<PortableForm>) -> Result<Derives, CodegenError> {
|
||||||
let joined_path = ty.path().segments().join("::");
|
let joined_path = ty.path.segments.join("::");
|
||||||
let ty_path: syn::TypePath = syn::parse_str(&joined_path)
|
let ty_path: syn::TypePath = syn::parse_str(&joined_path)
|
||||||
.map_err(|e| CodegenError::InvalidTypePath(joined_path, e))?;
|
.map_err(|e| CodegenError::InvalidTypePath(joined_path, e))?;
|
||||||
Ok(self.derives.resolve(&ty_path))
|
Ok(self.derives.resolve(&ty_path))
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ impl From<&syn::Path> for PathSegments {
|
|||||||
impl<T: scale_info::form::Form> From<&scale_info::Path<T>> for PathSegments {
|
impl<T: scale_info::form::Form> From<&scale_info::Path<T>> for PathSegments {
|
||||||
fn from(path: &scale_info::Path<T>) -> Self {
|
fn from(path: &scale_info::Path<T>) -> Self {
|
||||||
PathSegments(
|
PathSegments(
|
||||||
path.segments()
|
path.segments
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.as_ref().to_owned())
|
.map(|x| x.as_ref().to_owned())
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|||||||
@@ -40,15 +40,15 @@ impl TypeDefGen {
|
|||||||
let derives = type_gen.type_derives(ty)?;
|
let derives = type_gen.type_derives(ty)?;
|
||||||
|
|
||||||
let type_params = ty
|
let type_params = ty
|
||||||
.type_params()
|
.type_params
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, tp)| match tp.ty() {
|
.filter_map(|(i, tp)| match &tp.ty {
|
||||||
Some(ty) => {
|
Some(ty) => {
|
||||||
let tp_name = format_ident!("_{}", i);
|
let tp_name = format_ident!("_{}", i);
|
||||||
Some(TypeParameter {
|
Some(TypeParameter {
|
||||||
concrete_type_id: ty.id(),
|
concrete_type_id: ty.id,
|
||||||
original_name: tp.name().clone(),
|
original_name: tp.name.clone(),
|
||||||
name: tp_name,
|
name: tp_name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -58,17 +58,17 @@ impl TypeDefGen {
|
|||||||
|
|
||||||
let mut type_params = TypeDefParameters::new(type_params);
|
let mut type_params = TypeDefParameters::new(type_params);
|
||||||
|
|
||||||
let ty_kind = match ty.type_def() {
|
let ty_kind = match &ty.type_def {
|
||||||
TypeDef::Composite(composite) => {
|
TypeDef::Composite(composite) => {
|
||||||
let type_name = ty.path().ident().expect("structs should have a name");
|
let type_name = ty.path.ident().expect("structs should have a name");
|
||||||
let fields = CompositeDefFields::from_scale_info_fields(
|
let fields = CompositeDefFields::from_scale_info_fields(
|
||||||
&type_name,
|
&type_name,
|
||||||
composite.fields(),
|
&composite.fields,
|
||||||
type_params.params(),
|
type_params.params(),
|
||||||
type_gen,
|
type_gen,
|
||||||
)?;
|
)?;
|
||||||
type_params.update_unused(fields.field_types());
|
type_params.update_unused(fields.field_types());
|
||||||
let docs = should_gen_docs.then_some(ty.docs()).unwrap_or_default();
|
let docs = should_gen_docs.then_some(&*ty.docs).unwrap_or_default();
|
||||||
let composite_def = CompositeDef::struct_def(
|
let composite_def = CompositeDef::struct_def(
|
||||||
ty,
|
ty,
|
||||||
&type_name,
|
&type_name,
|
||||||
@@ -82,22 +82,22 @@ impl TypeDefGen {
|
|||||||
TypeDefGenKind::Struct(composite_def)
|
TypeDefGenKind::Struct(composite_def)
|
||||||
}
|
}
|
||||||
TypeDef::Variant(variant) => {
|
TypeDef::Variant(variant) => {
|
||||||
let type_name = ty.path().ident().expect("variants should have a name");
|
let type_name = ty.path.ident().expect("variants should have a name");
|
||||||
|
|
||||||
let variants = variant
|
let variants = variant
|
||||||
.variants()
|
.variants
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
let fields = CompositeDefFields::from_scale_info_fields(
|
let fields = CompositeDefFields::from_scale_info_fields(
|
||||||
v.name(),
|
&v.name,
|
||||||
v.fields(),
|
&v.fields,
|
||||||
type_params.params(),
|
type_params.params(),
|
||||||
type_gen,
|
type_gen,
|
||||||
)?;
|
)?;
|
||||||
type_params.update_unused(fields.field_types());
|
type_params.update_unused(fields.field_types());
|
||||||
let docs = should_gen_docs.then_some(v.docs()).unwrap_or_default();
|
let docs = should_gen_docs.then_some(&*v.docs).unwrap_or_default();
|
||||||
let variant_def = CompositeDef::enum_variant_def(v.name(), fields, docs);
|
let variant_def = CompositeDef::enum_variant_def(&v.name, fields, docs);
|
||||||
Ok((v.index(), variant_def))
|
Ok((v.index, variant_def))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, CodegenError>>()?;
|
.collect::<Result<Vec<_>, CodegenError>>()?;
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ impl TypeDefGen {
|
|||||||
_ => TypeDefGenKind::BuiltIn,
|
_ => TypeDefGenKind::BuiltIn,
|
||||||
};
|
};
|
||||||
|
|
||||||
let docs = ty.docs();
|
let docs = &ty.docs;
|
||||||
let ty_docs = should_gen_docs
|
let ty_docs = should_gen_docs
|
||||||
.then_some(quote! { #( #[doc = #docs ] )* })
|
.then_some(quote! { #( #[doc = #docs ] )* })
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ impl TypePathType {
|
|||||||
root_mod_ident: Ident,
|
root_mod_ident: Ident,
|
||||||
params: Vec<TypePath>,
|
params: Vec<TypePath>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let path_segments = path.segments();
|
let path_segments = &*path.segments;
|
||||||
|
|
||||||
let path: syn::Path = match path_segments {
|
let path: syn::Path = match path_segments {
|
||||||
[] => panic!("Type has no ident"),
|
[] => panic!("Type has no ident"),
|
||||||
|
|||||||
+2
-2
@@ -16,13 +16,13 @@ description = "Command line utilities for checking metadata compatibility betwee
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full"] }
|
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full"] }
|
||||||
frame-metadata = "15.0.0"
|
frame-metadata = "15.0.0"
|
||||||
scale-info = "2.4.0"
|
scale-info = "2.5.0"
|
||||||
sp-core-hashing = "7.0.0"
|
sp-core-hashing = "7.0.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
|
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
|
||||||
criterion = "0.4"
|
criterion = "0.4"
|
||||||
scale-info = { version = "2.4.0", features = ["bit-vec"] }
|
scale-info = { version = "2.5.0", features = ["bit-vec"] }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
# Without this, libtest cli opts interfere with criteron benches:
|
# Without this, libtest cli opts interfere with criteron benches:
|
||||||
|
|||||||
@@ -57,14 +57,14 @@ fn bench_get_call_hash(c: &mut Criterion) {
|
|||||||
for pallet in metadata.pallets.iter() {
|
for pallet in metadata.pallets.iter() {
|
||||||
let pallet_name = &pallet.name;
|
let pallet_name = &pallet.name;
|
||||||
let call_type_id = match &pallet.calls {
|
let call_type_id = match &pallet.calls {
|
||||||
Some(calls) => calls.ty.id(),
|
Some(calls) => calls.ty.id,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
let call_type = metadata.types.resolve(call_type_id).unwrap();
|
let call_type = metadata.types.resolve(call_type_id).unwrap();
|
||||||
let variants = expect_variant(call_type.type_def());
|
let variants = expect_variant(&call_type.type_def);
|
||||||
|
|
||||||
for variant in variants.variants() {
|
for variant in &variants.variants {
|
||||||
let call_name = variant.name();
|
let call_name = &variant.name;
|
||||||
let bench_name = format!("{pallet_name}/{call_name}");
|
let bench_name = format!("{pallet_name}/{call_name}");
|
||||||
group.bench_function(&bench_name, |b| {
|
group.bench_function(&bench_name, |b| {
|
||||||
b.iter(|| get_call_hash(&metadata, &pallet.name, call_name))
|
b.iter(|| get_call_hash(&metadata, &pallet.name, call_name))
|
||||||
|
|||||||
+31
-31
@@ -57,10 +57,10 @@ fn get_field_hash(
|
|||||||
field: &Field<PortableForm>,
|
field: &Field<PortableForm>,
|
||||||
visited_ids: &mut HashSet<u32>,
|
visited_ids: &mut HashSet<u32>,
|
||||||
) -> [u8; 32] {
|
) -> [u8; 32] {
|
||||||
let mut bytes = get_type_hash(registry, field.ty().id(), visited_ids);
|
let mut bytes = get_type_hash(registry, field.ty.id, visited_ids);
|
||||||
|
|
||||||
// XOR name and field name with the type hash if they exist
|
// XOR name and field name with the type hash if they exist
|
||||||
if let Some(name) = field.name() {
|
if let Some(name) = &field.name {
|
||||||
bytes = xor(bytes, hash(name.as_bytes()));
|
bytes = xor(bytes, hash(name.as_bytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +74,8 @@ fn get_variant_hash(
|
|||||||
visited_ids: &mut HashSet<u32>,
|
visited_ids: &mut HashSet<u32>,
|
||||||
) -> [u8; 32] {
|
) -> [u8; 32] {
|
||||||
// Merge our hashes of the name and each field together using xor.
|
// Merge our hashes of the name and each field together using xor.
|
||||||
let mut bytes = hash(var.name().as_bytes());
|
let mut bytes = hash(var.name.as_bytes());
|
||||||
for field in var.fields() {
|
for field in &var.fields {
|
||||||
bytes = hash_hashes(bytes, get_field_hash(registry, field, visited_ids))
|
bytes = hash_hashes(bytes, get_field_hash(registry, field, visited_ids))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,14 +91,14 @@ fn get_type_def_hash(
|
|||||||
match ty_def {
|
match ty_def {
|
||||||
TypeDef::Composite(composite) => {
|
TypeDef::Composite(composite) => {
|
||||||
let mut bytes = hash(&[TypeBeingHashed::Composite as u8]);
|
let mut bytes = hash(&[TypeBeingHashed::Composite as u8]);
|
||||||
for field in composite.fields() {
|
for field in &composite.fields {
|
||||||
bytes = hash_hashes(bytes, get_field_hash(registry, field, visited_ids));
|
bytes = hash_hashes(bytes, get_field_hash(registry, field, visited_ids));
|
||||||
}
|
}
|
||||||
bytes
|
bytes
|
||||||
}
|
}
|
||||||
TypeDef::Variant(variant) => {
|
TypeDef::Variant(variant) => {
|
||||||
let mut bytes = hash(&[TypeBeingHashed::Variant as u8]);
|
let mut bytes = hash(&[TypeBeingHashed::Variant as u8]);
|
||||||
for var in variant.variants().iter() {
|
for var in &variant.variants {
|
||||||
bytes = hash_hashes(bytes, get_variant_hash(registry, var, visited_ids));
|
bytes = hash_hashes(bytes, get_variant_hash(registry, var, visited_ids));
|
||||||
}
|
}
|
||||||
bytes
|
bytes
|
||||||
@@ -107,12 +107,12 @@ fn get_type_def_hash(
|
|||||||
let bytes = hash(&[TypeBeingHashed::Sequence as u8]);
|
let bytes = hash(&[TypeBeingHashed::Sequence as u8]);
|
||||||
xor(
|
xor(
|
||||||
bytes,
|
bytes,
|
||||||
get_type_hash(registry, sequence.type_param().id(), visited_ids),
|
get_type_hash(registry, sequence.type_param.id, visited_ids),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TypeDef::Array(array) => {
|
TypeDef::Array(array) => {
|
||||||
// Take length into account; different length must lead to different hash.
|
// Take length into account; different length must lead to different hash.
|
||||||
let len_bytes = array.len().to_be_bytes();
|
let len_bytes = array.len.to_be_bytes();
|
||||||
let bytes = hash(&[
|
let bytes = hash(&[
|
||||||
TypeBeingHashed::Array as u8,
|
TypeBeingHashed::Array as u8,
|
||||||
len_bytes[0],
|
len_bytes[0],
|
||||||
@@ -122,13 +122,13 @@ fn get_type_def_hash(
|
|||||||
]);
|
]);
|
||||||
xor(
|
xor(
|
||||||
bytes,
|
bytes,
|
||||||
get_type_hash(registry, array.type_param().id(), visited_ids),
|
get_type_hash(registry, array.type_param.id, visited_ids),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TypeDef::Tuple(tuple) => {
|
TypeDef::Tuple(tuple) => {
|
||||||
let mut bytes = hash(&[TypeBeingHashed::Tuple as u8]);
|
let mut bytes = hash(&[TypeBeingHashed::Tuple as u8]);
|
||||||
for field in tuple.fields() {
|
for field in &tuple.fields {
|
||||||
bytes = hash_hashes(bytes, get_type_hash(registry, field.id(), visited_ids));
|
bytes = hash_hashes(bytes, get_type_hash(registry, field.id, visited_ids));
|
||||||
}
|
}
|
||||||
bytes
|
bytes
|
||||||
}
|
}
|
||||||
@@ -140,18 +140,18 @@ fn get_type_def_hash(
|
|||||||
let bytes = hash(&[TypeBeingHashed::Compact as u8]);
|
let bytes = hash(&[TypeBeingHashed::Compact as u8]);
|
||||||
xor(
|
xor(
|
||||||
bytes,
|
bytes,
|
||||||
get_type_hash(registry, compact.type_param().id(), visited_ids),
|
get_type_hash(registry, compact.type_param.id, visited_ids),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TypeDef::BitSequence(bitseq) => {
|
TypeDef::BitSequence(bitseq) => {
|
||||||
let mut bytes = hash(&[TypeBeingHashed::BitSequence as u8]);
|
let mut bytes = hash(&[TypeBeingHashed::BitSequence as u8]);
|
||||||
bytes = xor(
|
bytes = xor(
|
||||||
bytes,
|
bytes,
|
||||||
get_type_hash(registry, bitseq.bit_order_type().id(), visited_ids),
|
get_type_hash(registry, bitseq.bit_order_type.id, visited_ids),
|
||||||
);
|
);
|
||||||
bytes = xor(
|
bytes = xor(
|
||||||
bytes,
|
bytes,
|
||||||
get_type_hash(registry, bitseq.bit_store_type().id(), visited_ids),
|
get_type_hash(registry, bitseq.bit_store_type.id, visited_ids),
|
||||||
);
|
);
|
||||||
bytes
|
bytes
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ fn get_type_hash(registry: &PortableRegistry, id: u32, visited_ids: &mut HashSet
|
|||||||
}
|
}
|
||||||
|
|
||||||
let ty = registry.resolve(id).unwrap();
|
let ty = registry.resolve(id).unwrap();
|
||||||
get_type_def_hash(registry, ty.type_def(), visited_ids)
|
get_type_def_hash(registry, &ty.type_def, visited_ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtain the hash representation of a `frame_metadata::ExtrinsicMetadata`.
|
/// Obtain the hash representation of a `frame_metadata::ExtrinsicMetadata`.
|
||||||
@@ -176,20 +176,20 @@ fn get_extrinsic_hash(
|
|||||||
) -> [u8; 32] {
|
) -> [u8; 32] {
|
||||||
let mut visited_ids = HashSet::<u32>::new();
|
let mut visited_ids = HashSet::<u32>::new();
|
||||||
|
|
||||||
let mut bytes = get_type_hash(registry, extrinsic.ty.id(), &mut visited_ids);
|
let mut bytes = get_type_hash(registry, extrinsic.ty.id, &mut visited_ids);
|
||||||
|
|
||||||
bytes = xor(bytes, hash(&[extrinsic.version]));
|
bytes = xor(bytes, hash(&[extrinsic.version]));
|
||||||
for signed_extension in extrinsic.signed_extensions.iter() {
|
for signed_extension in extrinsic.signed_extensions.iter() {
|
||||||
let mut ext_bytes = hash(signed_extension.identifier.as_bytes());
|
let mut ext_bytes = hash(signed_extension.identifier.as_bytes());
|
||||||
ext_bytes = xor(
|
ext_bytes = xor(
|
||||||
ext_bytes,
|
ext_bytes,
|
||||||
get_type_hash(registry, signed_extension.ty.id(), &mut visited_ids),
|
get_type_hash(registry, signed_extension.ty.id, &mut visited_ids),
|
||||||
);
|
);
|
||||||
ext_bytes = xor(
|
ext_bytes = xor(
|
||||||
ext_bytes,
|
ext_bytes,
|
||||||
get_type_hash(
|
get_type_hash(
|
||||||
registry,
|
registry,
|
||||||
signed_extension.additional_signed.id(),
|
signed_extension.additional_signed.id,
|
||||||
&mut visited_ids,
|
&mut visited_ids,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -212,7 +212,7 @@ fn get_storage_entry_hash(
|
|||||||
|
|
||||||
match &entry.ty {
|
match &entry.ty {
|
||||||
StorageEntryType::Plain(ty) => {
|
StorageEntryType::Plain(ty) => {
|
||||||
bytes = xor(bytes, get_type_hash(registry, ty.id(), visited_ids));
|
bytes = xor(bytes, get_type_hash(registry, ty.id, visited_ids));
|
||||||
}
|
}
|
||||||
StorageEntryType::Map {
|
StorageEntryType::Map {
|
||||||
hashers,
|
hashers,
|
||||||
@@ -223,8 +223,8 @@ fn get_storage_entry_hash(
|
|||||||
// Cloning the hasher should essentially be a copy.
|
// Cloning the hasher should essentially be a copy.
|
||||||
bytes = hash_hashes(bytes, [hasher.clone() as u8; 32]);
|
bytes = hash_hashes(bytes, [hasher.clone() as u8; 32]);
|
||||||
}
|
}
|
||||||
bytes = xor(bytes, get_type_hash(registry, key.id(), visited_ids));
|
bytes = xor(bytes, get_type_hash(registry, key.id, visited_ids));
|
||||||
bytes = xor(bytes, get_type_hash(registry, value.id(), visited_ids));
|
bytes = xor(bytes, get_type_hash(registry, value.id, visited_ids));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ pub fn get_constant_hash(
|
|||||||
.ok_or(NotFound::Item)?;
|
.ok_or(NotFound::Item)?;
|
||||||
|
|
||||||
// We only need to check that the type of the constant asked for matches.
|
// We only need to check that the type of the constant asked for matches.
|
||||||
let bytes = get_type_hash(&metadata.types, constant.ty.id(), &mut HashSet::new());
|
let bytes = get_type_hash(&metadata.types, constant.ty.id, &mut HashSet::new());
|
||||||
Ok(bytes)
|
Ok(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,18 +290,18 @@ pub fn get_call_hash(
|
|||||||
.find(|p| p.name == pallet_name)
|
.find(|p| p.name == pallet_name)
|
||||||
.ok_or(NotFound::Pallet)?;
|
.ok_or(NotFound::Pallet)?;
|
||||||
|
|
||||||
let call_id = pallet.calls.as_ref().ok_or(NotFound::Item)?.ty.id();
|
let call_id = pallet.calls.as_ref().ok_or(NotFound::Item)?.ty.id;
|
||||||
|
|
||||||
let call_ty = metadata.types.resolve(call_id).ok_or(NotFound::Item)?;
|
let call_ty = metadata.types.resolve(call_id).ok_or(NotFound::Item)?;
|
||||||
|
|
||||||
let call_variants = match call_ty.type_def() {
|
let call_variants = match &call_ty.type_def {
|
||||||
TypeDef::Variant(variant) => variant.variants(),
|
TypeDef::Variant(variant) => &variant.variants,
|
||||||
_ => return Err(NotFound::Item),
|
_ => return Err(NotFound::Item),
|
||||||
};
|
};
|
||||||
|
|
||||||
let variant = call_variants
|
let variant = call_variants
|
||||||
.iter()
|
.iter()
|
||||||
.find(|v| v.name() == call_name)
|
.find(|v| v.name == call_name)
|
||||||
.ok_or(NotFound::Item)?;
|
.ok_or(NotFound::Item)?;
|
||||||
|
|
||||||
// hash the specific variant representing the call we are interested in.
|
// hash the specific variant representing the call we are interested in.
|
||||||
@@ -321,26 +321,26 @@ pub fn get_pallet_hash(
|
|||||||
if let Some(calls) = &pallet.calls {
|
if let Some(calls) = &pallet.calls {
|
||||||
bytes = xor(
|
bytes = xor(
|
||||||
bytes,
|
bytes,
|
||||||
get_type_hash(registry, calls.ty.id(), &mut visited_ids),
|
get_type_hash(registry, calls.ty.id, &mut visited_ids),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(ref event) = pallet.event {
|
if let Some(ref event) = pallet.event {
|
||||||
bytes = xor(
|
bytes = xor(
|
||||||
bytes,
|
bytes,
|
||||||
get_type_hash(registry, event.ty.id(), &mut visited_ids),
|
get_type_hash(registry, event.ty.id, &mut visited_ids),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for constant in pallet.constants.iter() {
|
for constant in pallet.constants.iter() {
|
||||||
bytes = xor(bytes, hash(constant.name.as_bytes()));
|
bytes = xor(bytes, hash(constant.name.as_bytes()));
|
||||||
bytes = xor(
|
bytes = xor(
|
||||||
bytes,
|
bytes,
|
||||||
get_type_hash(registry, constant.ty.id(), &mut visited_ids),
|
get_type_hash(registry, constant.ty.id, &mut visited_ids),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(ref error) = pallet.error {
|
if let Some(ref error) = pallet.error {
|
||||||
bytes = xor(
|
bytes = xor(
|
||||||
bytes,
|
bytes,
|
||||||
get_type_hash(registry, error.ty.id(), &mut visited_ids),
|
get_type_hash(registry, error.ty.id, &mut visited_ids),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(ref storage) = pallet.storage {
|
if let Some(ref storage) = pallet.storage {
|
||||||
@@ -384,7 +384,7 @@ pub fn get_metadata_hash(metadata: &RuntimeMetadataV14) -> [u8; 32] {
|
|||||||
let mut visited_ids = HashSet::<u32>::new();
|
let mut visited_ids = HashSet::<u32>::new();
|
||||||
bytes.extend(get_type_hash(
|
bytes.extend(get_type_hash(
|
||||||
&metadata.types,
|
&metadata.types,
|
||||||
metadata.ty.id(),
|
metadata.ty.id,
|
||||||
&mut visited_ids,
|
&mut visited_ids,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -36,7 +36,7 @@ jsonrpsee-web = ["jsonrpsee/async-wasm-client", "jsonrpsee/client-web-transport"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full"] }
|
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full"] }
|
||||||
scale-info = "2.4.0"
|
scale-info = "2.5.0"
|
||||||
scale-value = "0.7.0"
|
scale-value = "0.7.0"
|
||||||
scale-bits = "0.3"
|
scale-bits = "0.3"
|
||||||
scale-decode = "0.5.0"
|
scale-decode = "0.5.0"
|
||||||
@@ -75,7 +75,7 @@ getrandom = { version = "0.2", features = ["js"] }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bitvec = "1"
|
bitvec = "1"
|
||||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
|
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
|
||||||
scale-info = { version = "2.4.0", features = ["bit-vec"] }
|
scale-info = { version = "2.5.0", features = ["bit-vec"] }
|
||||||
tokio = { version = "1.27", features = ["macros", "time", "rt-multi-thread"] }
|
tokio = { version = "1.27", features = ["macros", "time", "rt-multi-thread"] }
|
||||||
sp-core = { version = "18.0.0", default-features = false }
|
sp-core = { version = "18.0.0", default-features = false }
|
||||||
sp-runtime = "20.0.0"
|
sp-runtime = "20.0.0"
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ impl<T: Config, Client: OfflineClientT<T>> ConstantsClient<T, Client> {
|
|||||||
let constant = pallet.constant(address.constant_name())?;
|
let constant = pallet.constant(address.constant_name())?;
|
||||||
let value = <Address::Target as DecodeWithMetadata>::decode_with_metadata(
|
let value = <Address::Target as DecodeWithMetadata>::decode_with_metadata(
|
||||||
&mut &*constant.value,
|
&mut &*constant.value,
|
||||||
constant.ty.id(),
|
constant.ty.id,
|
||||||
&metadata,
|
&metadata,
|
||||||
)?;
|
)?;
|
||||||
Ok(value)
|
Ok(value)
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ impl EventDetails {
|
|||||||
// Skip over the bytes for this field:
|
// Skip over the bytes for this field:
|
||||||
scale_decode::visitor::decode_with_visitor(
|
scale_decode::visitor::decode_with_visitor(
|
||||||
input,
|
input,
|
||||||
field_metadata.ty().id(),
|
field_metadata.ty.id,
|
||||||
&metadata.runtime_metadata().types,
|
&metadata.runtime_metadata().types,
|
||||||
scale_decode::visitor::IgnoreVisitor,
|
scale_decode::visitor::IgnoreVisitor,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -380,7 +380,7 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
|
|||||||
.types
|
.types
|
||||||
.resolve(type_id)
|
.resolve(type_id)
|
||||||
.ok_or(InvalidMetadataError::MissingType(type_id))?;
|
.ok_or(InvalidMetadataError::MissingType(type_id))?;
|
||||||
if let scale_info::TypeDef::Variant(var) = ty.type_def() {
|
if let scale_info::TypeDef::Variant(var) = &ty.type_def {
|
||||||
Ok(var)
|
Ok(var)
|
||||||
} else {
|
} else {
|
||||||
Err(InvalidMetadataError::TypeDefNotVariant(type_id))
|
Err(InvalidMetadataError::TypeDefNotVariant(type_id))
|
||||||
@@ -390,20 +390,20 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
|
|||||||
.pallets
|
.pallets
|
||||||
.iter()
|
.iter()
|
||||||
.map(|pallet| {
|
.map(|pallet| {
|
||||||
let call_ty_id = pallet.calls.as_ref().map(|c| c.ty.id());
|
let call_ty_id = pallet.calls.as_ref().map(|c| c.ty.id);
|
||||||
let event_ty_id = pallet.event.as_ref().map(|e| e.ty.id());
|
let event_ty_id = pallet.event.as_ref().map(|e| e.ty.id);
|
||||||
|
|
||||||
let call_metadata = pallet.calls.as_ref().map_or(Ok(HashMap::new()), |call| {
|
let call_metadata = pallet.calls.as_ref().map_or(Ok(HashMap::new()), |call| {
|
||||||
let type_def_variant = get_type_def_variant(call.ty.id())?;
|
let type_def_variant = get_type_def_variant(call.ty.id)?;
|
||||||
let call_indexes = type_def_variant
|
let call_indexes = type_def_variant
|
||||||
.variants()
|
.variants
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
(
|
(
|
||||||
v.name().clone(),
|
v.name.clone(),
|
||||||
CallMetadata {
|
CallMetadata {
|
||||||
call_index: v.index(),
|
call_index: v.index,
|
||||||
fields: v.fields().to_vec(),
|
fields: v.fields.to_vec(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -443,16 +443,16 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
|
|||||||
for pallet in &metadata.pallets {
|
for pallet in &metadata.pallets {
|
||||||
if let Some(event) = &pallet.event {
|
if let Some(event) = &pallet.event {
|
||||||
let pallet_name: Arc<str> = pallet.name.to_string().into();
|
let pallet_name: Arc<str> = pallet.name.to_string().into();
|
||||||
let event_type_id = event.ty.id();
|
let event_type_id = event.ty.id;
|
||||||
let event_variant = get_type_def_variant(event_type_id)?;
|
let event_variant = get_type_def_variant(event_type_id)?;
|
||||||
for variant in event_variant.variants() {
|
for variant in &event_variant.variants {
|
||||||
events.insert(
|
events.insert(
|
||||||
(pallet.index, variant.index()),
|
(pallet.index, variant.index),
|
||||||
EventMetadata {
|
EventMetadata {
|
||||||
pallet: pallet_name.clone(),
|
pallet: pallet_name.clone(),
|
||||||
event: variant.name().to_owned(),
|
event: variant.name.clone(),
|
||||||
fields: variant.fields().to_vec(),
|
fields: variant.fields.clone(),
|
||||||
docs: variant.docs().to_vec(),
|
docs: variant.docs.clone(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -463,14 +463,14 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
|
|||||||
for pallet in &metadata.pallets {
|
for pallet in &metadata.pallets {
|
||||||
if let Some(error) = &pallet.error {
|
if let Some(error) = &pallet.error {
|
||||||
let pallet_name: Arc<str> = pallet.name.to_string().into();
|
let pallet_name: Arc<str> = pallet.name.to_string().into();
|
||||||
let error_variant = get_type_def_variant(error.ty.id())?;
|
let error_variant = get_type_def_variant(error.ty.id)?;
|
||||||
for variant in error_variant.variants() {
|
for variant in &error_variant.variants {
|
||||||
errors.insert(
|
errors.insert(
|
||||||
(pallet.index, variant.index()),
|
(pallet.index, variant.index),
|
||||||
ErrorMetadata {
|
ErrorMetadata {
|
||||||
pallet: pallet_name.clone(),
|
pallet: pallet_name.clone(),
|
||||||
error: variant.name().clone(),
|
error: variant.name.clone(),
|
||||||
docs: variant.docs().to_vec(),
|
docs: variant.docs.clone(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -479,10 +479,10 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
|
|||||||
|
|
||||||
let dispatch_error_ty = metadata
|
let dispatch_error_ty = metadata
|
||||||
.types
|
.types
|
||||||
.types()
|
.types
|
||||||
.iter()
|
.iter()
|
||||||
.find(|ty| ty.ty().path().segments() == ["sp_runtime", "DispatchError"])
|
.find(|ty| ty.ty.path.segments == ["sp_runtime", "DispatchError"])
|
||||||
.map(|ty| ty.id());
|
.map(|ty| ty.id);
|
||||||
|
|
||||||
Ok(Metadata {
|
Ok(Metadata {
|
||||||
inner: Arc::new(MetadataInner {
|
inner: Arc::new(MetadataInner {
|
||||||
|
|||||||
@@ -155,16 +155,16 @@ where
|
|||||||
}
|
}
|
||||||
StorageEntryType::Map { hashers, key, .. } => {
|
StorageEntryType::Map { hashers, key, .. } => {
|
||||||
let ty = metadata
|
let ty = metadata
|
||||||
.resolve_type(key.id())
|
.resolve_type(key.id)
|
||||||
.ok_or_else(|| StorageAddressError::TypeNotFound(key.id()))?;
|
.ok_or(StorageAddressError::TypeNotFound(key.id))?;
|
||||||
|
|
||||||
// If the key is a tuple, we encode each value to the corresponding tuple type.
|
// If the key is a tuple, we encode each value to the corresponding tuple type.
|
||||||
// If the key is not a tuple, encode a single value to the key type.
|
// If the key is not a tuple, encode a single value to the key type.
|
||||||
let type_ids = match ty.type_def() {
|
let type_ids = match &ty.type_def {
|
||||||
TypeDef::Tuple(tuple) => {
|
TypeDef::Tuple(tuple) => {
|
||||||
either::Either::Left(tuple.fields().iter().map(|f| f.id()))
|
either::Either::Left(tuple.fields.iter().map(|f| f.id))
|
||||||
}
|
}
|
||||||
_other => either::Either::Right(std::iter::once(key.id())),
|
_other => either::Either::Right(std::iter::once(key.id)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if type_ids.len() != self.storage_entry_keys.len() {
|
if type_ids.len() != self.storage_entry_keys.len() {
|
||||||
|
|||||||
@@ -352,8 +352,8 @@ fn lookup_storage_return_type(
|
|||||||
/// Fetch the return type out of a [`StorageEntryType`].
|
/// Fetch the return type out of a [`StorageEntryType`].
|
||||||
fn return_type_from_storage_entry_type(entry: &StorageEntryType<PortableForm>) -> u32 {
|
fn return_type_from_storage_entry_type(entry: &StorageEntryType<PortableForm>) -> u32 {
|
||||||
match entry {
|
match entry {
|
||||||
StorageEntryType::Plain(ty) => ty.id(),
|
StorageEntryType::Plain(ty) => ty.id,
|
||||||
StorageEntryType::Map { value, .. } => value.id(),
|
StorageEntryType::Map { value, .. } => value.id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,8 +367,8 @@ fn decode_storage_with_metadata<T: DecodeWithMetadata>(
|
|||||||
let ty = &metadata.pallet(pallet_name)?.storage(storage_entry)?.ty;
|
let ty = &metadata.pallet(pallet_name)?.storage(storage_entry)?.ty;
|
||||||
|
|
||||||
let id = match ty {
|
let id = match ty {
|
||||||
StorageEntryType::Plain(ty) => ty.id(),
|
StorageEntryType::Plain(ty) => ty.id,
|
||||||
StorageEntryType::Map { value, .. } => value.id(),
|
StorageEntryType::Map { value, .. } => value.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let val = T::decode_with_metadata(bytes, id, metadata)?;
|
let val = T::decode_with_metadata(bytes, id, metadata)?;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ impl<T> EncodeAsType for WrapperKeepOpaque<T> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Do a basic check that the target shape lines up.
|
// Do a basic check that the target shape lines up.
|
||||||
let scale_info::TypeDef::Composite(_) = ty.type_def() else {
|
let scale_info::TypeDef::Composite(_) = ty.type_def else {
|
||||||
return Err(Error::new(ErrorKind::WrongShape {
|
return Err(Error::new(ErrorKind::WrongShape {
|
||||||
actual: Kind::Struct,
|
actual: Kind::Struct,
|
||||||
expected: type_id,
|
expected: type_id,
|
||||||
@@ -95,7 +95,7 @@ impl<T> EncodeAsType for WrapperKeepOpaque<T> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Check that the name also lines up.
|
// Check that the name also lines up.
|
||||||
if ty.path().ident().as_deref() != Some("WrapperKeepOpaque") {
|
if ty.path.ident().as_deref() != Some("WrapperKeepOpaque") {
|
||||||
return Err(Error::new(ErrorKind::WrongShape {
|
return Err(Error::new(ErrorKind::WrongShape {
|
||||||
actual: Kind::Struct,
|
actual: Kind::Struct,
|
||||||
expected: type_id,
|
expected: type_id,
|
||||||
@@ -188,7 +188,7 @@ mod test {
|
|||||||
let mut types = scale_info::Registry::new();
|
let mut types = scale_info::Registry::new();
|
||||||
let id = types.register_type(&m);
|
let id = types.register_type(&m);
|
||||||
let portable_registry: scale_info::PortableRegistry = types.into();
|
let portable_registry: scale_info::PortableRegistry = types.into();
|
||||||
(id.id(), portable_registry)
|
(id.id, portable_registry)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn roundtrips_like_scale_codec<T>(t: T)
|
fn roundtrips_like_scale_codec<T>(t: T)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ frame-metadata = "15.0.0"
|
|||||||
futures = "0.3.27"
|
futures = "0.3.27"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
regex = "1.7.3"
|
regex = "1.7.3"
|
||||||
scale-info = { version = "2.4.0", features = ["bit-vec"] }
|
scale-info = { version = "2.5.0", features = ["bit-vec"] }
|
||||||
sp-core = { version = "18.0.0", default-features = false }
|
sp-core = { version = "18.0.0", default-features = false }
|
||||||
sp-runtime = "20.0.0"
|
sp-runtime = "20.0.0"
|
||||||
sp-keyring = "20.0.0"
|
sp-keyring = "20.0.0"
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ fn metadata_docs() -> Vec<String> {
|
|||||||
|
|
||||||
// Inspect the metadata types and collect the documentation.
|
// Inspect the metadata types and collect the documentation.
|
||||||
let mut docs = Vec::new();
|
let mut docs = Vec::new();
|
||||||
for ty in metadata.types.types() {
|
for ty in &metadata.types.types {
|
||||||
docs.extend_from_slice(ty.ty().docs());
|
docs.extend_from_slice(&ty.ty.docs);
|
||||||
}
|
}
|
||||||
|
|
||||||
for pallet in metadata.pallets {
|
for pallet in metadata.pallets {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ publish = false
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
trybuild = "1.0.79"
|
trybuild = "1.0.79"
|
||||||
scale-info = { version = "2.4.0", features = ["bit-vec"] }
|
scale-info = { version = "2.5.0", features = ["bit-vec"] }
|
||||||
frame-metadata = "15.0.0"
|
frame-metadata = "15.0.0"
|
||||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
|
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
|
||||||
subxt = { path = "../../subxt" }
|
subxt = { path = "../../subxt" }
|
||||||
|
|||||||
Reference in New Issue
Block a user