From 28f6cebabc384fb9376a57b8e22b0398f9ffbff8 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Wed, 28 Feb 2024 13:23:58 +0100 Subject: [PATCH 1/8] start migrating, broken --- Cargo.lock | 105 ++++++++++++++++++++----- Cargo.toml | 8 +- subxt/Cargo.toml | 18 +---- subxt/src/blocks/extrinsic_types.rs | 30 ++++--- subxt/src/dynamic.rs | 4 +- subxt/src/error/dispatch_error.rs | 14 ++-- subxt/src/events/events_type.rs | 16 ++-- subxt/src/tx/mod.rs | 2 +- subxt/src/tx/tx_payload.rs | 19 +---- subxt/src/utils/bits.rs | 39 +++++---- subxt/src/utils/static_type.rs | 22 +++--- subxt/src/utils/unchecked_extrinsic.rs | 30 ++++--- subxt/src/utils/wrapper_opaque.rs | 42 ++++++---- 13 files changed, 202 insertions(+), 147 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 502183c315..4205c4e4fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3480,29 +3480,53 @@ dependencies = [ "serde", ] +[[package]] +name = "scale-bits" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "662d10dcd57b1c2a3c41c9cf68f71fb09747ada1ea932ad961aca7e2ca28315f" +dependencies = [ + "parity-scale-codec", + "scale-info", + "scale-type-resolver", + "serde", +] + [[package]] name = "scale-decode" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7caaf753f8ed1ab4752c6afb20174f03598c664724e0e32628e161c21000ff76" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-bits 0.4.0", + "scale-info", + "smallvec", +] + +[[package]] +name = "scale-decode" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc79ba56a1c742f5aeeed1f1801f3edf51f7e818f0a54582cac6f131364ea7b" dependencies = [ "derive_more", "parity-scale-codec", "primitive-types", - "scale-bits", + "scale-bits 0.5.0", "scale-decode-derive", - "scale-info", + "scale-type-resolver", "smallvec", ] [[package]] name = "scale-decode-derive" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3475108a1b62c7efd1b5c65974f30109a598b2f45f23c9ae030acb9686966db" +checksum = "5398fdb3c7bea3cb419bac4983aadacae93fe1a7b5f693f4ebd98c3821aad7a5" dependencies = [ "darling 0.14.4", - "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -3513,21 +3537,34 @@ name = "scale-encode" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d70cb4b29360105483fac1ed567ff95d65224a14dd275b6303ed0a654c78de5" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-bits 0.4.0", + "scale-info", + "smallvec", +] + +[[package]] +name = "scale-encode" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628800925a33794fb5387781b883b5e14d130fece9af5a63613867b8de07c5c7" dependencies = [ "derive_more", "parity-scale-codec", "primitive-types", - "scale-bits", + "scale-bits 0.5.0", "scale-encode-derive", - "scale-info", + "scale-type-resolver", "smallvec", ] [[package]] name = "scale-encode-derive" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "995491f110efdc6bea96d6a746140e32bfceb4ea47510750a5467295a4707a25" +checksum = "7a304e1af7cdfbe7a24e08b012721456cc8cecdedadc14b3d10513eada63233c" dependencies = [ "darling 0.14.4", "proc-macro-crate 1.3.1", @@ -3562,6 +3599,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scale-type-resolver" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10b800069bfd43374e0f96f653e0d46882a2cb16d6d961ac43bea80f26c76843" +dependencies = [ + "scale-info", + "smallvec", +] + [[package]] name = "scale-typegen" version = "0.1.1" @@ -3589,7 +3636,7 @@ dependencies = [ "rand_chacha", "scale-info", "scale-typegen", - "scale-value", + "scale-value 0.13.0", "smallvec", ] @@ -3605,10 +3652,31 @@ dependencies = [ "either", "frame-metadata 15.1.0", "parity-scale-codec", - "scale-bits", - "scale-decode", - "scale-encode", + "scale-bits 0.4.0", + "scale-decode 0.10.0", + "scale-encode 0.5.0", + "scale-info", + "serde", + "yap", +] + +[[package]] +name = "scale-value" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c518ab8d2f3d6625f651409d4d223ebea8517fc41cd9814c1ab892f8f259a5" +dependencies = [ + "base58", + "blake2", + "derive_more", + "either", + "frame-metadata 15.1.0", + "parity-scale-codec", + "scale-bits 0.5.0", + "scale-decode 0.11.1", + "scale-encode 0.6.0", "scale-info", + "scale-type-resolver", "serde", "yap", ] @@ -4517,11 +4585,11 @@ dependencies = [ "parity-scale-codec", "primitive-types", "reconnecting-jsonrpsee-ws-client", - "scale-bits", - "scale-decode", - "scale-encode", + "scale-bits 0.5.0", + "scale-decode 0.11.1", + "scale-encode 0.6.0", "scale-info", - "scale-value", + "scale-value 0.14.0", "serde", "serde_json", "sp-core", @@ -4531,7 +4599,6 @@ dependencies = [ "subxt-lightclient", "subxt-macro", "subxt-metadata", - "subxt-signer", "thiserror", "tokio", "tokio-stream", @@ -4557,7 +4624,7 @@ dependencies = [ "quote", "scale-info", "scale-typegen-description", - "scale-value", + "scale-value 0.14.0", "serde", "serde_json", "smoldot", diff --git a/Cargo.toml b/Cargo.toml index d7165f0dfc..4610db5a2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,10 +81,10 @@ proc-macro2 = "1.0.78" quote = "1.0.35" regex = "1.10.3" scale-info = { version = "2.10.0", default-features = false } -scale-value = "0.13.0" -scale-bits = "0.4.0" -scale-decode = "0.10.0" -scale-encode = "0.5.0" +scale-value = "0.14.0" +scale-bits = "0.5.0" +scale-decode = "0.11.1" +scale-encode = "0.6.0" serde = { version = "1.0.197" } serde_json = { version = "1.0.114" } syn = { version = "2.0.15", features = ["full", "extra-traits"] } diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 4a18bb2b41..62b8bd64ab 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -24,23 +24,11 @@ default = ["jsonrpsee", "native"] # Enable this for native (ie non web/wasm builds). # Exactly 1 of "web" and "native" is expected. -native = [ - "jsonrpsee?/async-client", - "jsonrpsee?/client-ws-transport-native-tls", - "subxt-lightclient?/native", - "tokio-util" -] +native = ["jsonrpsee?/async-client", "jsonrpsee?/client-ws-transport-native-tls", "subxt-lightclient?/native", "tokio-util"] # Enable this for web/wasm builds. # Exactly 1 of "web" and "native" is expected. -web = [ - "jsonrpsee?/async-wasm-client", - "jsonrpsee?/client-web-transport", - "getrandom/js", - "subxt-lightclient?/web", - "subxt-macro/web", - "instant/wasm-bindgen" -] +web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js", "subxt-lightclient?/web", "subxt-macro/web", "instant/wasm-bindgen"] # Enable this to use the reconnecting rpc client unstable-reconnecting-rpc-client = ["dep:reconnecting-jsonrpsee-ws-client"] @@ -127,7 +115,7 @@ sp-core = { workspace = true } sp-keyring = { workspace = true } sp-runtime = { workspace = true } assert_matches = { workspace = true } -subxt-signer = { path = "../signer" } +# subxt-signer = { path = "../signer" } # Tracing subscriber is useful for light-client examples to ensure that # the `bootNodes` and chain spec are configured correctly. If all is fine, then # the light-client wlll emit INFO logs with diff --git a/subxt/src/blocks/extrinsic_types.rs b/subxt/src/blocks/extrinsic_types.rs index 333ee5bfe8..e01e48381e 100644 --- a/subxt/src/blocks/extrinsic_types.rs +++ b/subxt/src/blocks/extrinsic_types.rs @@ -245,27 +245,27 @@ where // Skip over the address, signature and extra fields. scale_decode::visitor::decode_with_visitor( cursor, - ids.address, + &ids.address, metadata.types(), - scale_decode::visitor::IgnoreVisitor, + scale_decode::visitor::IgnoreVisitor::new(), ) .map_err(scale_decode::Error::from)?; let address_end_idx = bytes.len() - cursor.len(); scale_decode::visitor::decode_with_visitor( cursor, - ids.signature, + &ids.signature, metadata.types(), - scale_decode::visitor::IgnoreVisitor, + scale_decode::visitor::IgnoreVisitor::new(), ) .map_err(scale_decode::Error::from)?; let signature_end_idx = bytes.len() - cursor.len(); scale_decode::visitor::decode_with_visitor( cursor, - ids.extra, + &ids.extra, metadata.types(), - scale_decode::visitor::IgnoreVisitor, + scale_decode::visitor::IgnoreVisitor::new(), ) .map_err(scale_decode::Error::from)?; let extra_end_idx = bytes.len() - cursor.len(); @@ -420,9 +420,7 @@ where /// Decode and provide the extrinsic fields back in the form of a [`scale_value::Composite`] /// type which represents the named or unnamed fields that were present in the extrinsic. - pub fn field_values( - &self, - ) -> Result, Error> { + pub fn field_values(&self) -> Result, Error> { let bytes = &mut self.field_bytes(); let extrinsic_metadata = self.extrinsic_metadata()?; @@ -430,8 +428,8 @@ where .variant .fields .iter() - .map(|f| scale_decode::Field::new(f.ty.id, f.name.as_deref())); - let decoded = >::decode_as_fields( + .map(|f| scale_decode::Field::new(&f.ty.id, f.name.as_deref())); + let decoded = >::decode_as_fields( bytes, &mut fields, self.metadata.types(), @@ -451,7 +449,7 @@ where .variant .fields .iter() - .map(|f| scale_decode::Field::new(f.ty.id, f.name.as_deref())); + .map(|f| scale_decode::Field::new(&f.ty.id, f.name.as_deref())); let decoded = E::decode_as_fields(&mut self.field_bytes(), &mut fields, self.metadata.types())?; Ok(Some(decoded)) @@ -466,7 +464,7 @@ where pub fn as_root_extrinsic(&self) -> Result { let decoded = E::decode_as_type( &mut &self.call_bytes()[..], - self.metadata.outer_enums().call_enum_ty(), + &self.metadata.outer_enums().call_enum_ty(), self.metadata.types(), )?; @@ -651,9 +649,9 @@ impl<'a, T: Config> ExtrinsicSignedExtensions<'a, T> { let cursor = &mut &bytes[byte_start_idx..]; if let Err(err) = scale_decode::visitor::decode_with_visitor( cursor, - ty_id, + &ty_id, metadata.types(), - scale_decode::visitor::IgnoreVisitor, + scale_decode::visitor::IgnoreVisitor::new(), ) .map_err(|e| Error::Decode(e.into())) { @@ -762,7 +760,7 @@ impl<'a, T: Config> ExtrinsicSignedExtension<'a, T> { } fn as_type(&self) -> Result { - let value = E::decode_as_type(&mut &self.bytes[..], self.ty_id, self.metadata.types())?; + let value = E::decode_as_type(&mut &self.bytes[..], &self.ty_id, self.metadata.types())?; Ok(value) } } diff --git a/subxt/src/dynamic.rs b/subxt/src/dynamic.rs index 2801feb683..5004d348eb 100644 --- a/subxt/src/dynamic.rs +++ b/subxt/src/dynamic.rs @@ -17,7 +17,7 @@ pub use scale_value::{At, Value}; /// regarding what type was used to decode each part of it. This implements /// [`crate::metadata::DecodeWithMetadata`], and is used as a return type /// for dynamic requests. -pub type DecodedValue = scale_value::Value; +pub type DecodedValue = scale_value::Value; // Submit dynamic transactions. pub use crate::tx::dynamic as tx; @@ -79,7 +79,7 @@ impl DecodedValueThunk { pub fn as_type(&self) -> Result { T::decode_as_type( &mut &self.scale_bytes[..], - self.type_id, + &self.type_id, self.metadata.types(), ) } diff --git a/subxt/src/error/dispatch_error.rs b/subxt/src/error/dispatch_error.rs index 3f0c54db56..c7049c74a0 100644 --- a/subxt/src/error/dispatch_error.rs +++ b/subxt/src/error/dispatch_error.rs @@ -7,7 +7,8 @@ use crate::metadata::{DecodeWithMetadata, Metadata}; use core::fmt::Debug; -use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType}; +use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType, TypeResolver}; +use scale_info::PortableRegistry; use std::borrow::Cow; use super::{Error, MetadataError}; @@ -209,7 +210,7 @@ impl ModuleError { pub fn as_root_error(&self) -> Result { let decoded = E::decode_as_type( &mut &self.bytes[..], - self.metadata.outer_enums().error_enum_ty(), + &self.metadata.outer_enums().error_enum_ty(), self.metadata.types(), )?; @@ -266,19 +267,22 @@ impl DispatchError { impl scale_decode::Visitor for DecodedModuleErrorBytesVisitor { type Error = scale_decode::Error; type Value<'scale, 'info> = DecodedModuleErrorBytes; + type TypeResolver = PortableRegistry; + fn unchecked_decode_as_type<'scale, 'info>( self, input: &mut &'scale [u8], - _type_id: scale_decode::visitor::TypeId, + _type_id: &u32, _types: &'info scale_info::PortableRegistry, ) -> DecodeAsTypeResult, Self::Error>> { DecodeAsTypeResult::Decoded(Ok(DecodedModuleErrorBytes(input.to_vec()))) } } + impl scale_decode::IntoVisitor for DecodedModuleErrorBytes { - type Visitor = DecodedModuleErrorBytesVisitor; - fn into_visitor() -> Self::Visitor { + type AnyVisitor = DecodedModuleErrorBytesVisitor; + fn into_visitor() -> DecodedModuleErrorBytesVisitor { DecodedModuleErrorBytesVisitor } } diff --git a/subxt/src/events/events_type.rs b/subxt/src/events/events_type.rs index 831268ad00..4cf175fb07 100644 --- a/subxt/src/events/events_type.rs +++ b/subxt/src/events/events_type.rs @@ -228,9 +228,9 @@ impl EventDetails { // Skip over the bytes for this field: scale_decode::visitor::decode_with_visitor( input, - field_metadata.ty.id, + &field_metadata.ty.id, metadata.types(), - scale_decode::visitor::IgnoreVisitor, + scale_decode::visitor::IgnoreVisitor::new(), ) .map_err(scale_decode::Error::from)?; } @@ -321,9 +321,7 @@ impl EventDetails { /// Decode and provide the event fields back in the form of a [`scale_value::Composite`] /// type which represents the named or unnamed fields that were present in the event. - pub fn field_values( - &self, - ) -> Result, Error> { + pub fn field_values(&self) -> Result, Error> { let bytes = &mut self.field_bytes(); let event_metadata = self.event_metadata(); @@ -331,10 +329,10 @@ impl EventDetails { .variant .fields .iter() - .map(|f| scale_decode::Field::new(f.ty.id, f.name.as_deref())); + .map(|f| scale_decode::Field::new(&f.ty.id, f.name.as_deref())); use scale_decode::DecodeAsFields; - let decoded = >::decode_as_fields( + let decoded = >::decode_as_fields( bytes, &mut fields, self.metadata.types(), @@ -352,7 +350,7 @@ impl EventDetails { .variant .fields .iter() - .map(|f| scale_decode::Field::new(f.ty.id, f.name.as_deref())); + .map(|f| scale_decode::Field::new(&f.ty.id, f.name.as_deref())); let decoded = E::decode_as_fields(&mut self.field_bytes(), &mut fields, self.metadata.types())?; Ok(Some(decoded)) @@ -369,7 +367,7 @@ impl EventDetails { let decoded = E::decode_as_type( &mut &bytes[..], - self.metadata.outer_enums().event_enum_ty(), + &self.metadata.outer_enums().event_enum_ty(), self.metadata.types(), )?; diff --git a/subxt/src/tx/mod.rs b/subxt/src/tx/mod.rs index 0bb2d9f3eb..c48cf1382b 100644 --- a/subxt/src/tx/mod.rs +++ b/subxt/src/tx/mod.rs @@ -28,6 +28,6 @@ pub use self::{ PartialExtrinsic, SubmittableExtrinsic, TransactionInvalid, TransactionUnknown, TxClient, ValidationResult, }, - tx_payload::{dynamic, BoxedPayload, DynamicPayload, Payload, TxPayload}, + tx_payload::{dynamic, DynamicPayload, Payload, TxPayload}, tx_progress::{TxInBlock, TxProgress, TxStatus}, }; diff --git a/subxt/src/tx/tx_payload.rs b/subxt/src/tx/tx_payload.rs index ff9c71fd21..c99478f904 100644 --- a/subxt/src/tx/tx_payload.rs +++ b/subxt/src/tx/tx_payload.rs @@ -65,10 +65,6 @@ pub struct Payload { validation_hash: Option<[u8; 32]>, } -/// A boxed transaction payload. -// Dev Note: Arc used to enable easy cloning (given that we can't have dyn Clone). -pub type BoxedPayload = Payload>; - /// The type of a payload typically used for dynamic transaction payloads. pub type DynamicPayload = Payload>; @@ -104,19 +100,6 @@ impl Payload { } } - /// Box the payload. - pub fn boxed(self) -> BoxedPayload - where - CallData: EncodeAsFields + Send + Sync + 'static, - { - BoxedPayload { - pallet_name: self.pallet_name, - call_name: self.call_name, - call_data: Arc::new(self.call_data), - validation_hash: self.validation_hash, - } - } - /// Do not validate this call prior to submitting it. pub fn unvalidated(self) -> Self { Self { @@ -174,7 +157,7 @@ impl TxPayload for Payload { let mut fields = call .fields .iter() - .map(|f| scale_encode::Field::new(f.ty.id, f.name.as_deref())); + .map(|f| scale_encode::Field::new(&f.ty.id, f.name.as_deref())); self.call_data .encode_as_fields_to(&mut fields, metadata.types(), out)?; diff --git a/subxt/src/utils/bits.rs b/subxt/src/utils/bits.rs index ed830a0dea..b8a4c7d08b 100644 --- a/subxt/src/utils/bits.rs +++ b/subxt/src/utils/bits.rs @@ -9,7 +9,8 @@ use scale_bits::{ scale::format::{Format, OrderFormat, StoreFormat}, Bits, }; -use scale_decode::IntoVisitor; +use scale_decode::{IntoVisitor, TypeResolver}; +use scale_info::PortableRegistry; use std::marker::PhantomData; /// Associates `bitvec::store::BitStore` trait with corresponding, type-erased `scale_bits::StoreFormat` enum. @@ -144,45 +145,43 @@ impl codec::Encode for DecodedBits(std::marker::PhantomData<(S, O)>); -impl scale_decode::Visitor for DecodedBitsVisitor { +pub struct DecodedBitsVisitor(std::marker::PhantomData<(S, O, R)>); + +impl scale_decode::Visitor for DecodedBitsVisitor { type Value<'scale, 'info> = DecodedBits; type Error = scale_decode::Error; + type TypeResolver = R; fn unchecked_decode_as_type<'scale, 'info>( self, input: &mut &'scale [u8], - type_id: scale_decode::visitor::TypeId, - types: &'info scale_info::PortableRegistry, + type_id: &R::TypeId, + types: &'info R, ) -> scale_decode::visitor::DecodeAsTypeResult< Self, Result, Self::Error>, > { - let res = scale_decode::visitor::decode_with_visitor( - input, - type_id.0, - types, - Bits::into_visitor(), - ) - .map(|bits| DecodedBits { - bits, - _marker: PhantomData, - }); + let res = + scale_decode::visitor::decode_with_visitor(input, type_id, types, Bits::into_visitor()) + .map(|bits| DecodedBits { + bits, + _marker: PhantomData, + }); scale_decode::visitor::DecodeAsTypeResult::Decoded(res) } } impl scale_decode::IntoVisitor for DecodedBits { - type Visitor = DecodedBitsVisitor; - fn into_visitor() -> Self::Visitor { + type AnyVisitor = DecodedBitsVisitor; + fn into_visitor() -> DecodedBitsVisitor { DecodedBitsVisitor(PhantomData) } } impl scale_encode::EncodeAsType for DecodedBits { - fn encode_as_type_to( + fn encode_as_type_to( &self, - type_id: u32, - types: &scale_info::PortableRegistry, + type_id: &R::TypeId, + types: &R, out: &mut Vec, ) -> Result<(), scale_encode::Error> { self.bits.encode_as_type_to(type_id, types, out) diff --git a/subxt/src/utils/static_type.rs b/subxt/src/utils/static_type.rs index 2d13e61eba..175390b8ff 100644 --- a/subxt/src/utils/static_type.rs +++ b/subxt/src/utils/static_type.rs @@ -3,8 +3,9 @@ // see LICENSE for license details. use codec::{Decode, Encode}; -use scale_decode::{visitor::DecodeAsTypeResult, IntoVisitor, Visitor}; +use scale_decode::{visitor::DecodeAsTypeResult, IntoVisitor, TypeResolver, Visitor}; use scale_encode::EncodeAsType; +use scale_info::PortableRegistry; /// If the type inside this implements [`Encode`], this will implement [`scale_encode::EncodeAsType`]. /// If the type inside this implements [`Decode`], this will implement [`scale_decode::DecodeAsType`]. @@ -18,10 +19,10 @@ use scale_encode::EncodeAsType; pub struct Static(pub T); impl EncodeAsType for Static { - fn encode_as_type_to( + fn encode_as_type_to( &self, - _type_id: u32, - _types: &scale_decode::PortableRegistry, + _type_id: &R::TypeId, + _types: &R, out: &mut Vec, ) -> Result<(), scale_encode::Error> { self.0.encode_to(out); @@ -29,17 +30,18 @@ impl EncodeAsType for Static { } } -pub struct StaticDecodeAsTypeVisitor(std::marker::PhantomData); +pub struct StaticDecodeAsTypeVisitor(std::marker::PhantomData<(T, R)>); -impl Visitor for StaticDecodeAsTypeVisitor { +impl Visitor for StaticDecodeAsTypeVisitor { type Value<'scale, 'info> = Static; type Error = scale_decode::Error; + type TypeResolver = R; fn unchecked_decode_as_type<'scale, 'info>( self, input: &mut &'scale [u8], - _type_id: scale_decode::visitor::TypeId, - _types: &'info scale_info::PortableRegistry, + _type_id: &R::TypeId, + _types: &'info R, ) -> DecodeAsTypeResult, Self::Error>> { use scale_decode::{visitor::DecodeError, Error}; let decoded = T::decode(input) @@ -50,8 +52,8 @@ impl Visitor for StaticDecodeAsTypeVisitor { } impl IntoVisitor for Static { - type Visitor = StaticDecodeAsTypeVisitor; - fn into_visitor() -> Self::Visitor { + type AnyVisitor = StaticDecodeAsTypeVisitor; + fn into_visitor() -> StaticDecodeAsTypeVisitor { StaticDecodeAsTypeVisitor(std::marker::PhantomData) } } diff --git a/subxt/src/utils/unchecked_extrinsic.rs b/subxt/src/utils/unchecked_extrinsic.rs index 882b490bed..e33f1b7b61 100644 --- a/subxt/src/utils/unchecked_extrinsic.rs +++ b/subxt/src/utils/unchecked_extrinsic.rs @@ -12,7 +12,8 @@ use std::marker::PhantomData; use codec::{Decode, Encode}; -use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType, IntoVisitor, Visitor}; +use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType, IntoVisitor, TypeResolver, Visitor}; +use scale_info::PortableRegistry; use super::{Encoded, Static}; @@ -52,10 +53,10 @@ impl Decode impl scale_encode::EncodeAsType for UncheckedExtrinsic { - fn encode_as_type_to( + fn encode_as_type_to( &self, - type_id: u32, - types: &scale_info::PortableRegistry, + type_id: &R::TypeId, + types: &R, out: &mut Vec, ) -> Result<(), scale_encode::Error> { self.0.encode_as_type_to(type_id, types, out) @@ -78,32 +79,35 @@ impl From( - PhantomData<(Address, Call, Signature, Extra)>, +pub struct UncheckedExtrinsicDecodeAsTypeVisitor( + PhantomData<(Address, Call, Signature, Extra, R)>, ); -impl Visitor - for UncheckedExtrinsicDecodeAsTypeVisitor +impl Visitor + for UncheckedExtrinsicDecodeAsTypeVisitor { type Value<'scale, 'info> = UncheckedExtrinsic; type Error = scale_decode::Error; + type TypeResolver = R; fn unchecked_decode_as_type<'scale, 'info>( self, input: &mut &'scale [u8], - type_id: scale_decode::visitor::TypeId, - types: &'info scale_info::PortableRegistry, + type_id: &R::TypeId, + types: &'info R, ) -> DecodeAsTypeResult, Self::Error>> { - DecodeAsTypeResult::Decoded(Self::Value::decode_as_type(input, type_id.0, types)) + DecodeAsTypeResult::Decoded(Self::Value::decode_as_type(input, type_id, types)) } } impl IntoVisitor for UncheckedExtrinsic { - type Visitor = UncheckedExtrinsicDecodeAsTypeVisitor; + type AnyVisitor = + UncheckedExtrinsicDecodeAsTypeVisitor; - fn into_visitor() -> Self::Visitor { + fn into_visitor( + ) -> UncheckedExtrinsicDecodeAsTypeVisitor { UncheckedExtrinsicDecodeAsTypeVisitor(PhantomData) } } diff --git a/subxt/src/utils/wrapper_opaque.rs b/subxt/src/utils/wrapper_opaque.rs index 9257405715..4689c419af 100644 --- a/subxt/src/utils/wrapper_opaque.rs +++ b/subxt/src/utils/wrapper_opaque.rs @@ -5,8 +5,9 @@ use super::PhantomDataSendSync; use codec::{Compact, Decode, DecodeAll, Encode}; use derivative::Derivative; -use scale_decode::{IntoVisitor, Visitor}; +use scale_decode::{ext::scale_type_resolver::visitor, IntoVisitor, TypeResolver, Visitor}; use scale_encode::EncodeAsType; +use scale_info::PortableRegistry; /// A wrapper for any type `T` which implement encode/decode in a way compatible with `Vec`. /// [`WrapperKeepOpaque`] stores the type only in its opaque format, aka as a `Vec`. To @@ -74,23 +75,33 @@ impl WrapperKeepOpaque { } impl EncodeAsType for WrapperKeepOpaque { - fn encode_as_type_to( + fn encode_as_type_to( &self, - type_id: u32, - types: &scale_info::PortableRegistry, + type_id: &R::TypeId, + types: &R, out: &mut Vec, ) -> Result<(), scale_encode::Error> { use scale_encode::error::{Error, ErrorKind, Kind}; + let visitor = visitor::new(out, |_, _| { + Err(Error::new(ErrorKind::WrongShape { + actual: Kind::Struct, + expected_id: format!("{:?}", type_id), + })) + }) + .visit_composite(|| {}); + + types.resolve_type(type_id, visitor); + let Some(ty) = types.resolve(type_id) else { - return Err(Error::new(ErrorKind::TypeNotFound(type_id))); + return; }; // Do a basic check that the target shape lines up. let scale_info::TypeDef::Composite(_) = &ty.type_def else { return Err(Error::new(ErrorKind::WrongShape { actual: Kind::Struct, - expected: type_id, + expected_id: format!("{:?}", type_id), })); }; @@ -98,7 +109,7 @@ impl EncodeAsType for WrapperKeepOpaque { if ty.path.ident().as_deref() != Some("WrapperKeepOpaque") { return Err(Error::new(ErrorKind::WrongShape { actual: Kind::Struct, - expected: type_id, + expected_id: format!("{:?}", type_id), })); } @@ -108,15 +119,16 @@ impl EncodeAsType for WrapperKeepOpaque { } } -pub struct WrapperKeepOpaqueVisitor(std::marker::PhantomData); -impl Visitor for WrapperKeepOpaqueVisitor { +pub struct WrapperKeepOpaqueVisitor(std::marker::PhantomData<(T, R)>); +impl Visitor for WrapperKeepOpaqueVisitor { type Value<'scale, 'info> = WrapperKeepOpaque; type Error = scale_decode::Error; + type TypeResolver = R; fn visit_composite<'scale, 'info>( self, - value: &mut scale_decode::visitor::types::Composite<'scale, 'info>, - _type_id: scale_decode::visitor::TypeId, + value: &mut scale_decode::visitor::types::Composite<'scale, 'info, R>, + _type_id: &R::TypeId, ) -> Result, Self::Error> { use scale_decode::error::{Error, ErrorKind}; @@ -151,8 +163,8 @@ impl Visitor for WrapperKeepOpaqueVisitor { } impl IntoVisitor for WrapperKeepOpaque { - type Visitor = WrapperKeepOpaqueVisitor; - fn into_visitor() -> Self::Visitor { + type AnyVisitor = WrapperKeepOpaqueVisitor; + fn into_visitor() -> WrapperKeepOpaqueVisitor { WrapperKeepOpaqueVisitor(std::marker::PhantomData) } } @@ -205,7 +217,7 @@ mod test { let (type_id, types) = make_type::(); let scale_codec_encoded = t.encode(); - let encode_as_type_encoded = t.encode_as_type(type_id, &types).unwrap(); + let encode_as_type_encoded = t.encode_as_type(&type_id, &types).unwrap(); assert_eq!( scale_codec_encoded, encode_as_type_encoded, @@ -213,7 +225,7 @@ mod test { ); let decode_as_type_bytes = &mut &*scale_codec_encoded; - let decoded_as_type = T::decode_as_type(decode_as_type_bytes, type_id, &types) + let decoded_as_type = T::decode_as_type(decode_as_type_bytes, &type_id, &types) .expect("decode-as-type decodes"); let decode_scale_codec_bytes = &mut &*scale_codec_encoded; From 75caf569f6452e6e6ec51cad497ae030bc6e43e0 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Thu, 29 Feb 2024 17:32:25 +0100 Subject: [PATCH 2/8] first iteration of updating --- Cargo.lock | 87 ++++--------------- Cargo.toml | 4 +- cli/src/commands/explore/pallets/constants.rs | 2 +- cli/src/commands/explore/pallets/storage.rs | 2 +- cli/src/commands/explore/runtime_apis/mod.rs | 5 +- subxt/src/blocks/extrinsic_types.rs | 12 ++- subxt/src/dynamic.rs | 7 +- subxt/src/error/dispatch_error.rs | 18 ++-- subxt/src/events/events_type.rs | 7 +- subxt/src/metadata/decode_encode_traits.rs | 4 +- subxt/src/runtime_api/runtime_payload.rs | 2 +- subxt/src/utils/wrapper_opaque.rs | 42 +++------ 12 files changed, 59 insertions(+), 133 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4205c4e4fe..4cfff6e44b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3469,17 +3469,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scale-bits" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "036575c29af9b6e4866ffb7fa055dbf623fe7a9cc159b33786de6013a6969d89" -dependencies = [ - "parity-scale-codec", - "scale-info", - "serde", -] - [[package]] name = "scale-bits" version = "0.5.0" @@ -3492,19 +3481,6 @@ dependencies = [ "serde", ] -[[package]] -name = "scale-decode" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7caaf753f8ed1ab4752c6afb20174f03598c664724e0e32628e161c21000ff76" -dependencies = [ - "derive_more", - "parity-scale-codec", - "scale-bits 0.4.0", - "scale-info", - "smallvec", -] - [[package]] name = "scale-decode" version = "0.11.1" @@ -3514,7 +3490,7 @@ dependencies = [ "derive_more", "parity-scale-codec", "primitive-types", - "scale-bits 0.5.0", + "scale-bits", "scale-decode-derive", "scale-type-resolver", "smallvec", @@ -3532,19 +3508,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "scale-encode" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d70cb4b29360105483fac1ed567ff95d65224a14dd275b6303ed0a654c78de5" -dependencies = [ - "derive_more", - "parity-scale-codec", - "scale-bits 0.4.0", - "scale-info", - "smallvec", -] - [[package]] name = "scale-encode" version = "0.6.0" @@ -3554,7 +3517,7 @@ dependencies = [ "derive_more", "parity-scale-codec", "primitive-types", - "scale-bits 0.5.0", + "scale-bits", "scale-encode-derive", "scale-type-resolver", "smallvec", @@ -3611,9 +3574,9 @@ dependencies = [ [[package]] name = "scale-typegen" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00860983481ac590ac87972062909bef0d6a658013b592ccc0f2feb272feab11" +checksum = "7e986e3a75a88c8e354c6fed3dfa0db1b2a99c5ae26cce28db50330d4c99b3fa" dependencies = [ "proc-macro2", "quote", @@ -3624,9 +3587,9 @@ dependencies = [ [[package]] name = "scale-typegen-description" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae69c1dfd81e9859a5fb42c1b560369e6ed82d2c5b5cb4cac3bba1962a73f017" +checksum = "91d6b7b4e0a9dec3fcae98c17ccf85b8dbee51156c81e0d66109159c432cf262" dependencies = [ "anyhow", "peekmore", @@ -3636,30 +3599,10 @@ dependencies = [ "rand_chacha", "scale-info", "scale-typegen", - "scale-value 0.13.0", + "scale-value", "smallvec", ] -[[package]] -name = "scale-value" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58223c7691bf0bd46b43c9aea6f0472d1067f378d574180232358d7c6e0a8089" -dependencies = [ - "base58", - "blake2", - "derive_more", - "either", - "frame-metadata 15.1.0", - "parity-scale-codec", - "scale-bits 0.4.0", - "scale-decode 0.10.0", - "scale-encode 0.5.0", - "scale-info", - "serde", - "yap", -] - [[package]] name = "scale-value" version = "0.14.0" @@ -3672,9 +3615,9 @@ dependencies = [ "either", "frame-metadata 15.1.0", "parity-scale-codec", - "scale-bits 0.5.0", - "scale-decode 0.11.1", - "scale-encode 0.6.0", + "scale-bits", + "scale-decode", + "scale-encode", "scale-info", "scale-type-resolver", "serde", @@ -4585,11 +4528,11 @@ dependencies = [ "parity-scale-codec", "primitive-types", "reconnecting-jsonrpsee-ws-client", - "scale-bits 0.5.0", - "scale-decode 0.11.1", - "scale-encode 0.6.0", + "scale-bits", + "scale-decode", + "scale-encode", "scale-info", - "scale-value 0.14.0", + "scale-value", "serde", "serde_json", "sp-core", @@ -4624,7 +4567,7 @@ dependencies = [ "quote", "scale-info", "scale-typegen-description", - "scale-value 0.14.0", + "scale-value", "serde", "serde_json", "smoldot", diff --git a/Cargo.toml b/Cargo.toml index 4610db5a2d..149e595d95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,8 +98,8 @@ url = "2.5.0" wabt = "0.10.0" wasm-bindgen-test = "0.3.24" which = "5.0.0" -scale-typegen-description = "0.1.0" -scale-typegen = "0.1.1" +scale-typegen-description = "0.1.2" +scale-typegen = "0.1.2" strip-ansi-escapes = "0.2.0" # Light client support: diff --git a/cli/src/commands/explore/pallets/constants.rs b/cli/src/commands/explore/pallets/constants.rs index dd5e5faddc..77b0e3ce08 100644 --- a/cli/src/commands/explore/pallets/constants.rs +++ b/cli/src/commands/explore/pallets/constants.rs @@ -65,7 +65,7 @@ pub fn explore_constants( // value let value = - scale_value::scale::decode_as_type(&mut constant.value(), constant.ty(), metadata.types())?; + scale_value::scale::decode_as_type(&mut constant.value(), &constant.ty(), metadata.types())?; let value = format_scale_value(&value).indent(4); writedoc!( diff --git a/cli/src/commands/explore/pallets/storage.rs b/cli/src/commands/explore/pallets/storage.rs index 0c932c8f1a..543406bd57 100644 --- a/cli/src/commands/explore/pallets/storage.rs +++ b/cli/src/commands/explore/pallets/storage.rs @@ -169,7 +169,7 @@ pub async fn explore_storage( {value_str} "}?; - let key_bytes = value.encode_as_type(type_id, metadata.types())?; + let key_bytes = value.encode_as_type(&type_id, metadata.types())?; let bytes_composite = Value::from_bytes(key_bytes); vec![bytes_composite] } diff --git a/cli/src/commands/explore/runtime_apis/mod.rs b/cli/src/commands/explore/runtime_apis/mod.rs index cdd5681e26..e3fed9ac01 100644 --- a/cli/src/commands/explore/runtime_apis/mod.rs +++ b/cli/src/commands/explore/runtime_apis/mod.rs @@ -161,9 +161,8 @@ pub async fn run<'a>( {value_str} "}?; // encode, then decode. This ensures that the scale value is of the correct shape for the param: - let bytes = value.encode_as_type(ty.ty, metadata.types())?; - let value = Value::decode_as_type(&mut &bytes[..], ty.ty, metadata.types())? - .map_context(|_| ()); + let bytes = value.encode_as_type(&ty.ty, metadata.types())?; + let value = Value::decode_as_type(&mut &bytes[..], &ty.ty, metadata.types())?; Ok(value) }) .collect::>>()?; diff --git a/subxt/src/blocks/extrinsic_types.rs b/subxt/src/blocks/extrinsic_types.rs index e01e48381e..6480a03e2b 100644 --- a/subxt/src/blocks/extrinsic_types.rs +++ b/subxt/src/blocks/extrinsic_types.rs @@ -420,7 +420,7 @@ where /// Decode and provide the extrinsic fields back in the form of a [`scale_value::Composite`] /// type which represents the named or unnamed fields that were present in the extrinsic. - pub fn field_values(&self) -> Result, Error> { + pub fn field_values(&self) -> Result, Error> { let bytes = &mut self.field_bytes(); let extrinsic_metadata = self.extrinsic_metadata()?; @@ -429,7 +429,7 @@ where .fields .iter() .map(|f| scale_decode::Field::new(&f.ty.id, f.name.as_deref())); - let decoded = >::decode_as_fields( + let decoded = >::decode_as_fields( bytes, &mut fields, self.metadata.types(), @@ -746,7 +746,13 @@ impl<'a, T: Config> ExtrinsicSignedExtension<'a, T> { /// Signed Extension as a [`scale_value::Value`] pub fn value(&self) -> Result { - self.as_type() + let value = scale_value::scale::decode_as_type( + &mut &self.bytes[..], + &self.ty_id, + self.metadata.types(), + ) + .map_err(|e| Error::Decode(e.into()))?; + Ok(value) } /// Decodes the bytes of this Signed Extension into its associated `Decoded` type. diff --git a/subxt/src/dynamic.rs b/subxt/src/dynamic.rs index 5004d348eb..49c05080c5 100644 --- a/subxt/src/dynamic.rs +++ b/subxt/src/dynamic.rs @@ -68,11 +68,12 @@ impl DecodedValueThunk { } /// Decode the SCALE encoded storage entry into a dynamic [`DecodedValue`] type. pub fn to_value(&self) -> Result { - let val = DecodedValue::decode_as_type( + let val = scale_value::scale::decode_as_type( &mut &*self.scale_bytes, - self.type_id, + &self.type_id, self.metadata.types(), - )?; + ) + .map_err(|e| Error::Decode(e.into()))?; Ok(val) } /// decode the `DecodedValueThunk` into a concrete type. diff --git a/subxt/src/error/dispatch_error.rs b/subxt/src/error/dispatch_error.rs index c7049c74a0..e42efb6cda 100644 --- a/subxt/src/error/dispatch_error.rs +++ b/subxt/src/error/dispatch_error.rs @@ -9,7 +9,7 @@ use crate::metadata::{DecodeWithMetadata, Metadata}; use core::fmt::Debug; use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType, TypeResolver}; use scale_info::PortableRegistry; -use std::borrow::Cow; +use std::{borrow::Cow, marker::PhantomData}; use super::{Error, MetadataError}; @@ -263,17 +263,17 @@ impl DispatchError { // a legacy format of 2 bytes, or a newer format of 5 bytes. So, just grab the bytes // out when decoding to manually work with them. struct DecodedModuleErrorBytes(Vec); - struct DecodedModuleErrorBytesVisitor; - impl scale_decode::Visitor for DecodedModuleErrorBytesVisitor { + struct DecodedModuleErrorBytesVisitor(PhantomData); + impl scale_decode::Visitor for DecodedModuleErrorBytesVisitor { type Error = scale_decode::Error; type Value<'scale, 'info> = DecodedModuleErrorBytes; - type TypeResolver = PortableRegistry; + type TypeResolver = R; fn unchecked_decode_as_type<'scale, 'info>( self, input: &mut &'scale [u8], - _type_id: &u32, - _types: &'info scale_info::PortableRegistry, + _type_id: &R::TypeId, + _types: &'info R, ) -> DecodeAsTypeResult, Self::Error>> { DecodeAsTypeResult::Decoded(Ok(DecodedModuleErrorBytes(input.to_vec()))) @@ -281,9 +281,9 @@ impl DispatchError { } impl scale_decode::IntoVisitor for DecodedModuleErrorBytes { - type AnyVisitor = DecodedModuleErrorBytesVisitor; - fn into_visitor() -> DecodedModuleErrorBytesVisitor { - DecodedModuleErrorBytesVisitor + type AnyVisitor = DecodedModuleErrorBytesVisitor; + fn into_visitor() -> DecodedModuleErrorBytesVisitor { + DecodedModuleErrorBytesVisitor(PhantomData) } } diff --git a/subxt/src/events/events_type.rs b/subxt/src/events/events_type.rs index 4cf175fb07..9944fd936f 100644 --- a/subxt/src/events/events_type.rs +++ b/subxt/src/events/events_type.rs @@ -14,7 +14,7 @@ use crate::{ }; use codec::{Compact, Decode}; use derivative::Derivative; -use scale_decode::DecodeAsType; +use scale_decode::{DecodeAsFields, DecodeAsType}; use std::sync::Arc; /// A collection of events obtained from a block, bundled with the necessary @@ -321,7 +321,7 @@ impl EventDetails { /// Decode and provide the event fields back in the form of a [`scale_value::Composite`] /// type which represents the named or unnamed fields that were present in the event. - pub fn field_values(&self) -> Result, Error> { + pub fn field_values(&self) -> Result, Error> { let bytes = &mut self.field_bytes(); let event_metadata = self.event_metadata(); @@ -331,8 +331,7 @@ impl EventDetails { .iter() .map(|f| scale_decode::Field::new(&f.ty.id, f.name.as_deref())); - use scale_decode::DecodeAsFields; - let decoded = >::decode_as_fields( + let decoded = scale_value::Composite::<()>::decode_as_fields( bytes, &mut fields, self.metadata.types(), diff --git a/subxt/src/metadata/decode_encode_traits.rs b/subxt/src/metadata/decode_encode_traits.rs index 81dbaea131..8b8d4077fa 100644 --- a/subxt/src/metadata/decode_encode_traits.rs +++ b/subxt/src/metadata/decode_encode_traits.rs @@ -21,7 +21,7 @@ impl DecodeWithMetadata for T { type_id: u32, metadata: &Metadata, ) -> Result { - let val = T::decode_as_type(bytes, type_id, metadata.types())?; + let val = T::decode_as_type(bytes, &type_id, metadata.types())?; Ok(val) } } @@ -45,7 +45,7 @@ impl EncodeWithMetadata for T { metadata: &Metadata, bytes: &mut Vec, ) -> Result<(), Error> { - self.encode_as_type_to(type_id, metadata.types(), bytes)?; + self.encode_as_type_to(&type_id, metadata.types(), bytes)?; Ok(()) } } diff --git a/subxt/src/runtime_api/runtime_payload.rs b/subxt/src/runtime_api/runtime_payload.rs index ff776eb14f..128440b98d 100644 --- a/subxt/src/runtime_api/runtime_payload.rs +++ b/subxt/src/runtime_api/runtime_payload.rs @@ -103,7 +103,7 @@ impl RuntimeApiPayload .ok_or_else(|| MetadataError::RuntimeMethodNotFound((*self.method_name).to_owned()))?; let mut fields = api_method .inputs() - .map(|input| scale_encode::Field::named(input.ty, &input.name)); + .map(|input| scale_encode::Field::named(&input.ty, &input.name)); self.args_data .encode_as_fields_to(&mut fields, metadata.types(), out)?; diff --git a/subxt/src/utils/wrapper_opaque.rs b/subxt/src/utils/wrapper_opaque.rs index 4689c419af..aa77990c95 100644 --- a/subxt/src/utils/wrapper_opaque.rs +++ b/subxt/src/utils/wrapper_opaque.rs @@ -84,38 +84,21 @@ impl EncodeAsType for WrapperKeepOpaque { use scale_encode::error::{Error, ErrorKind, Kind}; let visitor = visitor::new(out, |_, _| { + // Check that the target shape lines up: any other shape but composite it wrong. Err(Error::new(ErrorKind::WrongShape { actual: Kind::Struct, expected_id: format!("{:?}", type_id), })) }) - .visit_composite(|| {}); - - types.resolve_type(type_id, visitor); - - let Some(ty) = types.resolve(type_id) else { - return; - }; - - // Do a basic check that the target shape lines up. - let scale_info::TypeDef::Composite(_) = &ty.type_def else { - return Err(Error::new(ErrorKind::WrongShape { - actual: Kind::Struct, - expected_id: format!("{:?}", type_id), - })); - }; - - // Check that the name also lines up. - if ty.path.ident().as_deref() != Some("WrapperKeepOpaque") { - return Err(Error::new(ErrorKind::WrongShape { - actual: Kind::Struct, - expected_id: format!("{:?}", type_id), - })); - } - - // Just blat the bytes out. - self.data.encode_to(out); - Ok(()) + .visit_composite(|out, fields| { + self.data.encode_to(out); + Ok(()) + }); + + let res = types + .resolve_type(type_id, visitor) + .map_err(|_| Error::new(ErrorKind::TypeNotFound(format!("{:?}", type_id))))?; + res } } @@ -132,11 +115,6 @@ impl Visitor for WrapperKeepOpaqueVisitor { ) -> Result, Self::Error> { use scale_decode::error::{Error, ErrorKind}; - if value.path().ident().as_deref() != Some("WrapperKeepOpaque") { - return Err(Error::custom_str( - "Type to decode is not 'WrapperTypeKeepOpaque'", - )); - } if value.remaining() != 2 { return Err(Error::new(ErrorKind::WrongLength { actual_len: value.remaining(), From 790746815249e688dd4e06ff0a9383b033c50814 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Thu, 29 Feb 2024 17:36:26 +0100 Subject: [PATCH 3/8] fmt and clippy --- Cargo.lock | 1 + cli/src/commands/explore/pallets/constants.rs | 7 +++++-- subxt/Cargo.toml | 20 +++++++++++++++---- subxt/src/error/dispatch_error.rs | 2 +- subxt/src/tx/tx_payload.rs | 2 +- subxt/src/utils/bits.rs | 2 +- subxt/src/utils/static_type.rs | 1 - subxt/src/utils/unchecked_extrinsic.rs | 1 - subxt/src/utils/wrapper_opaque.rs | 8 +++----- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4cfff6e44b..0c18fccb17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4542,6 +4542,7 @@ dependencies = [ "subxt-lightclient", "subxt-macro", "subxt-metadata", + "subxt-signer", "thiserror", "tokio", "tokio-stream", diff --git a/cli/src/commands/explore/pallets/constants.rs b/cli/src/commands/explore/pallets/constants.rs index 77b0e3ce08..a267c401f8 100644 --- a/cli/src/commands/explore/pallets/constants.rs +++ b/cli/src/commands/explore/pallets/constants.rs @@ -64,8 +64,11 @@ pub fn explore_constants( .highlight(); // value - let value = - scale_value::scale::decode_as_type(&mut constant.value(), &constant.ty(), metadata.types())?; + let value = scale_value::scale::decode_as_type( + &mut constant.value(), + &constant.ty(), + metadata.types(), + )?; let value = format_scale_value(&value).indent(4); writedoc!( diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 62b8bd64ab..67c553fa50 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -24,11 +24,23 @@ default = ["jsonrpsee", "native"] # Enable this for native (ie non web/wasm builds). # Exactly 1 of "web" and "native" is expected. -native = ["jsonrpsee?/async-client", "jsonrpsee?/client-ws-transport-native-tls", "subxt-lightclient?/native", "tokio-util"] +native = [ + "jsonrpsee?/async-client", + "jsonrpsee?/client-ws-transport-native-tls", + "subxt-lightclient?/native", + "tokio-util" +] # Enable this for web/wasm builds. # Exactly 1 of "web" and "native" is expected. -web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js", "subxt-lightclient?/web", "subxt-macro/web", "instant/wasm-bindgen"] +web = [ + "jsonrpsee?/async-wasm-client", + "jsonrpsee?/client-web-transport", + "getrandom/js", + "subxt-lightclient?/web", + "subxt-macro/web", + "instant/wasm-bindgen" +] # Enable this to use the reconnecting rpc client unstable-reconnecting-rpc-client = ["dep:reconnecting-jsonrpsee-ws-client"] @@ -115,7 +127,7 @@ sp-core = { workspace = true } sp-keyring = { workspace = true } sp-runtime = { workspace = true } assert_matches = { workspace = true } -# subxt-signer = { path = "../signer" } +subxt-signer = { path = "../signer" } # Tracing subscriber is useful for light-client examples to ensure that # the `bootNodes` and chain spec are configured correctly. If all is fine, then # the light-client wlll emit INFO logs with @@ -142,4 +154,4 @@ features = ["default", "substrate-compat", "unstable-light-client"] rustdoc-args = ["--cfg", "docsrs"] [package.metadata.playground] -features = ["default", "substrate-compat", "unstable-light-client"] +features = ["default", "substrate-compat", "unstable-light-client"] \ No newline at end of file diff --git a/subxt/src/error/dispatch_error.rs b/subxt/src/error/dispatch_error.rs index e42efb6cda..6de0792dc0 100644 --- a/subxt/src/error/dispatch_error.rs +++ b/subxt/src/error/dispatch_error.rs @@ -8,7 +8,7 @@ use crate::metadata::{DecodeWithMetadata, Metadata}; use core::fmt::Debug; use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType, TypeResolver}; -use scale_info::PortableRegistry; + use std::{borrow::Cow, marker::PhantomData}; use super::{Error, MetadataError}; diff --git a/subxt/src/tx/tx_payload.rs b/subxt/src/tx/tx_payload.rs index c99478f904..c2a1dbe65c 100644 --- a/subxt/src/tx/tx_payload.rs +++ b/subxt/src/tx/tx_payload.rs @@ -14,7 +14,7 @@ use codec::Encode; use derivative::Derivative; use scale_encode::EncodeAsFields; use scale_value::{Composite, ValueDef, Variant}; -use std::{borrow::Cow, sync::Arc}; +use std::borrow::Cow; /// This represents a transaction payload that can be submitted /// to a node. diff --git a/subxt/src/utils/bits.rs b/subxt/src/utils/bits.rs index b8a4c7d08b..6c334d701c 100644 --- a/subxt/src/utils/bits.rs +++ b/subxt/src/utils/bits.rs @@ -10,7 +10,7 @@ use scale_bits::{ Bits, }; use scale_decode::{IntoVisitor, TypeResolver}; -use scale_info::PortableRegistry; + use std::marker::PhantomData; /// Associates `bitvec::store::BitStore` trait with corresponding, type-erased `scale_bits::StoreFormat` enum. diff --git a/subxt/src/utils/static_type.rs b/subxt/src/utils/static_type.rs index 175390b8ff..6cf1285f8b 100644 --- a/subxt/src/utils/static_type.rs +++ b/subxt/src/utils/static_type.rs @@ -5,7 +5,6 @@ use codec::{Decode, Encode}; use scale_decode::{visitor::DecodeAsTypeResult, IntoVisitor, TypeResolver, Visitor}; use scale_encode::EncodeAsType; -use scale_info::PortableRegistry; /// If the type inside this implements [`Encode`], this will implement [`scale_encode::EncodeAsType`]. /// If the type inside this implements [`Decode`], this will implement [`scale_decode::DecodeAsType`]. diff --git a/subxt/src/utils/unchecked_extrinsic.rs b/subxt/src/utils/unchecked_extrinsic.rs index e33f1b7b61..14ad39e790 100644 --- a/subxt/src/utils/unchecked_extrinsic.rs +++ b/subxt/src/utils/unchecked_extrinsic.rs @@ -13,7 +13,6 @@ use std::marker::PhantomData; use codec::{Decode, Encode}; use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType, IntoVisitor, TypeResolver, Visitor}; -use scale_info::PortableRegistry; use super::{Encoded, Static}; diff --git a/subxt/src/utils/wrapper_opaque.rs b/subxt/src/utils/wrapper_opaque.rs index aa77990c95..b3ea134ea7 100644 --- a/subxt/src/utils/wrapper_opaque.rs +++ b/subxt/src/utils/wrapper_opaque.rs @@ -7,7 +7,6 @@ use codec::{Compact, Decode, DecodeAll, Encode}; use derivative::Derivative; use scale_decode::{ext::scale_type_resolver::visitor, IntoVisitor, TypeResolver, Visitor}; use scale_encode::EncodeAsType; -use scale_info::PortableRegistry; /// A wrapper for any type `T` which implement encode/decode in a way compatible with `Vec`. /// [`WrapperKeepOpaque`] stores the type only in its opaque format, aka as a `Vec`. To @@ -90,15 +89,14 @@ impl EncodeAsType for WrapperKeepOpaque { expected_id: format!("{:?}", type_id), })) }) - .visit_composite(|out, fields| { + .visit_composite(|out, _fields| { self.data.encode_to(out); Ok(()) }); - let res = types + types .resolve_type(type_id, visitor) - .map_err(|_| Error::new(ErrorKind::TypeNotFound(format!("{:?}", type_id))))?; - res + .map_err(|_| Error::new(ErrorKind::TypeNotFound(format!("{:?}", type_id))))? } } From f07813f60c91cafc2652a4cc95fd102734d1d10d Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Tue, 5 Mar 2024 10:22:26 +0100 Subject: [PATCH 4/8] add Composite decoding via scale value patch --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- subxt/src/blocks/extrinsic_types.rs | 12 ++++-------- subxt/src/dynamic.rs | 3 +-- subxt/src/error/mod.rs | 6 ++++++ subxt/src/events/events_type.rs | 11 ++++------- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 63820c999b..68ca88625b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3605,9 +3605,9 @@ dependencies = [ [[package]] name = "scale-value" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c518ab8d2f3d6625f651409d4d223ebea8517fc41cd9814c1ab892f8f259a5" +checksum = "c07ccfee963104335c971aaf8b7b0e749be8569116322df23f1f75c4ca9e4a28" dependencies = [ "base58", "blake2", diff --git a/Cargo.toml b/Cargo.toml index 149e595d95..48c1a03977 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,7 +81,7 @@ proc-macro2 = "1.0.78" quote = "1.0.35" regex = "1.10.3" scale-info = { version = "2.10.0", default-features = false } -scale-value = "0.14.0" +scale-value = "0.14.1" scale-bits = "0.5.0" scale-decode = "0.11.1" scale-encode = "0.6.0" diff --git a/subxt/src/blocks/extrinsic_types.rs b/subxt/src/blocks/extrinsic_types.rs index 6480a03e2b..32bdb057e9 100644 --- a/subxt/src/blocks/extrinsic_types.rs +++ b/subxt/src/blocks/extrinsic_types.rs @@ -420,7 +420,7 @@ where /// Decode and provide the extrinsic fields back in the form of a [`scale_value::Composite`] /// type which represents the named or unnamed fields that were present in the extrinsic. - pub fn field_values(&self) -> Result, Error> { + pub fn field_values(&self) -> Result, Error> { let bytes = &mut self.field_bytes(); let extrinsic_metadata = self.extrinsic_metadata()?; @@ -429,11 +429,8 @@ where .fields .iter() .map(|f| scale_decode::Field::new(&f.ty.id, f.name.as_deref())); - let decoded = >::decode_as_fields( - bytes, - &mut fields, - self.metadata.types(), - )?; + let decoded = + scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())?; Ok(decoded) } @@ -750,8 +747,7 @@ impl<'a, T: Config> ExtrinsicSignedExtension<'a, T> { &mut &self.bytes[..], &self.ty_id, self.metadata.types(), - ) - .map_err(|e| Error::Decode(e.into()))?; + )?; Ok(value) } diff --git a/subxt/src/dynamic.rs b/subxt/src/dynamic.rs index 49c05080c5..c405450481 100644 --- a/subxt/src/dynamic.rs +++ b/subxt/src/dynamic.rs @@ -72,8 +72,7 @@ impl DecodedValueThunk { &mut &*self.scale_bytes, &self.type_id, self.metadata.types(), - ) - .map_err(|e| Error::Decode(e.into()))?; + )?; Ok(val) } /// decode the `DecodedValueThunk` into a concrete type. diff --git a/subxt/src/error/mod.rs b/subxt/src/error/mod.rs index 41dbc11d31..b4511b1b01 100644 --- a/subxt/src/error/mod.rs +++ b/subxt/src/error/mod.rs @@ -98,6 +98,12 @@ impl From for Error { } } +impl From for Error { + fn from(value: scale_decode::visitor::DecodeError) -> Self { + Error::Decode(value.into()) + } +} + impl Error { /// Checks whether the error was caused by a RPC re-connection. pub fn is_disconnected_will_reconnect(&self) -> bool { diff --git a/subxt/src/events/events_type.rs b/subxt/src/events/events_type.rs index 9944fd936f..6818a84815 100644 --- a/subxt/src/events/events_type.rs +++ b/subxt/src/events/events_type.rs @@ -14,7 +14,7 @@ use crate::{ }; use codec::{Compact, Decode}; use derivative::Derivative; -use scale_decode::{DecodeAsFields, DecodeAsType}; +use scale_decode::DecodeAsType; use std::sync::Arc; /// A collection of events obtained from a block, bundled with the necessary @@ -321,7 +321,7 @@ impl EventDetails { /// Decode and provide the event fields back in the form of a [`scale_value::Composite`] /// type which represents the named or unnamed fields that were present in the event. - pub fn field_values(&self) -> Result, Error> { + pub fn field_values(&self) -> Result, Error> { let bytes = &mut self.field_bytes(); let event_metadata = self.event_metadata(); @@ -331,11 +331,8 @@ impl EventDetails { .iter() .map(|f| scale_decode::Field::new(&f.ty.id, f.name.as_deref())); - let decoded = scale_value::Composite::<()>::decode_as_fields( - bytes, - &mut fields, - self.metadata.types(), - )?; + let decoded = + scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())?; Ok(decoded) } From 3f6fa393c981c55d2fd38b080f2eb2f12757f4d9 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Tue, 5 Mar 2024 17:10:06 +0100 Subject: [PATCH 5/8] bump scale type gen versions --- Cargo.lock | 8 ++-- Cargo.toml | 13 +++++-- examples/wasm-example/Cargo.lock | 65 +++++++++++++++++++------------- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68ca88625b..ae0ebd1d0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3574,9 +3574,9 @@ dependencies = [ [[package]] name = "scale-typegen" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e986e3a75a88c8e354c6fed3dfa0db1b2a99c5ae26cce28db50330d4c99b3fa" +checksum = "0d6108609f017741c78d35967c7afe4aeaa3999b848282581041428e10d23b63" dependencies = [ "proc-macro2", "quote", @@ -3587,9 +3587,9 @@ dependencies = [ [[package]] name = "scale-typegen-description" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d6b7b4e0a9dec3fcae98c17ccf85b8dbee51156c81e0d66109159c432cf262" +checksum = "479f0b8b0d75cce8d284ace5a9b7f5a12c523c94387c710835695e8b194a17bb" dependencies = [ "anyhow", "peekmore", diff --git a/Cargo.toml b/Cargo.toml index 48c1a03977..caf774bf4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,14 @@ members = [ # We exclude any crates that would depend on non mutually # exclusive feature flags and thus can't compile with the # workspace: -exclude = ["testing/no-std-tests", "testing/wasm-rpc-tests", "testing/wasm-lightclient-tests", "signer/wasm-tests", "examples/wasm-example", "examples/parachain-example"] +exclude = [ + "testing/no-std-tests", + "testing/wasm-rpc-tests", + "testing/wasm-lightclient-tests", + "signer/wasm-tests", + "examples/wasm-example", + "examples/parachain-example" +] resolver = "2" [workspace.package] @@ -98,8 +105,8 @@ url = "2.5.0" wabt = "0.10.0" wasm-bindgen-test = "0.3.24" which = "5.0.0" -scale-typegen-description = "0.1.2" -scale-typegen = "0.1.2" +scale-typegen-description = "0.2.0" +scale-typegen = "0.2.0" strip-ansi-escapes = "0.2.0" # Light client support: diff --git a/examples/wasm-example/Cargo.lock b/examples/wasm-example/Cargo.lock index f46412c7b8..a00774f219 100644 --- a/examples/wasm-example/Cargo.lock +++ b/examples/wasm-example/Cargo.lock @@ -476,12 +476,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.6" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c376d08ea6aa96aafe61237c7200d1241cb177b7d3a542d791f2d118e9cbb955" +checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" dependencies = [ - "darling_core 0.20.6", - "darling_macro 0.20.6", + "darling_core 0.20.8", + "darling_macro 0.20.8", ] [[package]] @@ -500,9 +500,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.6" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33043dcd19068b8192064c704b3f83eb464f91f1ff527b44a4e2b08d9cdb8855" +checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" dependencies = [ "fnv", "ident_case", @@ -525,11 +525,11 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.6" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" +checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ - "darling_core 0.20.6", + "darling_core 0.20.8", "quote", "syn 2.0.48", ] @@ -2084,38 +2084,38 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "scale-bits" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "036575c29af9b6e4866ffb7fa055dbf623fe7a9cc159b33786de6013a6969d89" +checksum = "662d10dcd57b1c2a3c41c9cf68f71fb09747ada1ea932ad961aca7e2ca28315f" dependencies = [ "parity-scale-codec", "scale-info", + "scale-type-resolver", "serde", ] [[package]] name = "scale-decode" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7caaf753f8ed1ab4752c6afb20174f03598c664724e0e32628e161c21000ff76" +checksum = "afc79ba56a1c742f5aeeed1f1801f3edf51f7e818f0a54582cac6f131364ea7b" dependencies = [ "derive_more", "parity-scale-codec", "primitive-types", "scale-bits", "scale-decode-derive", - "scale-info", + "scale-type-resolver", "smallvec", ] [[package]] name = "scale-decode-derive" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3475108a1b62c7efd1b5c65974f30109a598b2f45f23c9ae030acb9686966db" +checksum = "5398fdb3c7bea3cb419bac4983aadacae93fe1a7b5f693f4ebd98c3821aad7a5" dependencies = [ "darling 0.14.4", - "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -2123,24 +2123,24 @@ dependencies = [ [[package]] name = "scale-encode" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d70cb4b29360105483fac1ed567ff95d65224a14dd275b6303ed0a654c78de5" +checksum = "628800925a33794fb5387781b883b5e14d130fece9af5a63613867b8de07c5c7" dependencies = [ "derive_more", "parity-scale-codec", "primitive-types", "scale-bits", "scale-encode-derive", - "scale-info", + "scale-type-resolver", "smallvec", ] [[package]] name = "scale-encode-derive" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "995491f110efdc6bea96d6a746140e32bfceb4ea47510750a5467295a4707a25" +checksum = "7a304e1af7cdfbe7a24e08b012721456cc8cecdedadc14b3d10513eada63233c" dependencies = [ "darling 0.14.4", "proc-macro-crate 1.3.1", @@ -2176,10 +2176,20 @@ dependencies = [ ] [[package]] -name = "scale-typegen" +name = "scale-type-resolver" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00860983481ac590ac87972062909bef0d6a658013b592ccc0f2feb272feab11" +checksum = "10b800069bfd43374e0f96f653e0d46882a2cb16d6d961ac43bea80f26c76843" +dependencies = [ + "scale-info", + "smallvec", +] + +[[package]] +name = "scale-typegen" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6108609f017741c78d35967c7afe4aeaa3999b848282581041428e10d23b63" dependencies = [ "proc-macro2", "quote", @@ -2190,9 +2200,9 @@ dependencies = [ [[package]] name = "scale-value" -version = "0.13.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58223c7691bf0bd46b43c9aea6f0472d1067f378d574180232358d7c6e0a8089" +checksum = "c07ccfee963104335c971aaf8b7b0e749be8569116322df23f1f75c4ca9e4a28" dependencies = [ "base58", "blake2", @@ -2204,6 +2214,7 @@ dependencies = [ "scale-decode", "scale-encode", "scale-info", + "scale-type-resolver", "serde", "yap", ] @@ -2659,7 +2670,7 @@ dependencies = [ name = "subxt-macro" version = "0.34.0" dependencies = [ - "darling 0.20.6", + "darling 0.20.8", "parity-scale-codec", "proc-macro-error", "quote", From 400f3792ad045b8eab4752f528975e365f0c008a Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Thu, 7 Mar 2024 14:42:32 +0100 Subject: [PATCH 6/8] fix decoding with new scale decode --- subxt/src/storage/storage_key.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/subxt/src/storage/storage_key.rs b/subxt/src/storage/storage_key.rs index a8bffab329..71ecafde9d 100644 --- a/subxt/src/storage/storage_key.rs +++ b/subxt/src/storage/storage_key.rs @@ -2,7 +2,7 @@ use crate::{ error::{Error, MetadataError, StorageAddressError}, utils::{Encoded, Static}, }; -use scale_decode::{visitor::IgnoreVisitor, DecodeAsType}; +use scale_decode::visitor::IgnoreVisitor; use scale_encode::EncodeAsType; use scale_info::{PortableRegistry, TypeDef}; use scale_value::Value; @@ -203,7 +203,7 @@ impl StorageKey for StaticStorageKey { types: &PortableRegistry, ) -> Result<(), Error> { let (hasher, ty_id) = hashers.next_or_err()?; - let encoded_value = self.bytes.encode_as_type(ty_id, types)?; + let encoded_value = self.bytes.encode_as_type(&ty_id, types)?; hash_bytes(&encoded_value, hasher, bytes); Ok(()) } @@ -242,7 +242,7 @@ impl StorageKey for Vec { ) -> Result<(), Error> { for value in self.iter() { let (hasher, ty_id) = hashers.next_or_err()?; - let encoded_value = value.encode_as_type(ty_id, types)?; + let encoded_value = value.encode_as_type(&ty_id, types)?; hash_bytes(&encoded_value, hasher, bytes); } Ok(()) @@ -260,7 +260,8 @@ impl StorageKey for Vec { for (hasher, ty_id) in hashers.by_ref() { match consume_hash_returning_key_bytes(bytes, hasher, ty_id, types)? { Some(value_bytes) => { - let value = Value::decode_as_type(&mut &*value_bytes, ty_id, types)?; + let value = + scale_value::scale::decode_as_type(&mut &*value_bytes, &ty_id, types)?; result.push(value.remove_context()); } None => { @@ -296,8 +297,13 @@ fn consume_hash_returning_key_bytes<'a>( // Now, find the bytes representing the key, consuming them. let before_key = *bytes; if hasher.ends_with_key() { - scale_decode::visitor::decode_with_visitor(bytes, ty_id, types, IgnoreVisitor) - .map_err(|err| Error::Decode(err.into()))?; + scale_decode::visitor::decode_with_visitor( + bytes, + &ty_id, + types, + IgnoreVisitor::::new(), + ) + .map_err(|err| Error::Decode(err.into()))?; // Return the key bytes, having advanced the input cursor past them. let key_bytes = &before_key[..before_key.len() - bytes.len()]; From 98439555b7dedb67b063acde4d8a7fc38d4edb92 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Wed, 13 Mar 2024 13:37:27 +0100 Subject: [PATCH 7/8] fix js-sys versions --- examples/wasm-example/Cargo.lock | 36 ++++++++++++++++---------------- examples/wasm-example/Cargo.toml | 4 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/wasm-example/Cargo.lock b/examples/wasm-example/Cargo.lock index a00774f219..69aa797f9a 100644 --- a/examples/wasm-example/Cargo.lock +++ b/examples/wasm-example/Cargo.lock @@ -1329,9 +1329,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -1713,18 +1713,18 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pin-project" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", @@ -3022,9 +3022,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3032,9 +3032,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", @@ -3059,9 +3059,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3069,9 +3069,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", @@ -3082,9 +3082,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-example" @@ -3146,9 +3146,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.67" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/examples/wasm-example/Cargo.toml b/examples/wasm-example/Cargo.toml index 80d3be6ce7..6aaf175b54 100644 --- a/examples/wasm-example/Cargo.toml +++ b/examples/wasm-example/Cargo.toml @@ -9,10 +9,10 @@ edition = "2021" futures = "0.3.28" subxt = { path = "../../subxt", default-features = false, features = ["jsonrpsee", "web"], target_arch = "wasm32" } yew = { version = "0.20.0", features = ["csr"] } -web-sys = "0.3.63" +web-sys = "0.3.69" hex = "0.4.3" yew-router = "0.17.0" -js-sys = "0.3.63" +js-sys = "0.3.69" wasm-bindgen = "0.2.86" wasm-bindgen-futures = "0.4.36" anyhow = "1.0.71" From fde00e51891f40ff5ce78eb760d7ac3d5e99b286 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Wed, 13 Mar 2024 14:21:41 +0100 Subject: [PATCH 8/8] add nit comments --- subxt/src/utils/wrapper_opaque.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subxt/src/utils/wrapper_opaque.rs b/subxt/src/utils/wrapper_opaque.rs index b3ea134ea7..7888dee47f 100644 --- a/subxt/src/utils/wrapper_opaque.rs +++ b/subxt/src/utils/wrapper_opaque.rs @@ -83,7 +83,7 @@ impl EncodeAsType for WrapperKeepOpaque { use scale_encode::error::{Error, ErrorKind, Kind}; let visitor = visitor::new(out, |_, _| { - // Check that the target shape lines up: any other shape but composite it wrong. + // Check that the target shape lines up: any other shape but the composite is wrong. Err(Error::new(ErrorKind::WrongShape { actual: Kind::Struct, expected_id: format!("{:?}", type_id), @@ -113,6 +113,8 @@ impl Visitor for WrapperKeepOpaqueVisitor { ) -> Result, Self::Error> { use scale_decode::error::{Error, ErrorKind}; + // TODO: When `scale-type-resolver` [provides struct names](https://github.com/paritytech/scale-type-resolver/issues/4), check that this struct name is `WrapperKeepOpaque` + if value.remaining() != 2 { return Err(Error::new(ErrorKind::WrongLength { actual_len: value.remaining(),