From 3a4419625a5ea176640ea6c0a3670883a60d76a2 Mon Sep 17 00:00:00 2001 From: Resende <17102689+ZePedroResende@users.noreply.github.com> Date: Tue, 1 Aug 2023 11:42:08 +0100 Subject: [PATCH] feat(rpc): ots_getBlockDetails and ots_getBlockDetailsByHash (#4007) --- crates/rpc/rpc-builder/tests/it/http.rs | 11 +++++------ crates/rpc/rpc-types/src/eth/block.rs | 1 + crates/rpc/rpc-types/src/otterscan.rs | 26 +++++++++++++++++++++++-- crates/rpc/rpc/src/otterscan.rs | 6 ++++-- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/crates/rpc/rpc-builder/tests/it/http.rs b/crates/rpc/rpc-builder/tests/it/http.rs index 09dbc52cb254..9dbfb2136f02 100644 --- a/crates/rpc/rpc-builder/tests/it/http.rs +++ b/crates/rpc/rpc-builder/tests/it/http.rs @@ -206,12 +206,11 @@ where assert!(is_unimplemented( OtterscanClient::trace_transaction(client, tx_hash).await.err().unwrap() )); - assert!(is_unimplemented( - OtterscanClient::get_block_details(client, block_number,).await.err().unwrap() - )); - assert!(is_unimplemented( - OtterscanClient::get_block_details_by_hash(client, block_hash).await.err().unwrap() - )); + + OtterscanClient::get_block_details(client, block_number).await.unwrap(); + + OtterscanClient::get_block_details_by_hash(client, block_hash).await.unwrap(); + assert!(is_unimplemented( OtterscanClient::get_block_transactions(client, block_number, page_number, page_size,) .await diff --git a/crates/rpc/rpc-types/src/eth/block.rs b/crates/rpc/rpc-types/src/eth/block.rs index 5b07b300878f..fbb6a06b62e6 100644 --- a/crates/rpc/rpc-types/src/eth/block.rs +++ b/crates/rpc/rpc-types/src/eth/block.rs @@ -20,6 +20,7 @@ pub enum BlockTransactions { /// Special case for uncle response. Uncle, } + impl BlockTransactions { /// Check if the enum variant is /// used for an uncle response. diff --git a/crates/rpc/rpc-types/src/otterscan.rs b/crates/rpc/rpc-types/src/otterscan.rs index 57e12e8bf123..4c2c57223926 100644 --- a/crates/rpc/rpc-types/src/otterscan.rs +++ b/crates/rpc/rpc-types/src/otterscan.rs @@ -1,4 +1,4 @@ -use crate::{Block, Transaction, TransactionReceipt}; +use crate::{Block, BlockTransactions, Rich, Transaction, TransactionReceipt}; use reth_primitives::{Address, Bytes, U256}; use serde::{Deserialize, Serialize}; @@ -36,7 +36,7 @@ pub struct TraceEntry { } /// Internal issuance struct for `BlockDetails` struct -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub struct InternalIssuance { block_reward: U256, @@ -95,3 +95,25 @@ pub struct ContractCreator { tx: Transaction, 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(), + } + } +} diff --git a/crates/rpc/rpc/src/otterscan.rs b/crates/rpc/rpc/src/otterscan.rs index 767b3657ad79..7afcf2d545ae 100644 --- a/crates/rpc/rpc/src/otterscan.rs +++ b/crates/rpc/rpc/src/otterscan.rs @@ -59,12 +59,14 @@ where &self, block_number: BlockNumberOrTag, ) -> RpcResult> { - Err(internal_rpc_err("unimplemented")) + let block = self.eth.block_by_number(block_number, true).await?; + Ok(block.map(Into::into)) } /// Handler for `getBlockDetailsByHash` async fn get_block_details_by_hash(&self, block_hash: H256) -> RpcResult> { - Err(internal_rpc_err("unimplemented")) + let block = self.eth.block_by_hash(block_hash, true).await?; + Ok(block.map(Into::into)) } /// Handler for `getBlockTransactions`