feat(rpc): impl parity trace_transaction (#1765)

This commit is contained in:
Matthias Seitz
2023-03-15 15:03:42 +01:00
committed by GitHub
parent bba61c0b61
commit 0c434e7916
12 changed files with 349 additions and 130 deletions

View File

@@ -10,6 +10,20 @@ use std::collections::BTreeMap;
/// Result type for parity style transaction trace
pub type TraceResult = crate::trace::common::TraceResult<TraceOutput, String>;
// === impl TraceResult ===
impl TraceResult {
/// Wraps the result type in a [TraceResult::Success] variant
pub fn parity_success(result: TraceOutput) -> Self {
TraceResult::Success { result }
}
/// Wraps the result type in a [TraceResult::Error] variant
pub fn parity_error(error: String) -> Self {
TraceResult::Error { error }
}
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum TraceType {
@@ -190,10 +204,18 @@ pub struct TransactionTrace {
pub struct LocalizedTransactionTrace {
#[serde(flatten)]
pub trace: TransactionTrace,
/// Transaction index within the block, None if pending.
pub transaction_position: Option<usize>,
/// Hash of the transaction
pub transaction_hash: Option<H256>,
pub block_number: U64,
pub block_hash: H256,
/// Block number the transaction is included in, None if pending.
///
/// Note: this deviates from <https://openethereum.github.io/JSONRPC-trace-module#trace_transaction> which always returns a block number
pub block_number: Option<u64>,
/// Hash of the block, if not pending
///
/// Note: this deviates from <https://openethereum.github.io/JSONRPC-trace-module#trace_transaction> which always returns a block number
pub block_hash: Option<H256>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]

View File

@@ -0,0 +1,17 @@
//! Commonly used additional types that are not part of the JSON RPC spec but are often required
//! when working with RPC types, such as [Transaction](crate::Transaction)
use reth_primitives::{TxHash, H256};
/// Additional fields in the context of a block that contains this transaction.
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
pub struct TransactionInfo {
/// Hash of the transaction.
pub hash: Option<TxHash>,
/// Index of the transaction in the block
pub index: Option<usize>,
/// Hash of the block.
pub block_hash: Option<H256>,
/// Number of the block.
pub block_number: Option<u64>,
}

View File

@@ -1,8 +1,10 @@
mod common;
mod receipt;
mod request;
mod signature;
mod typed;
pub use common::TransactionInfo;
pub use receipt::TransactionReceipt;
pub use request::TransactionRequest;
pub use signature::Signature;