Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Support tuples for OnNewAccount hook in Balances module #2763

Closed
shawntabrizi opened this issue Jun 3, 2019 · 1 comment · Fixed by #2765
Closed

Support tuples for OnNewAccount hook in Balances module #2763

shawntabrizi opened this issue Jun 3, 2019 · 1 comment · Fixed by #2765
Labels
I7-refactor Code needs refactoring. U3-nice_to_have Issue is worth doing eventually. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder

Comments

@shawntabrizi
Copy link
Contributor

Runtime developers may want to trigger multiple functions when a new account is created, however this is not currently supported for OnNewAccount like it is for other hooks.

We should also look through the other modules and make sure that their hooks also support tuples.

@shawntabrizi shawntabrizi added B0-patchthis I7-refactor Code needs refactoring. U3-nice_to_have Issue is worth doing eventually. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder labels Jun 3, 2019
@xlc
Copy link
Contributor

xlc commented Jun 3, 2019

EventHandler pattern is commonly used in C#. Does it make sense to have something similar here to make those callback / event handler easier to use?

Something like

trait EventHandler<T> {
    fn onEvent(args: T);
}

struct SomeEvent {
   foo: u32
}

trait Trait {
    type OnSomeEvent: EventHandler<SomeEvent>;
}

impl<T> EventHandler<T> for () 
impl<T, A: EventHandler<T>, B: EventHandler<T>> EventHandler<T> for (A, B) 
....

impl my_module::Trait for Runtime {
   OnSomeEvent: (ModuleA, ModuleB)
}

The goal is avoid update each individual trigger to make them support multiple handlers.

Also, is there a proper name for this pattern? Trigger? Callback? I will want to call it event but there is already another event in Substrate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I7-refactor Code needs refactoring. U3-nice_to_have Issue is worth doing eventually. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants