From 612ad384a47943e1a91777dad94a397bd0892671 Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Sun, 12 Jul 2026 07:24:55 -0400 Subject: [PATCH] refactor: format lookup stages via Display --- src/retrieval/failure.rs | 3 ++- src/retrieval/types.rs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/retrieval/failure.rs b/src/retrieval/failure.rs index 2952fa7..4973d46 100644 --- a/src/retrieval/failure.rs +++ b/src/retrieval/failure.rs @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: 2025 Semiotic AI, Inc. +// SPDX-FileCopyrightText: 2026 Joseph Livesey // // SPDX-License-Identifier: Apache-2.0 @@ -91,7 +92,7 @@ pub(crate) fn lookup_request_failed( error: TransportError, ) -> RetrievalError { RetrievalError::Rpc(crate::errors::RpcError::request_failed( - format!("{operation}({tx_hash})", operation = stage.operation_name()), + format!("{stage}({tx_hash})"), error, )) } diff --git a/src/retrieval/types.rs b/src/retrieval/types.rs index 91ea9fb..ced9eb3 100644 --- a/src/retrieval/types.rs +++ b/src/retrieval/types.rs @@ -1,9 +1,12 @@ // SPDX-FileCopyrightText: 2025 Semiotic AI, Inc. +// SPDX-FileCopyrightText: 2026 Joseph Livesey // // SPDX-License-Identifier: Apache-2.0 //! Data types for combined gas and amount retrieval +use std::fmt; + use alloy_chains::NamedChain; use alloy_primitives::{Address, BlockNumber, TxHash, U256}; use serde::{Deserialize, Serialize}; @@ -48,6 +51,7 @@ pub enum CombinedDataLookupStage { } impl CombinedDataLookupStage { + /// Stable RPC operation label used in logs and operator-facing errors. #[must_use] pub const fn operation_name(self) -> &'static str { match self { @@ -57,6 +61,12 @@ impl CombinedDataLookupStage { } } +impl fmt::Display for CombinedDataLookupStage { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + formatter.write_str((*self).operation_name()) + } +} + /// Which pass produced a lookup error while enriching a decoded transfer log. #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] pub enum CombinedDataLookupPass { @@ -249,6 +259,18 @@ mod tests { } } + #[test] + fn test_combined_lookup_stage_display_matches_rpc_operation_name() { + assert_eq!( + CombinedDataLookupStage::Transaction.to_string(), + "get_transaction_by_hash" + ); + assert_eq!( + CombinedDataLookupStage::Receipt.to_string(), + "get_transaction_receipt" + ); + } + #[test] fn test_total_gas_cost_basic() { // Test basic calculation with L2 gas only