-
Notifications
You must be signed in to change notification settings - Fork 57
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 #404 from 0xPolygonMiden/bobbin-tx-events
Transaction host refactoring
- Loading branch information
Showing
12 changed files
with
142 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use core::fmt; | ||
|
||
// TRANSACTION EVENT PARSING ERROR | ||
// ================================================================================================ | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq)] | ||
pub enum TransactionEventParsingError { | ||
InvalidTransactionEvent(u32), | ||
NotTransactionEvent(u32), | ||
} | ||
|
||
impl fmt::Display for TransactionEventParsingError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::InvalidTransactionEvent(event_id) => { | ||
write!(f, "event {event_id} is not a valid transaction kernel event") | ||
}, | ||
Self::NotTransactionEvent(event_id) => { | ||
write!(f, "event {event_id} is not a transaction kernel event") | ||
}, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl std::error::Error for TransactionEventParsingError {} |
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,47 @@ | ||
use core::fmt; | ||
|
||
use super::TransactionEventParsingError; | ||
|
||
// TRANSACTION EVENT | ||
// ================================================================================================ | ||
|
||
/// Events which may be emitted by a transaction kernel. | ||
/// | ||
/// The events are emitted via the `emit.<event_id>` instruction. The event ID is a 32-bit | ||
/// unsigned integer which is used to identify the event type. For events emitted by the | ||
/// transaction kernel, the event_id is structured as follows: | ||
/// - The upper 16 bits of the event ID are set to 2. | ||
/// - The lower 16 bits represent a unique event ID within the transaction kernel. | ||
#[repr(u32)] | ||
#[derive(Debug, Clone, Eq, PartialEq)] | ||
pub enum TransactionEvent { | ||
AddAssetToAccountVault = 0x2_0000, // 131072 | ||
RemoveAssetFromAccountVault = 0x2_0001, // 131073 | ||
} | ||
|
||
impl TransactionEvent { | ||
/// Value of the top 16 bits of a transaction kernel event ID. | ||
pub const EVENT_ID_PREFIX: u16 = 2; | ||
} | ||
|
||
impl fmt::Display for TransactionEvent { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{self:?}") | ||
} | ||
} | ||
|
||
impl TryFrom<u32> for TransactionEvent { | ||
type Error = TransactionEventParsingError; | ||
|
||
fn try_from(value: u32) -> Result<Self, Self::Error> { | ||
if value >> 16 != Self::EVENT_ID_PREFIX as u32 { | ||
return Err(TransactionEventParsingError::NotTransactionEvent(value)); | ||
} | ||
|
||
match value { | ||
0x2_0000 => Ok(TransactionEvent::AddAssetToAccountVault), | ||
0x2_0001 => Ok(TransactionEvent::RemoveAssetFromAccountVault), | ||
_ => Err(TransactionEventParsingError::InvalidTransactionEvent(value)), | ||
} | ||
} | ||
} |
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
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.