Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deps to use scale-type-resolver 0.2 #1565

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
359 changes: 174 additions & 185 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ proc-macro2 = "1.0.81"
quote = "1.0.36"
regex = { version = "1.10.4", default-features = false }
scale-info = { version = "2.11.0", default-features = false }
scale-value = { version = "0.14.1", default-features = false }
scale-bits = { version = "0.5.0", default-features = false }
scale-decode = { version = "0.11.1", default-features = false }
scale-encode = { version = "0.6.0", default-features = false }
scale-typegen = "0.4.2"
scale-typegen-description = "0.4.3"
scale-value = { version = "0.15.0", default-features = false }
scale-bits = { version = "0.6.0", default-features = false }
scale-decode = { version = "0.12.0", default-features = false }
scale-encode = { version = "0.7.0", default-features = false }
scale-typegen = "0.5.0"
scale-typegen-description = "0.5.0"
serde = { version = "1.0.199", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.116", default-features = false }
syn = { version = "2.0.15", features = ["full", "extra-traits"] }
Expand Down
11 changes: 4 additions & 7 deletions cli/src/commands/explore/pallets/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn explore_constants(
Usage:
subxt explore pallet {pallet_name} constants <CONSTANT>
explore a specific constant of this pallet

{constants}
"}
};
Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn explore_constants(
writedoc! {output, "
Description:
{doc_string}

"}?;
}

Expand All @@ -64,11 +64,8 @@ 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!(
Expand Down
10 changes: 5 additions & 5 deletions cli/src/commands/explore/pallets/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub async fn explore_storage(
Usage:
subxt explore pallet {pallet_name} storage {storage_entry_placeholder}
explore a specific storage entry of this pallet

{storage_entries}
"}
};
Expand Down Expand Up @@ -139,7 +139,7 @@ pub async fn explore_storage(
"}?;
} else {
writedoc! {output,"

Can be accessed without providing a {key_value_placeholder}.
"}?;
}
Expand All @@ -164,12 +164,12 @@ pub async fn explore_storage(
let value = parse_string_into_scale_value(trailing_args)?;
let value_str = value.indent(4);
writedoc! {output, "

You submitted the following {key_value_placeholder}:
{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]
}
Expand All @@ -191,7 +191,7 @@ pub async fn explore_storage(

let value = decoded_value_thunk.to_value()?.to_string().highlight();
writedoc! {output, "

The value of the storage entry is:
{value}
"}?;
Expand Down
18 changes: 9 additions & 9 deletions cli/src/commands/explore/runtime_apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use subxt_metadata::RuntimeApiMetadata;
/// exectute is:
/// false => Show input type description + Example Value
/// true => validate (trailing args + build node connection)
/// validation is:
/// validation is:
/// Err => Show Error
/// Ok => Make a runtime api call witht the provided args.
/// response is:
Expand All @@ -51,7 +51,7 @@ pub async fn run<'a>(
Usage:
subxt explore api {api_name} <METHOD>
explore a specific runtime api method

{methods}
"}
};
Expand All @@ -63,7 +63,7 @@ pub async fn run<'a>(
writedoc! {output, "
Description:
{doc_string}

"}?;
}
writeln!(output, "{}", usage())?;
Expand All @@ -89,7 +89,7 @@ pub async fn run<'a>(
writedoc! {output, "
Description:
{doc_string}

"}?;
}

Expand All @@ -116,7 +116,7 @@ pub async fn run<'a>(
formatdoc! {"
The method expects an {input_value_placeholder} with this shape:
{fields_description}

For example you could provide this {input_value_placeholder}:
{fields_example}"}
};
Expand Down Expand Up @@ -156,13 +156,13 @@ pub async fn run<'a>(
let value_str = value.indent(4);
// convert to bytes:
writedoc! {output, "

You submitted the following {input_value_placeholder}:
{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())?;
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::<color_eyre::Result<Vec<Value>>>()?;
Expand All @@ -178,7 +178,7 @@ pub async fn run<'a>(

let output_value = output_value.to_value()?.to_string().highlight();
writedoc! {output, "

Returned value:
{output_value}
"}?;
Expand Down
6 changes: 3 additions & 3 deletions core/src/blocks/extrinsic_signed_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ 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::new(),
)
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<'a, T: Config> ExtrinsicSignedExtension<'a, T> {
pub fn value(&self) -> Result<Value<u32>, Error> {
let value = scale_value::scale::decode_as_type(
&mut &self.bytes[..],
&self.ty_id,
self.ty_id,
self.metadata.types(),
)?;
Ok(value)
Expand All @@ -163,7 +163,7 @@ impl<'a, T: Config> ExtrinsicSignedExtension<'a, T> {
}

fn as_type<E: DecodeAsType>(&self) -> Result<E, Error> {
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)
}
}
12 changes: 6 additions & 6 deletions core/src/blocks/extrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ 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::new(),
)
Expand All @@ -203,7 +203,7 @@ where

scale_decode::visitor::decode_with_visitor(
cursor,
&ids.signature,
ids.signature,
metadata.types(),
scale_decode::visitor::IgnoreVisitor::new(),
)
Expand All @@ -212,7 +212,7 @@ where

scale_decode::visitor::decode_with_visitor(
cursor,
&ids.extra,
ids.extra,
metadata.types(),
scale_decode::visitor::IgnoreVisitor::new(),
)
Expand Down Expand Up @@ -370,7 +370,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 =
scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())?;

Expand All @@ -388,7 +388,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))
Expand All @@ -403,7 +403,7 @@ where
pub fn as_root_extrinsic<E: DecodeAsType>(&self) -> Result<E, Error> {
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(),
)?;

Expand Down
4 changes: 2 additions & 2 deletions core/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl DecodedValueThunk {
pub fn to_value(&self) -> Result<DecodedValue, scale_decode::Error> {
let val = scale_value::scale::decode_as_type(
&mut &*self.scale_bytes,
&self.type_id,
self.type_id,
self.metadata.types(),
)?;
Ok(val)
Expand All @@ -76,7 +76,7 @@ impl DecodedValueThunk {
pub fn as_type<T: DecodeAsType>(&self) -> Result<T, scale_decode::Error> {
T::decode_as_type(
&mut &self.scale_bytes[..],
&self.type_id,
self.type_id,
self.metadata.types(),
)
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl<T: Config> EventDetails<T> {
// 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::new(),
)
Expand Down Expand Up @@ -373,7 +373,7 @@ impl<T: Config> EventDetails<T> {
.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 =
scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())?;
Expand All @@ -390,7 +390,7 @@ impl<T: Config> EventDetails<T> {
.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))
Expand All @@ -407,7 +407,7 @@ impl<T: Config> EventDetails<T> {

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(),
)?;

Expand Down
4 changes: 2 additions & 2 deletions core/src/metadata/decode_encode_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<T: scale_decode::DecodeAsType> DecodeWithMetadata for T {
type_id: u32,
metadata: &Metadata,
) -> Result<T, scale_decode::Error> {
let val = T::decode_as_type(bytes, &type_id, metadata.types())?;
let val = T::decode_as_type(bytes, type_id, metadata.types())?;
Ok(val)
}
}
Expand All @@ -46,7 +46,7 @@ impl<T: scale_encode::EncodeAsType> EncodeWithMetadata for T {
metadata: &Metadata,
bytes: &mut Vec<u8>,
) -> Result<(), scale_encode::Error> {
self.encode_as_type_to(&type_id, metadata.types(), bytes)?;
self.encode_as_type_to(type_id, metadata.types(), bytes)?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion core/src/runtime_api/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<ArgsData: EncodeAsFields, ReturnTy: DecodeWithMetadata> Payload
.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)?;
Expand Down
8 changes: 4 additions & 4 deletions core/src/storage/storage_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<K: ?Sized> StorageKey for StaticStorageKey<K> {
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(())
}
Expand Down Expand Up @@ -245,7 +245,7 @@ impl StorageKey for Vec<scale_value::Value> {
) -> 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(())
Expand All @@ -264,7 +264,7 @@ impl StorageKey for Vec<scale_value::Value> {
match consume_hash_returning_key_bytes(bytes, hasher, ty_id, types)? {
Some(value_bytes) => {
let value =
scale_value::scale::decode_as_type(&mut &*value_bytes, &ty_id, types)?;
scale_value::scale::decode_as_type(&mut &*value_bytes, ty_id, types)?;
result.push(value.remove_context());
}
None => {
Expand Down Expand Up @@ -302,7 +302,7 @@ fn consume_hash_returning_key_bytes<'a>(
if hasher.ends_with_key() {
scale_decode::visitor::decode_with_visitor(
bytes,
&ty_id,
ty_id,
types,
IgnoreVisitor::<PortableRegistry>::new(),
)
Expand Down
2 changes: 1 addition & 1 deletion core/src/tx/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<CallData: EncodeAsFields> Payload for DefaultPayload<CallData> {
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)
Expand Down
4 changes: 2 additions & 2 deletions core/src/utils/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<Store, Order, R: TypeResolver> scale_decode::Visitor for DecodedBitsVisitor
fn unchecked_decode_as_type<'scale, 'info>(
self,
input: &mut &'scale [u8],
type_id: &R::TypeId,
type_id: R::TypeId,
types: &'info R,
) -> scale_decode::visitor::DecodeAsTypeResult<
Self,
Expand All @@ -181,7 +181,7 @@ impl<Store, Order> scale_decode::IntoVisitor for DecodedBits<Store, Order> {
impl<Store, Order> scale_encode::EncodeAsType for DecodedBits<Store, Order> {
fn encode_as_type_to<R: TypeResolver>(
&self,
type_id: &R::TypeId,
type_id: R::TypeId,
types: &R,
out: &mut Vec<u8>,
) -> Result<(), scale_encode::Error> {
Expand Down
Loading
Loading