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

Subxt typeclash #190

Merged
merged 1 commit into from
Apr 26, 2021
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
2 changes: 2 additions & 0 deletions standalone/phost/src/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ impl Runtime for PhalaNodeRuntime {
event_type_registry.with_staking();
event_type_registry.with_session();

event_type_registry.register_type_size::<u64>("Assets::Balance");

register_default_type_sizes(event_type_registry);
}
}
Expand Down
15 changes: 9 additions & 6 deletions subxt/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl<T: Runtime + System> EventsDecoder<T> {
let mut event_data = Vec::<u8>::new();
let mut event_errors = Vec::<RuntimeError>::new();
let result = self.decode_raw_bytes(
module.name(),
&event_metadata.arguments(),
input,
&mut event_data,
Expand Down Expand Up @@ -192,6 +193,7 @@ impl<T: Runtime + System> EventsDecoder<T> {

fn decode_raw_bytes<W: Output>(
&self,
module: &str,
args: &[EventArg],
input: &mut &[u8],
output: &mut W,
Expand All @@ -203,15 +205,15 @@ impl<T: Runtime + System> EventsDecoder<T> {
let len = <Compact<u32>>::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) => {
match input.read_byte()? {
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(
Expand All @@ -221,14 +223,14 @@ impl<T: Runtime + System> EventsDecoder<T> {
}
}
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::<u8>::new();
seg.segment(input, &mut buf)?;
output.write(&buf);
Expand Down Expand Up @@ -336,8 +338,9 @@ impl<T: Runtime> EventTypeRegistry<T> {
}

/// Resolve a segmenter for a type by its name.
pub fn resolve(&self, name: &str) -> Option<&Box<dyn TypeSegmenter>> {
self.segmenters.get(name)
pub fn resolve(&self, module: &str, name: &str) -> Option<&Box<dyn TypeSegmenter>> {
let specific_name = format!("{}::{}", module, name);
self.segmenters.get(&specific_name).or(self.segmenters.get(name))
}
}

Expand Down