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 subxt and substrate dependencies #1149

Merged
merged 14 commits into from
Jun 23, 2023
10 changes: 5 additions & 5 deletions crates/cargo-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ rust_decimal = "1.30"

# dependencies for extrinsics (deploying and calling a contract)
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
sp-core = "20.0.0"
sp-runtime = "23.0.0"
sp-weights = "19.0.0"
pallet-contracts-primitives = "23.0.0"
sp-core = "21.0.0"
sp-runtime = "24.0.0"
sp-weights = "20.0.0"
pallet-contracts-primitives = "24.0.0"
scale-info = "2.8.0"
subxt = "0.28.0"
subxt = "0.29.0"
hex = "0.4.3"
jsonrpsee = { version = "0.18.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 @@ -168,7 +168,7 @@ impl CallCommand {
input_data: Vec<u8>,
client: &Client,
signer: &PairSigner,
) -> Result<ContractExecResult<Balance>> {
) -> Result<ContractExecResult<Balance, ()>> {
let url = self.extrinsic_opts.url_to_string();
let token_metadata = TokenMetadata::query(client).await?;
let storage_deposit_limit = self
Expand Down
18 changes: 11 additions & 7 deletions crates/cargo-contract/src/cmd/extrinsics/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl From<subxt::Error> for ErrorVariant {
.details()
.map(|details| {
ErrorVariant::Module(ModuleError {
pallet: details.pallet().to_string(),
error: details.error().to_string(),
docs: details.docs().to_vec(),
pallet: details.pallet.name().to_string(),
error: details.variant.name.to_string(),
docs: details.variant.docs.clone(),
})
})
.unwrap_or_else(|err| {
Expand Down Expand Up @@ -91,11 +91,15 @@ impl ErrorVariant {
) -> anyhow::Result<ErrorVariant> {
match error {
DispatchError::Module(err) => {
let details = metadata.error(err.index, err.error[0])?;
let pallet = metadata.pallet_by_index_err(err.index)?;
let variant =
pallet.error_variant_by_index(err.error[0]).ok_or_else(|| {
anyhow::anyhow!("Error variant {} not found", err.error[0])
})?;
Ok(ErrorVariant::Module(ModuleError {
pallet: details.pallet().to_owned(),
error: details.error().to_owned(),
docs: details.docs().to_owned(),
pallet: pallet.name().to_string(),
error: variant.name.to_owned(),
docs: variant.docs.to_owned(),
}))
}
err => {
Expand Down
16 changes: 9 additions & 7 deletions crates/cargo-contract/src/cmd/extrinsics/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,20 @@ impl DisplayEvents {
) -> Result<DisplayEvents> {
let mut events: Vec<Event> = vec![];

let runtime_metadata = subxt_metadata.runtime_metadata();
let events_transcoder = TranscoderBuilder::new(&runtime_metadata.types)
let events_transcoder = TranscoderBuilder::new(subxt_metadata.types())
.with_default_custom_type_transcoders()
.done();

for event in result.iter() {
let event = event?;
tracing::debug!("displaying event {:?}", event);
tracing::debug!(
"displaying event {}:{}",
event.pallet_name(),
event.variant_name()
);

let event_metadata =
subxt_metadata.event(event.pallet_index(), event.variant_index())?;
let event_fields = event_metadata.fields();
let event_metadata = event.event_metadata();
let event_fields = &event_metadata.variant.fields;

let mut event_entry = Event {
pallet: event.pallet_name().to_string(),
Expand Down Expand Up @@ -136,7 +138,7 @@ impl DisplayEvents {
});

let decoded_field = events_transcoder.decode(
&runtime_metadata.types,
subxt_metadata.types(),
field_metadata.ty.id,
event_data,
)?;
Expand Down
5 changes: 3 additions & 2 deletions crates/cargo-contract/src/cmd/extrinsics/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ impl Exec {

async fn instantiate_dry_run(
&self,
) -> Result<ContractInstantiateResult<<DefaultConfig as Config>::AccountId, Balance>>
{
) -> Result<
ContractInstantiateResult<<DefaultConfig as Config>::AccountId, Balance, ()>,
> {
let storage_deposit_limit = self.args.storage_deposit_limit;
let call_request = InstantiateRequest {
origin: self.signer.account_id().clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/cargo-contract/src/cmd/extrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub const MAX_KEY_COL_WIDTH: usize = STORAGE_DEPOSIT_KEY.len() + 1;

/// Print to stdout the fields of the result of a `instantiate` or `call` dry-run via RPC.
pub fn display_contract_exec_result<R, const WIDTH: usize>(
result: &ContractResult<R, Balance>,
result: &ContractResult<R, Balance, ()>,
) -> Result<()> {
let mut debug_message_lines = std::str::from_utf8(&result.debug_message)
.context("Error decoding UTF8 debug message bytes")?
Expand All @@ -352,7 +352,7 @@ pub fn display_contract_exec_result<R, const WIDTH: usize>(
}

pub fn display_contract_exec_result_debug<R, const WIDTH: usize>(
result: &ContractResult<R, Balance>,
result: &ContractResult<R, Balance, ()>,
) -> Result<()> {
let mut debug_message_lines = std::str::from_utf8(&result.debug_message)
.context("Error decoding UTF8 debug message bytes")?
Expand Down
Binary file not shown.
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 @@ -19,7 +19,7 @@
#[subxt::subxt(
runtime_metadata_path = "src/cmd/runtime_api/contracts_runtime.scale",
substitute_type(
type = "sp_weights::weight_v2::Weight",
path = "sp_weights::weight_v2::Weight",
with = "::subxt::utils::Static<::sp_weights::Weight>"
)
)]
Expand Down