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

Document how to add custom type in event decoding #192

Closed
h4x3rotab opened this issue Nov 26, 2020 · 1 comment
Closed

Document how to add custom type in event decoding #192

h4x3rotab opened this issue Nov 26, 2020 · 1 comment

Comments

@h4x3rotab
Copy link
Contributor

Suppose we have an customized event defined in a pallet:

pub enum Event<T> ... {
  MyEvent(MyStruct),
}
#[derive(...)]
struct MyStruct {
  field1: u32
}

Once I send and watch any extrinsic with subxt, it tries to decode all the events. As long as there's one or more events with customized type, it fails with Err(TypeSizeUnavailable("MyStruct")). After reading some code, I finally fixed it by adding a associated type in the runtime trait like this:

impl MyModule for MyRuntime {
    type MyStruct = MyStruct;
}

#[module]
pub trait MyModule: System + Balances {
  type MyStruct: Encode + Decode + PartialEq + Eq + Default + Send + Sync + 'static;
}

I think it would be nice to document it. Also, I wonder why we need such a long list of constraint for the associated type.

@ascjones
Copy link
Contributor

ascjones commented Nov 8, 2021

Closed by #294

@ascjones ascjones closed this as completed Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants