diff --git a/runtime-sdk/src/module.rs b/runtime-sdk/src/module.rs index fe5623ae47..d60cbbc6af 100644 --- a/runtime-sdk/src/module.rs +++ b/runtime-sdk/src/module.rs @@ -7,6 +7,8 @@ use std::{ use cbor::Encode as _; use impl_trait_for_tuples::impl_for_tuples; +use oasis_core_runtime::consensus::roothash; + use crate::{ context::{Context, TxContext}, dispatcher, error, @@ -22,6 +24,8 @@ use crate::{ }, }, }; +use crate::modules::core::Error; +use crate::types::in_msg::IncomingMessageData; /// Result of invoking the method handler. pub enum DispatchResult { @@ -370,6 +374,48 @@ impl TransactionHandler for Tuple { } } +pub trait IncomingMessageHandler { + fn prefetch_in_msg( + _prefixes: &mut BTreeSet, + _in_msg: &roothash::IncomingMessage, + _data: &IncomingMessageData, + _tx: &Option, + ) -> Result<(), modules::core::Error> { + Ok(()) + } + fn execute_in_msg( + _ctx: &mut C, + _in_msg: &roothash::IncomingMessage, + _data: &IncomingMessageData, + _tx: &Option, + ) -> Result<(), modules::core::Error> { + Ok(()) + } +} + +#[impl_for_tuples(30)] +impl IncomingMessageHandler for Tuple { + fn prefetch_in_msg( + prefixes: &mut BTreeSet, + in_msg: &roothash::IncomingMessage, + data: &IncomingMessageData, + tx: &Option, + ) -> Result<(), Error> { + for_tuples!( #( Tuple::prefetch_in_msg(prefixes, in_msg, data, tx)?; )* ); + Ok(()) + } + + fn execute_in_msg( + ctx: &mut C, + in_msg: &roothash::IncomingMessage, + data: &IncomingMessageData, + tx: &Option, + ) -> Result<(), Error> { + for_tuples!( #( Tuple::execute_in_msg(ctx, in_msg, data, tx)?; )* ); + Ok(()) + } +} + /// Migration handler. pub trait MigrationHandler { /// Genesis state type. diff --git a/runtime-sdk/src/runtime.rs b/runtime-sdk/src/runtime.rs index 2f828c5708..af8375e8be 100644 --- a/runtime-sdk/src/runtime.rs +++ b/runtime-sdk/src/runtime.rs @@ -22,6 +22,7 @@ use crate::{ }, modules, storage, }; +use crate::module::IncomingMessageHandler; /// A runtime. pub trait Runtime { @@ -43,6 +44,7 @@ pub trait Runtime { type Modules: TransactionHandler + MigrationHandler + MethodHandler + + IncomingMessageHandler + BlockHandler + InvariantHandler + ModuleInfoHandler;