use crate::to_rpc_params_impl; use derive_more::{Constructor, From}; use jsonrpsee::core::traits::ToRpcParams; use serde::{Deserialize, Serialize}; pub use ethereum_types::{H160, H256, U64}; /// Partial RPC response for `eth_getTransactionReceipt`. /// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct GetTransactionReceiptResponse { pub block_hash: H256, pub block_number: U64, pub status: U64, pub logs: Vec, } /// Request args for `eth_getTransactionReceipt`. /// pub struct GetTransactionReceiptARgs { pub transaction_hash: H256, } /// Partial RPC response for `eth_getBlockByNumber`. /// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] pub struct GetBlockByNumberResponse { /// the block number pub number: U64, /// the canonical block hash at this block number pub hash: H256, } /// Partial RPC arguments for `eth_getBlockByNumber`. /// #[derive( Constructor, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, )] pub struct GetBlockByNumberArgs(BlockNumberOrTag, ReturnFullTransactionObjects); /// First argument to `eth_getBlockByNumber`: either a finality tag or a concrete block number. /// Per the JSON-RPC spec the value is serialized as a string — finality tags as their lowercase /// name, block numbers as `0x`-prefixed hex. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(untagged)] pub enum BlockNumberOrTag { Tag(FinalityTag), Number(U64), } impl From for BlockNumberOrTag { fn from(tag: FinalityTag) -> Self { Self::Tag(tag) } } impl From for BlockNumberOrTag { fn from(number: U64) -> Self { Self::Number(number) } } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum FinalityTag { Safe, Finalized, Latest, } #[derive(From, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] pub struct ReturnFullTransactionObjects(bool); impl Serialize for GetTransactionReceiptARgs { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { let request_parameters = [self.transaction_hash]; request_parameters.serialize(serializer) } } /// An Ethereum log entry as defined in return /// section of #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Log { pub removed: bool, pub log_index: U64, pub transaction_index: U64, pub transaction_hash: H256, pub block_hash: H256, pub block_number: U64, pub address: H160, pub data: String, pub topics: Vec, } impl ToRpcParams for &GetTransactionReceiptARgs { to_rpc_params_impl!(); } impl ToRpcParams for &GetBlockByNumberArgs { to_rpc_params_impl!(); }