Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add helpers for trace action #982

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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