Skip to content

Commit

Permalink
feat: add helpers for trace action (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jun 26, 2024
1 parent 1376683 commit 60cd429
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion crates/rpc-types-trace/src/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use std::{
};

/// Different Trace diagnostic targets.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum TraceType {
/// Default trace
#[default]
Trace,
/// Provides a full trace of the VM’s state throughout the execution of the transaction,
/// including for any subcalls.
Expand Down Expand Up @@ -199,6 +200,38 @@ impl Action {
matches!(self, Self::Reward(_))
}

/// Returns the [`CallAction`] if it is [`Action::Call`]
pub const fn as_call(&self) -> Option<&CallAction> {
match self {
Self::Call(action) => Some(action),
_ => None,
}
}

/// Returns the [`CreateAction`] if it is [`Action::Create`]
pub const fn as_create(&self) -> Option<&CreateAction> {
match self {
Self::Create(action) => Some(action),
_ => None,
}
}

/// Returns the [`SelfdestructAction`] if it is [`Action::Selfdestruct`]
pub const fn as_selfdestruct(&self) -> Option<&SelfdestructAction> {
match self {
Self::Selfdestruct(action) => Some(action),
_ => None,
}
}

/// Returns the [`RewardAction`] if it is [`Action::Reward`]
pub const fn as_reward(&self) -> Option<&RewardAction> {
match self {
Self::Reward(action) => Some(action),
_ => None,
}
}

/// Returns what kind of action this is
pub const fn kind(&self) -> ActionType {
match self {
Expand Down

0 comments on commit 60cd429

Please sign in to comment.