diff --git a/crates/rpc-trace-types/src/lib.rs b/crates/rpc-trace-types/src/lib.rs index 5e5b08f26e5..5e52a1ccf7a 100644 --- a/crates/rpc-trace-types/src/lib.rs +++ b/crates/rpc-trace-types/src/lib.rs @@ -19,5 +19,6 @@ pub mod common; pub mod filter; pub mod geth; pub mod opcode; +pub mod otterscan; pub mod parity; pub mod tracerequest; diff --git a/crates/rpc-trace-types/src/otterscan.rs b/crates/rpc-trace-types/src/otterscan.rs new file mode 100644 index 00000000000..9ae9cae9792 --- /dev/null +++ b/crates/rpc-trace-types/src/otterscan.rs @@ -0,0 +1,126 @@ +#![allow(missing_docs)] + +use alloy_primitives::{Address, Bytes, U256}; +use alloy_rpc_types::{ + serde_helpers::u64_hex, Block, BlockTransactions, Rich, Transaction, TransactionReceipt, +}; +use serde::{Deserialize, Serialize}; + +/// Operation type enum for `InternalOperation` struct +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[allow(missing_copy_implementations)] +pub enum OperationType { + /// Operation Transfer + OpTransfer = 0, + /// Operation Contract self destruct + OpSelfDestruct = 1, + /// Operation Create + OpCreate = 2, + /// Operation Create2 + OpCreate2 = 3, +} + +/// Custom struct for otterscan `getInternalOperations` RPC response +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct InternalOperation { + pub r#type: OperationType, + pub from: Address, + pub to: Address, + pub value: U256, +} + +/// Custom struct for otterscan `traceTransaction` RPC response +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct TraceEntry { + pub r#type: String, + pub depth: u32, + pub from: Address, + pub to: Address, + pub value: U256, + pub input: Bytes, +} + +/// Internal issuance struct for `BlockDetails` struct +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Default)] +#[allow(missing_copy_implementations)] +#[serde(rename_all = "camelCase")] +pub struct InternalIssuance { + pub block_reward: U256, + pub uncle_reward: U256, + pub issuance: U256, +} + +/// Custom `Block` struct that includes transaction count for Otterscan responses +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct OtsBlock { + #[serde(flatten)] + pub block: Block, + pub transaction_count: usize, +} + +/// Custom struct for otterscan `getBlockDetails` RPC response +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct BlockDetails { + pub block: OtsBlock, + pub issuance: InternalIssuance, + pub total_fees: U256, +} + +/// Custom transaction receipt struct for otterscan `OtsBlockTransactions` struct +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct OtsTransactionReceipt { + #[serde(flatten)] + pub receipt: TransactionReceipt, + #[serde(with = "u64_hex")] + pub timestamp: u64, +} + +/// Custom struct for otterscan `getBlockTransactions` RPC response +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct OtsBlockTransactions { + pub fullblock: OtsBlock, + pub receipts: Vec, +} + +/// Custom struct for otterscan `searchTransactionsAfter`and `searchTransactionsBefore` RPC +/// responses +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct TransactionsWithReceipts { + pub txs: Vec, + pub receipts: Vec, + pub first_page: bool, + pub last_page: bool, +} + +/// Custom struct for otterscan `getContractCreator` RPC responses +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ContractCreator { + pub tx: Transaction, + pub creator: Address, +} + +impl From for OtsBlock { + fn from(block: Block) -> Self { + let transaction_count = match &block.transactions { + BlockTransactions::Full(t) => t.len(), + BlockTransactions::Hashes(t) => t.len(), + BlockTransactions::Uncle => 0, + }; + + Self { block, transaction_count } + } +} + +impl From> for BlockDetails { + fn from(rich_block: Rich) -> Self { + Self { + block: rich_block.inner.into(), + issuance: Default::default(), + total_fees: U256::default(), + } + } +}