oasis_runtime_sdk/
schedule_control.rs

1//! Types related to schedule control.
2use oasis_core_runtime::{
3    common::crypto::hash::Hash, transaction::types::TxnBatch, types::Body, Protocol,
4};
5
6/// Unique module name.
7const MODULE_NAME: &str = "schedule_control";
8
9/// Schedule control errors.
10#[derive(Debug, thiserror::Error, oasis_runtime_sdk_macros::Error)]
11pub enum Error {
12    #[error("failed to fetch batch from host")]
13    #[sdk_error(code = 1)]
14    FailedToFetchBatch,
15}
16
17/// Interface to the runtime host that supports schedule control features.
18pub trait ScheduleControlHost: Send + Sync {
19    /// Fetch the specified set of transactions from the host's transaction queue.
20    ///
21    /// Offset specifies the transaction hash that should serve as an offset when returning
22    /// transactions from the pool. Transactions will be skipped until the given hash is encountered
23    /// and only following transactions will be returned.
24    fn fetch_tx_batch(&self, offset: Option<Hash>, limit: u32) -> Result<Option<TxnBatch>, Error>;
25}
26
27impl ScheduleControlHost for Protocol {
28    fn fetch_tx_batch(&self, offset: Option<Hash>, limit: u32) -> Result<Option<TxnBatch>, Error> {
29        match self.call_host(Body::HostFetchTxBatchRequest { offset, limit }) {
30            Ok(Body::HostFetchTxBatchResponse { batch }) => Ok(batch),
31            _ => Err(Error::FailedToFetchBatch),
32        }
33    }
34}