use oasis_core_runtime::{
common::crypto::hash::Hash, transaction::types::TxnBatch, types::Body, Protocol,
};
const MODULE_NAME: &str = "schedule_control";
#[derive(Debug, thiserror::Error, oasis_runtime_sdk_macros::Error)]
pub enum Error {
#[error("failed to fetch batch from host")]
#[sdk_error(code = 1)]
FailedToFetchBatch,
}
pub trait ScheduleControlHost: Send + Sync {
fn fetch_tx_batch(&self, offset: Option<Hash>, limit: u32) -> Result<Option<TxnBatch>, Error>;
}
impl ScheduleControlHost for Protocol {
fn fetch_tx_batch(&self, offset: Option<Hash>, limit: u32) -> Result<Option<TxnBatch>, Error> {
match self.call_host(Body::HostFetchTxBatchRequest { offset, limit }) {
Ok(Body::HostFetchTxBatchResponse { batch }) => Ok(batch),
_ => Err(Error::FailedToFetchBatch),
}
}
}