Skip to content

Commit

Permalink
Updating subxt
Browse files Browse the repository at this point in the history
  • Loading branch information
ascjones committed Aug 21, 2023
1 parent 7b9a4cb commit 97f60be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
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

0 comments on commit 97f60be

Please sign in to comment.