Skip to content
New issue

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

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

Already on GitHub? # to your account

Store type name of a field in event metadata #654

Merged
merged 4 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.23.1] - 2022-09-15

Fields in `EventMetadata` now also store name of a type specified in the pallet's source code.

## [0.23.0] - 2022-08-11

This is one of the most significant releases to date in Subxt, and carries with it a number of significant breaking changes, but in exchange, a number of significant improvements. The most significant PR is [#593](https://github.com/paritytech/subxt/pull/593); the fundamental change that this makes is to separate creating a query/transaction/address from submitting it. This gives us flexibility when creating queries; they can be either dynamically or statically generated, but also flexibility in our client, enabling methods to be exposed for online or offline use.
Expand Down
8 changes: 4 additions & 4 deletions subxt/src/events/events_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl EventDetails {
);

// Skip over the bytes belonging to this event.
for (_name, type_id) in event_metadata.fields() {
for (_name, _type_name, type_id) in event_metadata.fields() {
// Skip over the bytes for this field:
scale_decode::decode(
input,
Expand Down Expand Up @@ -288,12 +288,12 @@ impl EventDetails {
let is_named = event_metadata
.fields()
.get(0)
.map(|(n, _)| n.is_some())
.map(|(n, _, _)| n.is_some())
.unwrap_or(false);

if !is_named {
let mut event_values = vec![];
for (_, type_id) in event_metadata.fields() {
for (_, _, type_id) in event_metadata.fields() {
let value = scale_value::scale::decode_as_type(
bytes,
*type_id,
Expand All @@ -305,7 +305,7 @@ impl EventDetails {
Ok(scale_value::Composite::Unnamed(event_values))
} else {
let mut event_values = vec![];
for (name, type_id) in event_metadata.fields() {
for (name, _, type_id) in event_metadata.fields() {
let value = scale_value::scale::decode_as_type(
bytes,
*type_id,
Expand Down
14 changes: 10 additions & 4 deletions subxt/src/metadata/metadata_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub struct EventMetadata {
// behind an Arc to avoid lots of needless clones of it existing.
pallet: Arc<str>,
event: String,
fields: Vec<(Option<String>, u32)>,
fields: Vec<(Option<String>, Option<String>, u32)>,
docs: Vec<String>,
}

Expand All @@ -319,8 +319,8 @@ impl EventMetadata {
&self.event
}

/// The names and types of each field in the event.
pub fn fields(&self) -> &[(Option<String>, u32)] {
/// The names, type names & types of each field in the event.
pub fn fields(&self) -> &[(Option<String>, Option<String>, u32)] {
&self.fields
}

Expand Down Expand Up @@ -457,7 +457,13 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
fields: variant
.fields()
.iter()
.map(|f| (f.name().map(|n| n.to_owned()), f.ty().id()))
.map(|f| {
(
f.name().map(|n| n.to_owned()),
f.type_name().map(|n| n.to_owned()),
f.ty().id(),
)
})
.collect(),
docs: variant.docs().to_vec(),
},
Expand Down