From d60c040db902504bd63902c3404d2f2eea0be6e4 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 24 Sep 2024 20:58:55 +0200 Subject: [PATCH] rpc: add OtterscanTxResp trait --- crates/network-primitives/src/lib.rs | 4 +++- crates/network-primitives/src/traits.rs | 6 ++++++ crates/rpc-types-eth/src/transaction/mod.rs | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/network-primitives/src/lib.rs b/crates/network-primitives/src/lib.rs index 6012668a3dd..c04f64444b2 100644 --- a/crates/network-primitives/src/lib.rs +++ b/crates/network-primitives/src/lib.rs @@ -10,7 +10,9 @@ extern crate alloc; mod traits; -pub use traits::{BlockResponse, HeaderResponse, ReceiptResponse, TransactionResponse}; +pub use traits::{ + BlockResponse, HeaderResponse, OtterscanTxResp, ReceiptResponse, TransactionResponse, +}; mod block; pub use block::{BlockTransactionHashes, BlockTransactions, BlockTransactionsKind}; diff --git a/crates/network-primitives/src/traits.rs b/crates/network-primitives/src/traits.rs index fe8dd988711..7e1fa82d6a2 100644 --- a/crates/network-primitives/src/traits.rs +++ b/crates/network-primitives/src/traits.rs @@ -62,6 +62,12 @@ pub trait ReceiptResponse { fn state_root(&self) -> Option; } +/// Extension trait for [`TransactionResponse`] to support Otterscan-specific API. +pub trait OtterscanTxResp: TransactionResponse { + /// Truncate the input for Otterscan API. + fn otterscan_api_truncate_input(&mut self); +} + /// Transaction JSON-RPC response. pub trait TransactionResponse { /// Signature type of the transaction diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index c1432f1d1da..9bb186b05a8 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -5,7 +5,7 @@ use alloy_consensus::{ TxEnvelope, TxLegacy, TxType, }; use alloy_eips::eip7702::SignedAuthorization; -use alloy_network_primitives::TransactionResponse; +use alloy_network_primitives::{OtterscanTxResp, TransactionResponse}; use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxHash, TxKind, B256, U256}; use alloc::vec::Vec; @@ -338,6 +338,12 @@ impl TryFrom for TxEnvelope { } } +impl OtterscanTxResp for Transaction { + fn otterscan_api_truncate_input(&mut self) { + self.input = self.input.slice(..4); + } +} + impl TransactionResponse for Transaction { type Signature = Signature;