From 60cd429bd036c16f1e1f23ec7950689ad9819c76 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 26 Jun 2024 22:36:21 +0200 Subject: [PATCH] feat: add helpers for trace action (#982) --- crates/rpc-types-trace/src/parity.rs | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/crates/rpc-types-trace/src/parity.rs b/crates/rpc-types-trace/src/parity.rs index 55feda41208..caadcd18cc9 100644 --- a/crates/rpc-types-trace/src/parity.rs +++ b/crates/rpc-types-trace/src/parity.rs @@ -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. @@ -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 {