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

Upgrade subxt to 0.28 #1039

Merged
merged 8 commits into from
Apr 14, 2023
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
801 changes: 331 additions & 470 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions crates/cargo-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ rust_decimal = "1.29"

# dependencies for extrinsics (deploying and calling a contract)
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
sp-core = "16.0.0"
sp-runtime = "18.0.0"
sp-weights = "14.0.0"
pallet-contracts-primitives = "18.0.0"
subxt = "0.27.1"
sp-core = "20.0.0"
sp-runtime = "23.0.0"
sp-weights = "19.0.0"
pallet-contracts-primitives = "23.0.0"
scale-info = "2.3.1"
subxt = "0.28.0"
hex = "0.4.3"
jsonrpsee = { version = "0.16.2", features = ["ws-client"] }

Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/extrinsics/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl CallCommand {
let call = api::tx().contracts().call(
self.contract.clone().into(),
self.value.denominate_balance(&token_metadata)?,
gas_limit,
gas_limit.into(),
self.extrinsic_opts.storage_deposit_limit(&token_metadata)?,
data,
);
Expand Down
20 changes: 15 additions & 5 deletions crates/cargo-contract/src/cmd/extrinsics/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ impl From<subxt::Error> for ErrorVariant {
fn from(error: subxt::Error) -> Self {
match error {
subxt::Error::Runtime(subxt::error::DispatchError::Module(module_err)) => {
ErrorVariant::Module(ModuleError {
pallet: module_err.pallet.clone(),
error: module_err.error.clone(),
docs: module_err.description,
})
module_err
.details()
.map(|details| {
ErrorVariant::Module(ModuleError {
pallet: details.pallet().to_string(),
error: details.error().to_string(),
docs: details.docs().to_vec(),
})
})
.unwrap_or_else(|err| {
ErrorVariant::Generic(GenericError::from_message(format!(
"Error extracting subxt error details: {}",
err
)))
})
}
err => ErrorVariant::Generic(GenericError::from_message(err.to_string())),
}
Expand Down
15 changes: 8 additions & 7 deletions crates/cargo-contract/src/cmd/extrinsics/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use contract_transcode::{
};

use anyhow::Result;
use scale_info::form::PortableForm;
use std::{
fmt::Write,
str::FromStr,
Expand All @@ -41,7 +42,6 @@ use subxt::{
self,
blocks::ExtrinsicEvents,
events::StaticEvent,
metadata::EventFieldMetadata,
};

/// Field that represent data of an event from invoking a contract extrinsic.
Expand Down Expand Up @@ -115,7 +115,7 @@ impl DisplayEvents {
if <ContractEmitted as StaticEvent>::is_event(
event.pallet_name(),
event.variant_name(),
) && field_metadata.name() == Some("data")
) && field_metadata.name == Some("data".to_string())
{
tracing::debug!("event data: {:?}", hex::encode(&event_data));
let field = contract_event_data_field(
Expand All @@ -126,7 +126,8 @@ impl DisplayEvents {
event_entry.fields.push(field);
} else {
let field_name = field_metadata
.name()
.name
.as_ref()
.map(|s| s.to_string())
.unwrap_or_else(|| {
let name = unnamed_field_name.to_string();
Expand All @@ -136,13 +137,13 @@ impl DisplayEvents {

let decoded_field = events_transcoder.decode(
&runtime_metadata.types,
field_metadata.type_id(),
field_metadata.ty.id,
event_data,
)?;
let field = Field::new(
field_name,
decoded_field,
field_metadata.type_name().map(|s| s.to_string()),
field_metadata.type_name.as_ref().map(|s| s.to_string()),
);
event_entry.fields.push(field);
}
Expand Down Expand Up @@ -210,7 +211,7 @@ impl DisplayEvents {
/// [`ContractMessageTranscoder`] if available.
fn contract_event_data_field(
transcoder: Option<&ContractMessageTranscoder>,
field_metadata: &EventFieldMetadata,
field_metadata: &scale_info::Field<PortableForm>,
event_data: &mut &[u8],
) -> Result<Field> {
let event_value = if let Some(transcoder) = transcoder {
Expand All @@ -230,6 +231,6 @@ fn contract_event_data_field(
Ok(Field::new(
String::from("data"),
event_value,
field_metadata.type_name().map(|s| s.to_string()),
field_metadata.type_name.as_ref().map(|s| s.to_string()),
))
}
4 changes: 2 additions & 2 deletions crates/cargo-contract/src/cmd/extrinsics/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Exec {

let call = api::tx().contracts().instantiate_with_code(
self.args.value,
gas_limit,
gas_limit.into(),
self.args.storage_deposit_limit_compact(),
code.to_vec(),
self.args.data.clone(),
Expand Down Expand Up @@ -294,7 +294,7 @@ impl Exec {

let call = api::tx().contracts().instantiate(
self.args.value,
gas_limit,
gas_limit.into(),
self.args.storage_deposit_limit_compact(),
code_hash,
self.args.data.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl InfoCommand {

let contract_info_of = client
.storage()
.at(None)
.at_latest()
.await?
.fetch(&info_contract_call)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/runtime_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
runtime_metadata_path = "src/cmd/runtime_api/contracts_runtime.scale",
substitute_type(
type = "sp_weights::weight_v2::Weight",
with = "::sp_weights::Weight"
with = "::subxt::utils::Static<::sp_weights::Weight>"
)
)]
pub mod api {}