From 0901fd3deaf06512b01dd329898f77c37f65879e Mon Sep 17 00:00:00 2001 From: h4x3rotab Date: Sun, 25 Apr 2021 19:42:09 +0000 Subject: [PATCH] patch subxt: resolve Assets type clash --- standalone/phost/src/runtimes.rs | 2 ++ subxt/src/events.rs | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/standalone/phost/src/runtimes.rs b/standalone/phost/src/runtimes.rs index 865bf2f13b..507c2525ba 100644 --- a/standalone/phost/src/runtimes.rs +++ b/standalone/phost/src/runtimes.rs @@ -83,6 +83,8 @@ impl Runtime for PhalaNodeRuntime { event_type_registry.with_staking(); event_type_registry.with_session(); + event_type_registry.register_type_size::("Assets::Balance"); + register_default_type_sizes(event_type_registry); } } diff --git a/subxt/src/events.rs b/subxt/src/events.rs index 2cda82f0fe..27371a7e55 100644 --- a/subxt/src/events.rs +++ b/subxt/src/events.rs @@ -157,6 +157,7 @@ impl EventsDecoder { let mut event_data = Vec::::new(); let mut event_errors = Vec::::new(); let result = self.decode_raw_bytes( + module.name(), &event_metadata.arguments(), input, &mut event_data, @@ -192,6 +193,7 @@ impl EventsDecoder { fn decode_raw_bytes( &self, + module: &str, args: &[EventArg], input: &mut &[u8], output: &mut W, @@ -203,7 +205,7 @@ impl EventsDecoder { let len = >::decode(input)?; len.encode_to(output); for _ in 0..len.0 { - self.decode_raw_bytes(&[*arg.clone()], input, output, errors)? + self.decode_raw_bytes(module, &[*arg.clone()], input, output, errors)? } } EventArg::Option(arg) => { @@ -211,7 +213,7 @@ impl EventsDecoder { 0 => output.push_byte(0), 1 => { output.push_byte(1); - self.decode_raw_bytes(&[*arg.clone()], input, output, errors)? + self.decode_raw_bytes(module, &[*arg.clone()], input, output, errors)? } _ => { return Err(Error::Other( @@ -221,14 +223,14 @@ impl EventsDecoder { } } EventArg::Tuple(args) => { - self.decode_raw_bytes(args, input, output, errors)? + self.decode_raw_bytes(module, args, input, output, errors)? } EventArg::Primitive(name) => { let result = match name.as_str() { "DispatchResult" => DispatchResult::decode(input)?, "DispatchError" => Err(DispatchError::decode(input)?), _ => { - if let Some(seg) = self.event_type_registry.resolve(name) { + if let Some(seg) = self.event_type_registry.resolve(module, name) { let mut buf = Vec::::new(); seg.segment(input, &mut buf)?; output.write(&buf); @@ -336,8 +338,9 @@ impl EventTypeRegistry { } /// Resolve a segmenter for a type by its name. - pub fn resolve(&self, name: &str) -> Option<&Box> { - self.segmenters.get(name) + pub fn resolve(&self, module: &str, name: &str) -> Option<&Box> { + let specific_name = format!("{}::{}", module, name); + self.segmenters.get(&specific_name).or(self.segmenters.get(name)) } }