reth_rpc_types_compat/
transaction.rs

1//! Compatibility functions for rpc `Transaction` type.
2
3use alloy_consensus::transaction::Recovered;
4use alloy_rpc_types_eth::{request::TransactionRequest, TransactionInfo};
5use core::error;
6use serde::{Deserialize, Serialize};
7use std::fmt;
8
9/// Builds RPC transaction w.r.t. network.
10pub trait TransactionCompat<T>: Send + Sync + Unpin + Clone + fmt::Debug {
11    /// RPC transaction response type.
12    type Transaction: Serialize
13        + for<'de> Deserialize<'de>
14        + Send
15        + Sync
16        + Unpin
17        + Clone
18        + fmt::Debug;
19
20    /// RPC transaction error type.
21    type Error: error::Error + Into<jsonrpsee_types::ErrorObject<'static>>;
22
23    /// Wrapper for `fill()` with default `TransactionInfo`
24    /// Create a new rpc transaction result for a _pending_ signed transaction, setting block
25    /// environment related fields to `None`.
26    fn fill_pending(&self, tx: Recovered<T>) -> Result<Self::Transaction, Self::Error> {
27        self.fill(tx, TransactionInfo::default())
28    }
29
30    /// Create a new rpc transaction result for a mined transaction, using the given block hash,
31    /// number, and tx index fields to populate the corresponding fields in the rpc result.
32    ///
33    /// The block hash, number, and tx index fields should be from the original block where the
34    /// transaction was mined.
35    fn fill(
36        &self,
37        tx: Recovered<T>,
38        tx_inf: TransactionInfo,
39    ) -> Result<Self::Transaction, Self::Error>;
40
41    /// Builds a fake transaction from a transaction request for inclusion into block built in
42    /// `eth_simulateV1`.
43    fn build_simulate_v1_transaction(&self, request: TransactionRequest) -> Result<T, Self::Error>;
44
45    /// Truncates the input of a transaction to only the first 4 bytes.
46    // todo: remove in favour of using constructor on `TransactionResponse` or similar
47    // <https://github.com/alloy-rs/alloy/issues/1315>.
48    fn otterscan_api_truncate_input(tx: &mut Self::Transaction);
49}