Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): ots_getBlockDetails and ots_getBlockDetailsByHash #4007

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions crates/rpc/rpc-builder/tests/it/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc-types/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 24 additions & 2 deletions crates/rpc/rpc-types/src/otterscan.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -95,3 +95,25 @@ pub struct ContractCreator {
tx: Transaction,
creator: Address,
}

impl From<Block> 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<Rich<Block>> for BlockDetails {
fn from(rich_block: Rich<Block>) -> Self {
Self {
block: rich_block.inner.into(),
issuance: Default::default(),
total_fees: U256::default(),
}
}
}
6 changes: 4 additions & 2 deletions crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ where
&self,
block_number: BlockNumberOrTag,
) -> RpcResult<Option<BlockDetails>> {
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<Option<BlockDetails>> {
Err(internal_rpc_err("unimplemented"))
let block = self.eth.block_by_hash(block_hash, true).await?;
Ok(block.map(Into::into))
}

/// Handler for `getBlockTransactions`
Expand Down