|
1 | 1 | //! Types used by tracing backends
|
2 | 2 |
|
| 3 | +use alloy_primitives::TxHash; |
3 | 4 | use serde::{Deserialize, Serialize};
|
4 | 5 |
|
5 | 6 | /// The result of a single transaction trace.
|
6 | 7 | #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
7 |
| -#[serde(untagged)] |
8 |
| -#[allow(missing_docs)] |
| 8 | +#[serde(untagged, rename_all = "camelCase")] |
9 | 9 | pub enum TraceResult<Ok, Err> {
|
10 | 10 | /// Untagged success variant
|
11 |
| - Success { result: Ok }, |
| 11 | + Success { |
| 12 | + /// Trace results produced by the tracer |
| 13 | + result: Ok, |
| 14 | + /// transaction hash |
| 15 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 16 | + tx_hash: Option<TxHash>, |
| 17 | + }, |
12 | 18 | /// Untagged error variant
|
13 |
| - Error { error: Err }, |
| 19 | + Error { |
| 20 | + /// Trace failure produced by the tracer |
| 21 | + error: Err, |
| 22 | + /// transaction hash |
| 23 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 24 | + tx_hash: Option<TxHash>, |
| 25 | + }, |
| 26 | +} |
| 27 | + |
| 28 | +impl<Ok, Err> TraceResult<Ok, Err> { |
| 29 | + /// Returns the hash of the transaction that was traced. |
| 30 | + pub fn tx_hash(&self) -> Option<TxHash> { |
| 31 | + *match self { |
| 32 | + TraceResult::Success { tx_hash, .. } => tx_hash, |
| 33 | + TraceResult::Error { tx_hash, .. } => tx_hash, |
| 34 | + } |
| 35 | + } |
14 | 36 | }
|
0 commit comments