-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from 0xPolygonMiden/frisitano-event-vault-delta
Introduce host event handling
- Loading branch information
Showing
19 changed files
with
401 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
mod account_stub; | ||
pub use account_stub::{ | ||
extract_account_storage_delta, extract_account_vault_delta, parse_final_account_stub, | ||
}; | ||
pub use account_stub::{extract_account_storage_delta, parse_final_account_stub}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use miden_objects::{accounts::AccountVaultDelta, transaction::Event}; | ||
use vm_processor::{ExecutionError, HostResponse, ProcessState}; | ||
|
||
mod vault_delta; | ||
use vault_delta::AccountVaultDeltaHandler; | ||
|
||
/// The [EventHandler] is responsible for handling events emitted by a transaction. | ||
/// | ||
/// It is composed of multiple sub-handlers, each of which is responsible for handling specific | ||
/// event types. The event handler has access to the [ProcessState] at the time the event was | ||
/// emitted, and can use it to extract the data required to handle the event. | ||
/// | ||
/// Below we define the sub-handlers and their associated event types: | ||
/// | ||
/// - [VaultDeltaHandler]: | ||
/// - [Event::AddAssetToAccountVault] | ||
/// - [Event::RemoveAssetFromAccountVault] | ||
#[derive(Default, Debug)] | ||
pub struct EventHandler { | ||
acct_vault_delta_handler: AccountVaultDeltaHandler, | ||
} | ||
|
||
impl EventHandler { | ||
/// Handles the event with the provided event ID. | ||
pub fn handle_event<S: ProcessState>( | ||
&mut self, | ||
process: &S, | ||
event_id: u32, | ||
) -> Result<HostResponse, ExecutionError> { | ||
match Event::try_from(event_id)? { | ||
Event::AddAssetToAccountVault => self.acct_vault_delta_handler.add_asset(process), | ||
Event::RemoveAssetFromAccountVault => { | ||
self.acct_vault_delta_handler.remove_asset(process) | ||
} | ||
} | ||
} | ||
|
||
/// Consumes the [EventHandler] and finalizes the sub-handlers it is composed of. | ||
/// | ||
/// Returns the result of finalizing the sub-handlers. | ||
pub fn finalize(self) -> AccountVaultDelta { | ||
self.acct_vault_delta_handler.finalize() | ||
} | ||
} |
Oops, something went wrong.