-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Matthias Seitz <[email protected]>
- Loading branch information
Showing
3 changed files
with
52 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,36 @@ | ||
//! Types used by tracing backends | ||
use alloy_primitives::TxHash; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The result of a single transaction trace. | ||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
#[allow(missing_docs)] | ||
#[serde(untagged, rename_all = "camelCase")] | ||
pub enum TraceResult<Ok, Err> { | ||
/// Untagged success variant | ||
Success { result: Ok }, | ||
Success { | ||
/// Trace results produced by the tracer | ||
result: Ok, | ||
/// transaction hash | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
tx_hash: Option<TxHash>, | ||
}, | ||
/// Untagged error variant | ||
Error { error: Err }, | ||
Error { | ||
/// Trace failure produced by the tracer | ||
error: Err, | ||
/// transaction hash | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
tx_hash: Option<TxHash>, | ||
}, | ||
} | ||
|
||
impl<Ok, Err> TraceResult<Ok, Err> { | ||
/// Returns the hash of the transaction that was traced. | ||
pub fn tx_hash(&self) -> Option<TxHash> { | ||
*match self { | ||
TraceResult::Success { tx_hash, .. } => tx_hash, | ||
TraceResult::Error { tx_hash, .. } => tx_hash, | ||
} | ||
} | ||
} |
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