ISMP Dispatcher
The dispatcher is the public interface which IsmpModule
s use to dispatch requests and responses. It is also responsible for committing the outgoing requests and responses to storage. It may do so in an overlay tree or the underlying state trie. This ensures that state proofs maybe obtained for dispatched requests and responses. The dispatcher should also emit relevant events after any dispatch operation. The interface for the Ismp Dispatcher is
/// Simplified POST request, intended to be used for sending outgoing requests
pub struct DispatchPost {
/// The destination state machine of this request.
pub dest: StateMachine,
/// Module Id of the sending module
pub from: Vec<u8>,
/// Module ID of the receiving module
pub to: Vec<u8>,
/// Timestamp which this request expires in seconds.
pub timeout_timestamp: u64,
/// Encoded Request.
pub data: Vec<u8>,
}
/// Simplified GET request, intended to be used for sending outgoing requests
pub struct DispatchGet {
/// The destination state machine of this request.
pub dest: StateMachine,
/// Module Id of the sending module
pub from: Vec<u8>,
/// Raw Storage keys that would be used to fetch the values from the counterparty
pub keys: Vec<Vec<u8>>,
/// Height at which to read the state machine.
pub height: u64,
/// Host timestamp at which this request expires in seconds
pub timeout_timestamp: u64,
}
/// Simplified request, intended to be used for sending outgoing requests
pub enum DispatchRequest {
/// The POST variant
Post(DispatchPost),
/// The GET variant
Get(DispatchGet),
}
/// The response to a POST request
pub struct PostResponse {
/// The request that triggered this response.
pub post: Post,
/// The response message.
pub response: Vec<u8>,
/// Timestamp at which this response expires in seconds.
pub timeout_timestamp: u64,
}
pub trait IsmpDispatcher {
/// This function should accept requests from modules and commit them to the state
/// It should emit the `Request` event after a successful dispatch
fn dispatch_request(&self, request: DispatchRequest) -> Result<(), Error>;
/// This function should accept responses from modules and commit them to the state
/// It should emit the `Response` event after a successful dispatch
fn dispatch_response(&self, response: PostResponse) -> Result<(), Error>;
}
Events
Events should be emitted when requests are responses are dispatched. This notifies relayers of the new requests and responses to be transmitted. The structure of ISMP dispatcher events is described below
pub enum Event {
/// Emitted for an outgoing response
Response(PostResponse),
/// Emitted for an outgoing request
Request(Request),
}