Skip to content

ISMP Router

The router lives in-between the ISMP message handlers and modules, the router provides access to a concrete implementation of an IsmpModule which a request or response is designated for based on the destination module Id. The interface for the router is

pub trait IsmpRouter {
    /// Should decode the module id and return a handler to the appropriate `IsmpModule`
    /// implementation
    fn module_for_id(&self, bytes: Vec<u8>) -> Result<Box<dyn IsmpModule>, Error>;
}

ISMP Modules

Users cannot directly initiate requests or receive responses. Instead, they must transact with an application, which then initiates the request and receives the responses. These applications, referred to as ISMP Modules, can be either pallets or smart-contracts. For an application to be ISMP compatible, it must implement a specific interface that enables the router to dispatch incoming requests and responses. Each application should have a unique identifier configured in the runtime for identification by the router. The required module interface is as follows

/// Individual modules which live on a state machine must conform to this interface in order to send
/// and receive ISMP requests and responses
pub trait IsmpModule {
    /// Called by the message handler on a module, to notify module of a new POST request
    /// the module may choose to respond immediately, or in a later block
    fn on_accept(&self, request: Post) -> Result<(), Error>;
 
    /// Called by the message handler on a module, to notify module of a response to a previously
    /// sent out request
    fn on_response(&self, response: Response) -> Result<(), Error>;
 
    /// Called by the message handler on a module, to notify module of requests that were previously
    /// sent but have now timed-out
    fn on_timeout(&self, request: Timeout) -> Result<(), Error>;
}