-
Notifications
You must be signed in to change notification settings - Fork 111
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
Auto-generate hooks based on Runtime #320
Comments
What about this:
#[derive(Genesis, DispatchCall, MessageCodec, Hooks)]
pub struct Runtime<C: Context> {
#[hook]
pub sequencer: sequencer::Sequencer<C>,
pub bank: bank::Bank<C>,
pub election: election::Election<C>,
pub value_setter: value_setter::ValueSetter<C>,
#[hook]
pub accounts: accounts::Accounts<C>,
} And the implementation of the |
This looks great overall. Do we have a motivating a use case where users would want a module without its hooks though? If not, can we just derive a no-op |
Yeah we can automatically derive implementations with noop. |
After incorporating #361, the hooks implementation has a well-defined structure, allowing us to implement the macro. However, there is a small remaining issue. impl<C: Context> TxHooks for Runtime<C> {
type Context = C;
fn pre_dispatch_tx_hook(
&self,
tx: Transaction<Self::Context>,
working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>,
) -> anyhow::Result<<Self::Context as Spec>::Address> {
self.accounts.pre_dispatch_tx_hook(tx, working_set)
}
fn post_dispatch_tx_hook(
&self,
tx: &Transaction<Self::Context>,
working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>,
) -> anyhow::Result<()> {
self.accounts.post_dispatch_tx_hook(tx, working_set)
}
} The issue with the To address this, we can modify the 1.Remove the functionality that updates the |
Currently, users have to manually define their TxHooks implementation based on the modules they use. In principle, though, it seems like it should be possible (and much less error-prone) to automatically generate the hooks based on the runtime.
cc @bkolad
The text was updated successfully, but these errors were encountered: