diff --git a/hermes/bin/src/event_queue/event.rs b/hermes/bin/src/event_queue/event.rs index 18dcb6758..b357ffa14 100644 --- a/hermes/bin/src/event_queue/event.rs +++ b/hermes/bin/src/event_queue/event.rs @@ -3,7 +3,7 @@ use crate::wasm::module::ModuleInstance; /// A trait for defining the behavior of a Hermes event. -pub trait HermesEventPayload { +pub trait HermesEventPayload: Send { /// Returns the name of the event associated with the payload. fn event_name(&self) -> &str; @@ -16,5 +16,5 @@ pub trait HermesEventPayload { /// # Returns /// /// An `anyhow::Result` indicating the success or failure of the payload execution. - fn execute(&self, executor: &mut ModuleInstance) -> anyhow::Result<()>; + fn execute(&self, module: &mut ModuleInstance) -> anyhow::Result<()>; } diff --git a/hermes/bin/src/lib.rs b/hermes/bin/src/lib.rs index 802f8a952..78d6a0016 100644 --- a/hermes/bin/src/lib.rs +++ b/hermes/bin/src/lib.rs @@ -2,6 +2,6 @@ //! This file exists, so that doc tests can be used inside binary crates. mod event_queue; -mod runtime; +mod runtime_extensions; mod state; mod wasm; diff --git a/hermes/bin/src/main.rs b/hermes/bin/src/main.rs index 117bdf2fe..69b7bc9a8 100644 --- a/hermes/bin/src/main.rs +++ b/hermes/bin/src/main.rs @@ -1,7 +1,7 @@ //! The Hermes Node. mod event_queue; -mod runtime; +mod runtime_extensions; mod state; mod wasm; diff --git a/hermes/bin/src/runtime/host/hermes/binary/mod.rs b/hermes/bin/src/runtime/host/hermes/binary/mod.rs deleted file mode 100644 index 763e74690..000000000 --- a/hermes/bin/src/runtime/host/hermes/binary/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! Host - CBOR implementations - -use crate::{ - runtime::extensions::{ - bindings::hermes::binary::api::Host, - state::{Context, Stateful}, - }, - state::HermesState, -}; - -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - -impl Host for HermesState {} diff --git a/hermes/bin/src/runtime/host/hermes/cbor/mod.rs b/hermes/bin/src/runtime/host/hermes/cbor/mod.rs deleted file mode 100644 index 685fded80..000000000 --- a/hermes/bin/src/runtime/host/hermes/cbor/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! Host - CBOR implementations - -use crate::{ - runtime::extensions::{ - bindings::hermes::cbor::api::Host, - state::{Context, Stateful}, - }, - state::HermesState, -}; - -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - -impl Host for HermesState {} diff --git a/hermes/bin/src/runtime/host/hermes/json/mod.rs b/hermes/bin/src/runtime/host/hermes/json/mod.rs deleted file mode 100644 index 9b360f379..000000000 --- a/hermes/bin/src/runtime/host/hermes/json/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! Host - JSON implementations - -use crate::{ - runtime::extensions::{ - bindings::hermes::json::api::Host, - state::{Context, Stateful}, - }, - state::HermesState, -}; - -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - -impl Host for HermesState {} diff --git a/hermes/bin/src/runtime/host/mod.rs b/hermes/bin/src/runtime/host/mod.rs deleted file mode 100644 index 6e3721d85..000000000 --- a/hermes/bin/src/runtime/host/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! Runtime runtime extensions - Host implementations - -pub(crate) mod hermes; -pub(crate) mod wasi; diff --git a/hermes/bin/src/runtime/mod.rs b/hermes/bin/src/runtime/mod.rs deleted file mode 100644 index 6591d1e6e..000000000 --- a/hermes/bin/src/runtime/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! Runtime modules - -pub(crate) mod extensions; -pub(crate) mod host; diff --git a/hermes/bin/src/runtime/extensions/bindings.rs b/hermes/bin/src/runtime_extensions/bindings.rs similarity index 100% rename from hermes/bin/src/runtime/extensions/bindings.rs rename to hermes/bin/src/runtime_extensions/bindings.rs diff --git a/hermes/bin/src/runtime_extensions/hermes/binary/host.rs b/hermes/bin/src/runtime_extensions/hermes/binary/host.rs new file mode 100644 index 000000000..7eddd020f --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/binary/host.rs @@ -0,0 +1,5 @@ +//! Binary host implementation for WASM runtime. + +use crate::{runtime_extensions::bindings::hermes::binary::api::Host, state::HermesState}; + +impl Host for HermesState {} diff --git a/hermes/bin/src/runtime_extensions/hermes/binary/mod.rs b/hermes/bin/src/runtime_extensions/hermes/binary/mod.rs new file mode 100644 index 000000000..69a2afd33 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/binary/mod.rs @@ -0,0 +1,14 @@ +//! Binary runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime_extensions/hermes/cardano/event.rs b/hermes/bin/src/runtime_extensions/hermes/cardano/event.rs new file mode 100644 index 000000000..af952b5ae --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/cardano/event.rs @@ -0,0 +1,87 @@ +//! Cardano Blockchain runtime extension event handler implementation. + +use crate::{ + event_queue::event::HermesEventPayload, + runtime_extensions::bindings::hermes::cardano::api::{ + BlockSrc, CardanoBlock, CardanoBlockchainId, CardanoTxn, + }, +}; + +/// On Cardano block event +struct OnCardanoBlockEvent { + /// The blockchain id the block originated from. + blockchain: CardanoBlockchainId, + /// This raw CBOR block data. + block: CardanoBlock, + /// Source information about where the block came from, and if we are at tip or not. + source: BlockSrc, +} + +impl HermesEventPayload for OnCardanoBlockEvent { + fn event_name(&self) -> &str { + "on-cardano-block" + } + + fn execute(&self, module: &mut crate::wasm::module::ModuleInstance) -> anyhow::Result<()> { + module + .instance + .hermes_cardano_event_on_block() + .call_on_cardano_block(&mut module.store, self.blockchain, &self.block, self.source)?; + Ok(()) + } +} + +/// On Cardano txn event +struct OnCardanoTxnEvent { + /// The blockchain id the block originated from. + blockchain: CardanoBlockchainId, + /// The slot the transaction is in. + slot: u64, + /// The offset in the block this transaction is at. + txn_index: u32, + /// The raw transaction data itself. + txn: CardanoTxn, +} + +impl HermesEventPayload for OnCardanoTxnEvent { + fn event_name(&self) -> &str { + "on-cardano-txn" + } + + fn execute(&self, module: &mut crate::wasm::module::ModuleInstance) -> anyhow::Result<()> { + module + .instance + .hermes_cardano_event_on_txn() + .call_on_cardano_txn( + &mut module.store, + self.blockchain, + self.slot, + self.txn_index, + &self.txn, + )?; + + Ok(()) + } +} + +/// On Cardano rollback event +struct OnCardanoRollback { + /// The blockchain id the block originated from. + blockchain: CardanoBlockchainId, + /// The slot the transaction is in. + slot: u64, +} + +impl HermesEventPayload for OnCardanoRollback { + fn event_name(&self) -> &str { + "on-cardano-rollback" + } + + fn execute(&self, module: &mut crate::wasm::module::ModuleInstance) -> anyhow::Result<()> { + module + .instance + .hermes_cardano_event_on_rollback() + .call_on_cardano_rollback(&mut module.store, self.blockchain, self.slot)?; + Ok(()) + } +} diff --git a/hermes/bin/src/runtime/host/hermes/cardano/mod.rs b/hermes/bin/src/runtime_extensions/hermes/cardano/host.rs similarity index 92% rename from hermes/bin/src/runtime/host/hermes/cardano/mod.rs rename to hermes/bin/src/runtime_extensions/hermes/cardano/host.rs index 8ab3dda37..1949e263e 100644 --- a/hermes/bin/src/runtime/host/hermes/cardano/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/cardano/host.rs @@ -1,25 +1,13 @@ -//! Host - Cardano Blockchain implementations +//! Cardano Blockchain host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::hermes::cardano::api::{ - CardanoBlock, CardanoBlockchainId, CardanoTxn, FetchError, Host, Slot, TxnError, - UnsubscribeOptions, - }, - state::{Context, Stateful}, + runtime_extensions::bindings::hermes::cardano::api::{ + CardanoBlock, CardanoBlockchainId, CardanoTxn, FetchError, Host, Slot, TxnError, + UnsubscribeOptions, }, state::HermesState, }; -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - impl Host for HermesState { /// Subscribe to the Blockchain block data. /// diff --git a/hermes/bin/src/runtime_extensions/hermes/cardano/mod.rs b/hermes/bin/src/runtime_extensions/hermes/cardano/mod.rs new file mode 100644 index 000000000..d6c134dda --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/cardano/mod.rs @@ -0,0 +1,15 @@ +//! Cardano Blockchain runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod event; +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime_extensions/hermes/cbor/host.rs b/hermes/bin/src/runtime_extensions/hermes/cbor/host.rs new file mode 100644 index 000000000..ccd135018 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/cbor/host.rs @@ -0,0 +1,5 @@ +//! CBOR host implementation for WASM runtime. + +use crate::{runtime_extensions::bindings::hermes::cbor::api::Host, state::HermesState}; + +impl Host for HermesState {} diff --git a/hermes/bin/src/runtime_extensions/hermes/cbor/mod.rs b/hermes/bin/src/runtime_extensions/hermes/cbor/mod.rs new file mode 100644 index 000000000..24972f85c --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/cbor/mod.rs @@ -0,0 +1,14 @@ +//! CBOR runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime_extensions/hermes/cron/event.rs b/hermes/bin/src/runtime_extensions/hermes/cron/event.rs new file mode 100644 index 000000000..20b1b36b7 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/cron/event.rs @@ -0,0 +1,30 @@ +//! Cron runtime extension event handler implementation. + +use crate::{ + event_queue::event::HermesEventPayload, + runtime_extensions::bindings::hermes::cron::api::CronTagged, +}; + +/// On cron event +struct OnCronEvent { + /// The tagged cron event that was triggered. + tag: CronTagged, + /// This cron event will not retrigger. + last: bool, +} + +impl HermesEventPayload for OnCronEvent { + fn event_name(&self) -> &str { + "on-cron" + } + + fn execute(&self, module: &mut crate::wasm::module::ModuleInstance) -> anyhow::Result<()> { + // TODO (@stevenj): https://github.com/input-output-hk/hermes/issues/93 + let _res: bool = module.instance.hermes_cron_event().call_on_cron( + &mut module.store, + &self.tag, + self.last, + )?; + Ok(()) + } +} diff --git a/hermes/bin/src/runtime/host/hermes/cron/mod.rs b/hermes/bin/src/runtime_extensions/hermes/cron/host.rs similarity index 92% rename from hermes/bin/src/runtime/host/hermes/cron/mod.rs rename to hermes/bin/src/runtime_extensions/hermes/cron/host.rs index 463e2a9e1..75260877b 100644 --- a/hermes/bin/src/runtime/host/hermes/cron/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/cron/host.rs @@ -1,25 +1,13 @@ -//! Host - Cron implementations +//! Cron host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::{ - hermes::cron::api::{CronEventTag, CronSched, CronTagged, CronTime, Host}, - wasi::clocks::monotonic_clock::Instant, - }, - state::{Context, Stateful}, + runtime_extensions::bindings::{ + hermes::cron::api::{CronEventTag, CronSched, CronTagged, CronTime, Host}, + wasi::clocks::monotonic_clock::Instant, }, state::HermesState, }; -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - impl Host for HermesState { /// # Schedule Recurrent CRON event /// diff --git a/hermes/bin/src/runtime_extensions/hermes/cron/mod.rs b/hermes/bin/src/runtime_extensions/hermes/cron/mod.rs new file mode 100644 index 000000000..27b6ab0b7 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/cron/mod.rs @@ -0,0 +1,15 @@ +//! Cron runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod event; +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime/host/hermes/crypto/mod.rs b/hermes/bin/src/runtime_extensions/hermes/crypto/host.rs similarity index 82% rename from hermes/bin/src/runtime/host/hermes/crypto/mod.rs rename to hermes/bin/src/runtime_extensions/hermes/crypto/host.rs index 2b06252de..c014e60be 100644 --- a/hermes/bin/src/runtime/host/hermes/crypto/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/crypto/host.rs @@ -1,28 +1,16 @@ -//! Host - Crypto implementations +//! Crypto host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::hermes::{ - binary::api::Bstr, - crypto::api::{ - Ed25519Bip32, Ed25519Bip32PrivateKey, Ed25519Bip32PublicKey, Ed25519Bip32Signature, - Host, HostEd25519Bip32, - }, + runtime_extensions::bindings::hermes::{ + binary::api::Bstr, + crypto::api::{ + Ed25519Bip32, Ed25519Bip32PrivateKey, Ed25519Bip32PublicKey, Ed25519Bip32Signature, + Host, HostEd25519Bip32, }, - state::{Context, Stateful}, }, state::HermesState, }; -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - impl HostEd25519Bip32 for HermesState { /// Create a new ED25519-BIP32 Crypto resource /// diff --git a/hermes/bin/src/runtime_extensions/hermes/crypto/mod.rs b/hermes/bin/src/runtime_extensions/hermes/crypto/mod.rs new file mode 100644 index 000000000..6cbb6a69d --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/crypto/mod.rs @@ -0,0 +1,14 @@ +//! Crypto runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime/host/hermes/hash/mod.rs b/hermes/bin/src/runtime_extensions/hermes/hash/host.rs similarity index 67% rename from hermes/bin/src/runtime/host/hermes/hash/mod.rs rename to hermes/bin/src/runtime_extensions/hermes/hash/host.rs index 9f1a642a2..1e196eb89 100644 --- a/hermes/bin/src/runtime/host/hermes/hash/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/hash/host.rs @@ -1,25 +1,13 @@ -//! Host - Hash implementations +//! Hash host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::hermes::{ - binary::api::Bstr, - hash::api::{Errno, Host}, - }, - state::{Context, Stateful}, + runtime_extensions::bindings::hermes::{ + binary::api::Bstr, + hash::api::{Errno, Host}, }, state::HermesState, }; -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - impl Host for HermesState { /// Hash a binary buffer with BLAKE2s fn blake2s( diff --git a/hermes/bin/src/runtime_extensions/hermes/hash/mod.rs b/hermes/bin/src/runtime_extensions/hermes/hash/mod.rs new file mode 100644 index 000000000..db70a87d0 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/hash/mod.rs @@ -0,0 +1,14 @@ +//! Hash runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime/host/hermes/init/mod.rs b/hermes/bin/src/runtime_extensions/hermes/init/mod.rs similarity index 55% rename from hermes/bin/src/runtime/host/hermes/init/mod.rs rename to hermes/bin/src/runtime_extensions/hermes/init/mod.rs index b796452e0..0eee10a7b 100644 --- a/hermes/bin/src/runtime/host/hermes/init/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/init/mod.rs @@ -1,6 +1,6 @@ -//! Host - Init implementations +//! Init runtime extension implementation. -use crate::runtime::extensions::state::{Context, Stateful}; +use crate::runtime_extensions::state::{Context, Stateful}; /// State pub(crate) struct State {} diff --git a/hermes/bin/src/runtime_extensions/hermes/json/host.rs b/hermes/bin/src/runtime_extensions/hermes/json/host.rs new file mode 100644 index 000000000..00e7e46c8 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/json/host.rs @@ -0,0 +1,5 @@ +//! JSON host implementation for WASM runtime. + +use crate::{runtime_extensions::bindings::hermes::json::api::Host, state::HermesState}; + +impl Host for HermesState {} diff --git a/hermes/bin/src/runtime_extensions/hermes/json/mod.rs b/hermes/bin/src/runtime_extensions/hermes/json/mod.rs new file mode 100644 index 000000000..68389f3f6 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/json/mod.rs @@ -0,0 +1,14 @@ +//! JSON runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime_extensions/hermes/kv_store/event.rs b/hermes/bin/src/runtime_extensions/hermes/kv_store/event.rs new file mode 100644 index 000000000..42394b865 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/kv_store/event.rs @@ -0,0 +1,29 @@ +//! KV-Store runtime extension event handler implementation. + +use crate::{ + event_queue::event::HermesEventPayload, + runtime_extensions::bindings::hermes::kv_store::api::KvValues, +}; + +/// KV update event +struct KVUpdateEvent { + /// Key. + key: String, + /// Value. + value: KvValues, +} + +impl HermesEventPayload for KVUpdateEvent { + fn event_name(&self) -> &str { + "kv-update" + } + + fn execute(&self, module: &mut crate::wasm::module::ModuleInstance) -> anyhow::Result<()> { + module.instance.hermes_kv_store_event().call_kv_update( + &mut module.store, + &self.key, + &self.value, + )?; + Ok(()) + } +} diff --git a/hermes/bin/src/runtime/host/hermes/kv_store/mod.rs b/hermes/bin/src/runtime_extensions/hermes/kv_store/host.rs similarity index 92% rename from hermes/bin/src/runtime/host/hermes/kv_store/mod.rs rename to hermes/bin/src/runtime_extensions/hermes/kv_store/host.rs index 36d79c21b..eb9647e55 100644 --- a/hermes/bin/src/runtime/host/hermes/kv_store/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/kv_store/host.rs @@ -1,22 +1,10 @@ -//! Host - KV-Store implementations +//! KV-Store host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::hermes::kv_store::api::{Host, KvValues}, - state::{Context, Stateful}, - }, + runtime_extensions::bindings::hermes::kv_store::api::{Host, KvValues}, state::HermesState, }; -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - impl Host for HermesState { /// Set a value in the local key-value store /// Setting None will cause the Key to be deleted from the KV store. diff --git a/hermes/bin/src/runtime_extensions/hermes/kv_store/mod.rs b/hermes/bin/src/runtime_extensions/hermes/kv_store/mod.rs new file mode 100644 index 000000000..21fa3eb22 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/kv_store/mod.rs @@ -0,0 +1,15 @@ +//! KV-Store runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod event; +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime/host/hermes/localtime/mod.rs b/hermes/bin/src/runtime_extensions/hermes/localtime/host.rs similarity index 81% rename from hermes/bin/src/runtime/host/hermes/localtime/mod.rs rename to hermes/bin/src/runtime_extensions/hermes/localtime/host.rs index 8ee18ae29..67af83d8b 100644 --- a/hermes/bin/src/runtime/host/hermes/localtime/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/localtime/host.rs @@ -1,25 +1,13 @@ -//! Host - Localtime implementations +//! Localtime host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::{ - hermes::localtime::api::{Errno, Host, Localtime, Timezone}, - wasi::clocks::wall_clock::Datetime, - }, - state::{Context, Stateful}, + runtime_extensions::bindings::{ + hermes::localtime::api::{Errno, Host, Localtime, Timezone}, + wasi::clocks::wall_clock::Datetime, }, state::HermesState, }; -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - impl Host for HermesState { /// Get localtime from a datetime or now. /// diff --git a/hermes/bin/src/runtime_extensions/hermes/localtime/mod.rs b/hermes/bin/src/runtime_extensions/hermes/localtime/mod.rs new file mode 100644 index 000000000..9472a28b9 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/localtime/mod.rs @@ -0,0 +1,14 @@ +//! Localtime runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime/host/hermes/logging/mod.rs b/hermes/bin/src/runtime_extensions/hermes/logging/host.rs similarity index 88% rename from hermes/bin/src/runtime/host/hermes/logging/mod.rs rename to hermes/bin/src/runtime_extensions/hermes/logging/host.rs index d872929c4..dd3962815 100644 --- a/hermes/bin/src/runtime/host/hermes/logging/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/logging/host.rs @@ -1,25 +1,13 @@ -//! Host - Logging implementations +//! Logging host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::hermes::{ - json::api::Json, - logging::api::{Host, Level}, - }, - state::{Context, Stateful}, + runtime_extensions::bindings::hermes::{ + json::api::Json, + logging::api::{Host, Level}, }, state::HermesState, }; -/// State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - State {} - } -} - impl Host for HermesState { /// Generate a Log /// diff --git a/hermes/bin/src/runtime_extensions/hermes/logging/mod.rs b/hermes/bin/src/runtime_extensions/hermes/logging/mod.rs new file mode 100644 index 000000000..dc7d340eb --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/logging/mod.rs @@ -0,0 +1,14 @@ +//! Logging runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + State {} + } +} diff --git a/hermes/bin/src/runtime/host/hermes/mod.rs b/hermes/bin/src/runtime_extensions/hermes/mod.rs similarity index 92% rename from hermes/bin/src/runtime/host/hermes/mod.rs rename to hermes/bin/src/runtime_extensions/hermes/mod.rs index ffe732a92..3e01852ed 100644 --- a/hermes/bin/src/runtime/host/hermes/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/mod.rs @@ -1,6 +1,6 @@ -//! Runtime modules - extensions - HERMES custom extensions +//! Hermes runtime extensions implementations - HERMES custom extensions -use crate::runtime::extensions::state::{Context, Stateful}; +use crate::runtime_extensions::state::{Context, Stateful}; pub(crate) mod binary; pub(crate) mod cardano; diff --git a/hermes/bin/src/runtime/extensions/mod.rs b/hermes/bin/src/runtime_extensions/mod.rs similarity index 97% rename from hermes/bin/src/runtime/extensions/mod.rs rename to hermes/bin/src/runtime_extensions/mod.rs index 52aff0da5..da720dfce 100644 --- a/hermes/bin/src/runtime/extensions/mod.rs +++ b/hermes/bin/src/runtime_extensions/mod.rs @@ -15,12 +15,14 @@ use self::bindings::{ use crate::state::HermesState; pub(crate) mod bindings; +pub(crate) mod hermes; pub(crate) mod state; +pub(crate) mod wasi; /// Example of how to call the autogenerated entry points #[allow(dead_code)] fn example() -> anyhow::Result<()> { - use crate::runtime::extensions::state::{Context, Stateful}; + use crate::runtime_extensions::state::{Context, Stateful}; // Configure an `Engine` and compile the `Component` that is being run for // the application. diff --git a/hermes/bin/src/runtime/extensions/state.rs b/hermes/bin/src/runtime_extensions/state.rs similarity index 100% rename from hermes/bin/src/runtime/extensions/state.rs rename to hermes/bin/src/runtime_extensions/state.rs diff --git a/hermes/bin/src/runtime/host/wasi/cli/mod.rs b/hermes/bin/src/runtime_extensions/wasi/cli/host.rs similarity index 80% rename from hermes/bin/src/runtime/host/wasi/cli/mod.rs rename to hermes/bin/src/runtime_extensions/wasi/cli/host.rs index d1237cda5..68f22faec 100644 --- a/hermes/bin/src/runtime/host/wasi/cli/mod.rs +++ b/hermes/bin/src/runtime_extensions/wasi/cli/host.rs @@ -1,25 +1,13 @@ -//! Host - WASI - CLI implementations +//! CLI host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::wasi::{ - cli, - io::streams::{InputStream, OutputStream}, - }, - state::{Context, Stateful}, + runtime_extensions::bindings::wasi::{ + cli, + io::streams::{InputStream, OutputStream}, }, state::HermesState, }; -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} - impl cli::environment::Host for HermesState { /// Get the POSIX-style environment variables. /// diff --git a/hermes/bin/src/runtime_extensions/wasi/cli/mod.rs b/hermes/bin/src/runtime_extensions/wasi/cli/mod.rs new file mode 100644 index 000000000..8aebdf8a8 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/cli/mod.rs @@ -0,0 +1,14 @@ +//! CLI runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/runtime/host/wasi/clocks/mod.rs b/hermes/bin/src/runtime_extensions/wasi/clocks/mod.rs similarity index 87% rename from hermes/bin/src/runtime/host/wasi/clocks/mod.rs rename to hermes/bin/src/runtime_extensions/wasi/clocks/mod.rs index 674319ca3..f7b982f12 100644 --- a/hermes/bin/src/runtime/host/wasi/clocks/mod.rs +++ b/hermes/bin/src/runtime_extensions/wasi/clocks/mod.rs @@ -1,6 +1,6 @@ //! Host - WASI - Clock implementations -use crate::runtime::extensions::state::{Context, Stateful}; +use crate::runtime_extensions::state::{Context, Stateful}; mod monotonic; mod wall; diff --git a/hermes/bin/src/runtime/host/wasi/clocks/monotonic.rs b/hermes/bin/src/runtime_extensions/wasi/clocks/monotonic/host.rs similarity index 61% rename from hermes/bin/src/runtime/host/wasi/clocks/monotonic.rs rename to hermes/bin/src/runtime_extensions/wasi/clocks/monotonic/host.rs index e3e77bbe7..77eb45e4e 100644 --- a/hermes/bin/src/runtime/host/wasi/clocks/monotonic.rs +++ b/hermes/bin/src/runtime_extensions/wasi/clocks/monotonic/host.rs @@ -1,22 +1,10 @@ -//! Host - WASI - monotonic clock implementations +//! Monotonic clock host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::wasi::clocks::monotonic_clock::{Duration, Host, Instant}, - state::{Context, Stateful}, - }, + runtime_extensions::bindings::wasi::clocks::monotonic_clock::{Duration, Host, Instant}, state::HermesState, }; -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} - impl Host for HermesState { /// Read the current value of the clock. /// diff --git a/hermes/bin/src/runtime_extensions/wasi/clocks/monotonic/mod.rs b/hermes/bin/src/runtime_extensions/wasi/clocks/monotonic/mod.rs new file mode 100644 index 000000000..23cf470f0 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/clocks/monotonic/mod.rs @@ -0,0 +1,14 @@ +//! Monotonic clock runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/runtime/host/wasi/clocks/wall.rs b/hermes/bin/src/runtime_extensions/wasi/clocks/wall/host.rs similarity index 77% rename from hermes/bin/src/runtime/host/wasi/clocks/wall.rs rename to hermes/bin/src/runtime_extensions/wasi/clocks/wall/host.rs index 2a25685d7..e6d043eee 100644 --- a/hermes/bin/src/runtime/host/wasi/clocks/wall.rs +++ b/hermes/bin/src/runtime_extensions/wasi/clocks/wall/host.rs @@ -1,22 +1,10 @@ -//! Host - WASI - Wall Clock implementations +//! Wall clock host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::wasi::clocks::wall_clock::{Datetime, Host}, - state::{Context, Stateful}, - }, + runtime_extensions::bindings::wasi::clocks::wall_clock::{Datetime, Host}, state::HermesState, }; -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} - impl Host for HermesState { /// Read the current value of the clock. /// diff --git a/hermes/bin/src/runtime_extensions/wasi/clocks/wall/mod.rs b/hermes/bin/src/runtime_extensions/wasi/clocks/wall/mod.rs new file mode 100644 index 000000000..cfdcad95d --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/clocks/wall/mod.rs @@ -0,0 +1,14 @@ +//! Wall clock runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/runtime/host/wasi/filesystem/mod.rs b/hermes/bin/src/runtime_extensions/wasi/filesystem/host.rs similarity index 96% rename from hermes/bin/src/runtime/host/wasi/filesystem/mod.rs rename to hermes/bin/src/runtime_extensions/wasi/filesystem/host.rs index 60462a1f0..a61460e3b 100644 --- a/hermes/bin/src/runtime/host/wasi/filesystem/mod.rs +++ b/hermes/bin/src/runtime_extensions/wasi/filesystem/host.rs @@ -1,32 +1,20 @@ -//! Host - WASI - Filesystem implementations +//! Filesystem host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::wasi::{ - filesystem::{ - self, - types::{ - Advice, Descriptor, DescriptorFlags, DescriptorStat, DescriptorType, - DirectoryEntry, DirectoryEntryStream, Error, ErrorCode, Filesize, - MetadataHashValue, NewTimestamp, OpenFlags, PathFlags, - }, + runtime_extensions::bindings::wasi::{ + filesystem::{ + self, + types::{ + Advice, Descriptor, DescriptorFlags, DescriptorStat, DescriptorType, + DirectoryEntry, DirectoryEntryStream, Error, ErrorCode, Filesize, + MetadataHashValue, NewTimestamp, OpenFlags, PathFlags, }, - io::streams::{InputStream, OutputStream}, }, - state::{Context, Stateful}, + io::streams::{InputStream, OutputStream}, }, state::HermesState, }; -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} - impl filesystem::types::HostDescriptor for HermesState { /// Return a stream for reading from a file, if available. /// diff --git a/hermes/bin/src/runtime_extensions/wasi/filesystem/mod.rs b/hermes/bin/src/runtime_extensions/wasi/filesystem/mod.rs new file mode 100644 index 000000000..aa77b84c2 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/filesystem/mod.rs @@ -0,0 +1,14 @@ +//! Filesystem runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/runtime/host/wasi/http/mod.rs b/hermes/bin/src/runtime_extensions/wasi/http/host.rs similarity index 96% rename from hermes/bin/src/runtime/host/wasi/http/mod.rs rename to hermes/bin/src/runtime_extensions/wasi/http/host.rs index edc03203f..817a025ce 100644 --- a/hermes/bin/src/runtime/host/wasi/http/mod.rs +++ b/hermes/bin/src/runtime_extensions/wasi/http/host.rs @@ -1,36 +1,24 @@ -//! Host - WASI - HTTP implementations +//! HTTP host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::wasi::{ - http::{ - self, - outgoing_handler::{ - ErrorCode, FutureIncomingResponse, OutgoingRequest, RequestOptions, - }, - types::{ - Duration, FieldKey, FieldValue, Fields, FutureTrailers, HeaderError, Headers, - HostIncomingResponse, HostOutgoingResponse, IncomingBody, IncomingRequest, - IncomingResponse, IoError, Method, OutgoingBody, OutgoingResponse, - ResponseOutparam, Scheme, StatusCode, Trailers, - }, + runtime_extensions::bindings::wasi::{ + http::{ + self, + outgoing_handler::{ + ErrorCode, FutureIncomingResponse, OutgoingRequest, RequestOptions, + }, + types::{ + Duration, FieldKey, FieldValue, Fields, FutureTrailers, HeaderError, Headers, + HostIncomingResponse, HostOutgoingResponse, IncomingBody, IncomingRequest, + IncomingResponse, IoError, Method, OutgoingBody, OutgoingResponse, + ResponseOutparam, Scheme, StatusCode, Trailers, }, - io::streams::{InputStream, OutputStream}, }, - state::{Context, Stateful}, + io::streams::{InputStream, OutputStream}, }, state::HermesState, }; -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} - impl http::types::HostFutureIncomingResponse for HermesState { /// Returns the incoming HTTP Response, or an error, once one is ready. /// diff --git a/hermes/bin/src/runtime_extensions/wasi/http/mod.rs b/hermes/bin/src/runtime_extensions/wasi/http/mod.rs new file mode 100644 index 000000000..a585b9268 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/http/mod.rs @@ -0,0 +1,14 @@ +//! HTTP runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/runtime/host/wasi/io/error.rs b/hermes/bin/src/runtime_extensions/wasi/io/error/host.rs similarity index 71% rename from hermes/bin/src/runtime/host/wasi/io/error.rs rename to hermes/bin/src/runtime_extensions/wasi/io/error/host.rs index 2b0aa8828..c83020e96 100644 --- a/hermes/bin/src/runtime/host/wasi/io/error.rs +++ b/hermes/bin/src/runtime_extensions/wasi/io/error/host.rs @@ -1,22 +1,10 @@ -//! WASI IO Error +//! IO Error host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::wasi::io::error::{Error, Host, HostError}, - state::{Context, Stateful}, - }, + runtime_extensions::bindings::wasi::io::error::{Error, Host, HostError}, state::HermesState, }; -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} - impl HostError for HermesState { /// Returns a string that is suitable to assist humans in debugging /// this error. diff --git a/hermes/bin/src/runtime_extensions/wasi/io/error/mod.rs b/hermes/bin/src/runtime_extensions/wasi/io/error/mod.rs new file mode 100644 index 000000000..2c8a5f9a6 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/io/error/mod.rs @@ -0,0 +1,14 @@ +//! IO Error runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/runtime/host/wasi/io/mod.rs b/hermes/bin/src/runtime_extensions/wasi/io/mod.rs similarity index 87% rename from hermes/bin/src/runtime/host/wasi/io/mod.rs rename to hermes/bin/src/runtime_extensions/wasi/io/mod.rs index 6994734de..ba46e0ec6 100644 --- a/hermes/bin/src/runtime/host/wasi/io/mod.rs +++ b/hermes/bin/src/runtime_extensions/wasi/io/mod.rs @@ -1,6 +1,6 @@ //! Host - WASI IO Implementation -use crate::runtime::extensions::state::{Context, Stateful}; +use crate::runtime_extensions::state::{Context, Stateful}; pub(crate) mod error; pub(crate) mod streams; diff --git a/hermes/bin/src/runtime/host/wasi/io/streams.rs b/hermes/bin/src/runtime_extensions/wasi/io/streams/host.rs similarity index 96% rename from hermes/bin/src/runtime/host/wasi/io/streams.rs rename to hermes/bin/src/runtime_extensions/wasi/io/streams/host.rs index c96645894..945924104 100644 --- a/hermes/bin/src/runtime/host/wasi/io/streams.rs +++ b/hermes/bin/src/runtime_extensions/wasi/io/streams/host.rs @@ -1,24 +1,12 @@ -//! WASI IO Streams +//! IO Streams host implementation for WASM runtime. use crate::{ - runtime::extensions::{ - bindings::wasi::io::streams::{ - Host, HostInputStream, HostOutputStream, InputStream, OutputStream, StreamError, - }, - state::{Context, Stateful}, + runtime_extensions::bindings::wasi::io::streams::{ + Host, HostInputStream, HostOutputStream, InputStream, OutputStream, StreamError, }, state::HermesState, }; -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} - impl HostInputStream for HermesState { /// Perform a non-blocking read from the stream. /// diff --git a/hermes/bin/src/runtime_extensions/wasi/io/streams/mod.rs b/hermes/bin/src/runtime_extensions/wasi/io/streams/mod.rs new file mode 100644 index 000000000..68d0b1cb6 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/io/streams/mod.rs @@ -0,0 +1,14 @@ +//! IO Streams runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/runtime/host/wasi/mod.rs b/hermes/bin/src/runtime_extensions/wasi/mod.rs similarity index 86% rename from hermes/bin/src/runtime/host/wasi/mod.rs rename to hermes/bin/src/runtime_extensions/wasi/mod.rs index f8b5f0a08..3e7afb002 100644 --- a/hermes/bin/src/runtime/host/wasi/mod.rs +++ b/hermes/bin/src/runtime_extensions/wasi/mod.rs @@ -1,6 +1,6 @@ -//! Runtime modules - extensions - WASI standard extensions +//! Hermes runtime extensions implementations - WASI standard extensions -use crate::runtime::extensions::state::{Context, Stateful}; +use crate::runtime_extensions::state::{Context, Stateful}; pub(crate) mod cli; pub(crate) mod clocks; diff --git a/hermes/bin/src/runtime/host/wasi/random/insecure.rs b/hermes/bin/src/runtime_extensions/wasi/random/insecure/host.rs similarity index 71% rename from hermes/bin/src/runtime/host/wasi/random/insecure.rs rename to hermes/bin/src/runtime_extensions/wasi/random/insecure/host.rs index 6fe934459..05efa3e72 100644 --- a/hermes/bin/src/runtime/host/wasi/random/insecure.rs +++ b/hermes/bin/src/runtime_extensions/wasi/random/insecure/host.rs @@ -1,21 +1,6 @@ -//! Insecure RNG +//! Insecure RNG host implementation for WASM runtime. -use crate::{ - runtime::extensions::{ - bindings::wasi::random::insecure::Host, - state::{Context, Stateful}, - }, - state::HermesState, -}; - -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} +use crate::{runtime_extensions::bindings::wasi::random::insecure::Host, state::HermesState}; impl Host for HermesState { /// Return `len` insecure pseudo-random bytes. diff --git a/hermes/bin/src/runtime_extensions/wasi/random/insecure/mod.rs b/hermes/bin/src/runtime_extensions/wasi/random/insecure/mod.rs new file mode 100644 index 000000000..5167521d1 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/random/insecure/mod.rs @@ -0,0 +1,14 @@ +//! Insecure RNG runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/runtime/host/wasi/random/insecure_seed.rs b/hermes/bin/src/runtime_extensions/wasi/random/insecure_seed/host.rs similarity index 76% rename from hermes/bin/src/runtime/host/wasi/random/insecure_seed.rs rename to hermes/bin/src/runtime_extensions/wasi/random/insecure_seed/host.rs index 7f414d6b0..2037d52b7 100644 --- a/hermes/bin/src/runtime/host/wasi/random/insecure_seed.rs +++ b/hermes/bin/src/runtime_extensions/wasi/random/insecure_seed/host.rs @@ -1,21 +1,7 @@ -//! Insecure RNG +//! Insecure RNG seed host implementation for WASM runtime. -use crate::{ - runtime::extensions::{ - bindings::wasi::random::insecure_seed::Host, - state::{Context, Stateful}, - }, - state::HermesState, -}; +use crate::{runtime_extensions::bindings::wasi::random::insecure_seed::Host, state::HermesState}; -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} impl Host for HermesState { /// Return a 128-bit value that may contain a pseudo-random value. /// diff --git a/hermes/bin/src/runtime_extensions/wasi/random/insecure_seed/mod.rs b/hermes/bin/src/runtime_extensions/wasi/random/insecure_seed/mod.rs new file mode 100644 index 000000000..c18a06d7c --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/random/insecure_seed/mod.rs @@ -0,0 +1,14 @@ +//! Insecure RNG seed runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/runtime/host/wasi/random/mod.rs b/hermes/bin/src/runtime_extensions/wasi/random/mod.rs similarity index 90% rename from hermes/bin/src/runtime/host/wasi/random/mod.rs rename to hermes/bin/src/runtime_extensions/wasi/random/mod.rs index 416a6e6b6..a1e32999e 100644 --- a/hermes/bin/src/runtime/host/wasi/random/mod.rs +++ b/hermes/bin/src/runtime_extensions/wasi/random/mod.rs @@ -1,6 +1,6 @@ //! Host - WASI - Random implementations -use crate::runtime::extensions::state::{Context, Stateful}; +use crate::runtime_extensions::state::{Context, Stateful}; pub(crate) mod insecure; pub(crate) mod insecure_seed; diff --git a/hermes/bin/src/runtime/host/wasi/random/secure.rs b/hermes/bin/src/runtime_extensions/wasi/random/secure/host.rs similarity index 79% rename from hermes/bin/src/runtime/host/wasi/random/secure.rs rename to hermes/bin/src/runtime_extensions/wasi/random/secure/host.rs index 878ff8dd2..93f0f9c1e 100644 --- a/hermes/bin/src/runtime/host/wasi/random/secure.rs +++ b/hermes/bin/src/runtime_extensions/wasi/random/secure/host.rs @@ -1,21 +1,6 @@ -//! Random RNG +//! Random RNG host implementation for WASM runtime. -use crate::{ - runtime::extensions::{ - bindings::wasi::random::random::Host, - state::{Context, Stateful}, - }, - state::HermesState, -}; - -/// WASI State -pub(crate) struct State {} - -impl Stateful for State { - fn new(_ctx: &Context) -> Self { - Self {} - } -} +use crate::{runtime_extensions::bindings::wasi::random::random::Host, state::HermesState}; impl Host for HermesState { /// Return `len` cryptographically-secure random or pseudo-random bytes. diff --git a/hermes/bin/src/runtime_extensions/wasi/random/secure/mod.rs b/hermes/bin/src/runtime_extensions/wasi/random/secure/mod.rs new file mode 100644 index 000000000..f98cb3bb0 --- /dev/null +++ b/hermes/bin/src/runtime_extensions/wasi/random/secure/mod.rs @@ -0,0 +1,14 @@ +//! Random RNG runtime extension implementation. + +use crate::runtime_extensions::state::{Context, Stateful}; + +mod host; + +/// WASI State +pub(crate) struct State {} + +impl Stateful for State { + fn new(_ctx: &Context) -> Self { + Self {} + } +} diff --git a/hermes/bin/src/state.rs b/hermes/bin/src/state.rs index e5b1d9401..131116755 100644 --- a/hermes/bin/src/state.rs +++ b/hermes/bin/src/state.rs @@ -1,8 +1,9 @@ //! Hermes state implementation. -use crate::runtime::{ - extensions::state::{Context, Stateful}, - host::{hermes, wasi}, +use crate::runtime_extensions::{ + hermes, + state::{Context, Stateful}, + wasi, }; #[allow(dead_code)] diff --git a/hermes/bin/src/wasm/module.rs b/hermes/bin/src/wasm/module.rs index f354694bc..febd36a31 100644 --- a/hermes/bin/src/wasm/module.rs +++ b/hermes/bin/src/wasm/module.rs @@ -11,7 +11,7 @@ use wasmtime::{ use crate::{ event_queue::event::HermesEventPayload, - runtime::extensions::{ + runtime_extensions::{ bindings, state::{Context, Stateful}, }, @@ -29,9 +29,9 @@ struct BadWASMModuleError(String); /// It is used to interact with the WASM module. pub(crate) struct ModuleInstance { /// `wasmtime::Store` entity - pub(crate) _store: WasmStore, + pub(crate) store: WasmStore, /// `Instance` entity - pub(crate) _instance: bindings::Hermes, + pub(crate) instance: bindings::Hermes, } /// Structure defines an abstraction over the WASM module @@ -94,7 +94,7 @@ impl Module { /// # Errors /// - `BadModuleError` #[allow(dead_code)] - pub(crate) fn execute_event(&mut self, event: &impl HermesEventPayload) -> anyhow::Result<()> { + pub(crate) fn execute_event(&mut self, event: &dyn HermesEventPayload) -> anyhow::Result<()> { self.context.use_for(event.event_name().to_string()); let state = HermesState::new(&self.context); @@ -102,10 +102,7 @@ impl Module { let (instance, _) = bindings::Hermes::instantiate_pre(&mut store, &self.pre_instance) .map_err(|e| BadWASMModuleError(e.to_string()))?; - event.execute(&mut ModuleInstance { - _instance: instance, - _store: store, - })?; + event.execute(&mut ModuleInstance { store, instance })?; Ok(()) } } diff --git a/wasm/wasi/wit/deps/hermes-cardano/api.wit b/wasm/wasi/wit/deps/hermes-cardano/api.wit index 77a419a25..525e53ccf 100644 --- a/wasm/wasi/wit/deps/hermes-cardano/api.wit +++ b/wasm/wasi/wit/deps/hermes-cardano/api.wit @@ -24,6 +24,13 @@ interface api { local-test-blockchain // A local isolated test blockchain. } + /// Source information about where the block came from, and if we are at tip or not. + flags block-src { + tip, + node, + mithril + } + /// The Slot number to interact with variant slot { genesis, // The very start of the blockchain. diff --git a/wasm/wasi/wit/deps/hermes-cardano/event.wit b/wasm/wasi/wit/deps/hermes-cardano/event.wit index 780e06deb..5cbee8775 100644 --- a/wasm/wasi/wit/deps/hermes-cardano/event.wit +++ b/wasm/wasi/wit/deps/hermes-cardano/event.wit @@ -22,13 +22,7 @@ /// Cardano API Interface - Export ONLY interface event-on-block { - use api.{cardano-blockchain-id, cardano-block}; - - flags block-src { - tip, - node, - mithril - } + use api.{cardano-blockchain-id, cardano-block, block-src}; /// Triggered when a cardano block event fires. /// @@ -43,7 +37,7 @@ interface event-on-block { /// Returns: /// Nothing. /// - on-cardano-block: func(blockchain: cardano-blockchain-id, block: cardano-block, source:block-src); + on-cardano-block: func(blockchain: cardano-blockchain-id, block: cardano-block, source: block-src); } /// Cardano API Interface - Export ONLY @@ -64,7 +58,7 @@ interface event-on-txn { /// Returns: /// Nothing. /// - on-cardano-txn: func(blockchain: cardano-blockchain-id, slot:u64, txn-index: u32, txn: cardano-txn); + on-cardano-txn: func(blockchain: cardano-blockchain-id, slot: u64, txn-index: u32, txn: cardano-txn); } /// Cardano API Interface - Export ONLY @@ -83,7 +77,7 @@ interface event-on-rollback { /// Returns: /// Nothing. /// - on-cardano-rollback: func(blockchain: cardano-blockchain-id, slot:u64); + on-cardano-rollback: func(blockchain: cardano-blockchain-id, slot: u64); }