From 7ffe9344ed730b2b6981dc46608a6e147c0f4f01 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 27 Jan 2016 14:43:43 +0100 Subject: [PATCH] replaced client block_details with block_total_difficulty --- rpc/src/impls/eth.rs | 6 +++--- src/client.rs | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/rpc/src/impls/eth.rs b/rpc/src/impls/eth.rs index af71ac0d5..ac27111d6 100644 --- a/rpc/src/impls/eth.rs +++ b/rpc/src/impls/eth.rs @@ -69,8 +69,8 @@ impl Eth for EthClient { fn block(&self, params: Params) -> Result { match from_params::<(H256, bool)>(params) { - Ok((hash, _include_txs)) => match (self.client.block_header(&hash), self.client.block_details(&hash)) { - (Some(bytes), Some(details)) => { + Ok((hash, _include_txs)) => match (self.client.block_header(&hash), self.client.block_total_difficulty(&hash)) { + (Some(bytes), Some(total_difficulty)) => { let view = HeaderView::new(&bytes); let block = Block { hash: view.sha3(), @@ -87,7 +87,7 @@ impl Eth for EthClient { logs_bloom: view.log_bloom(), timestamp: U256::from(view.timestamp()), difficulty: view.difficulty(), - total_difficulty: details.total_difficulty, + total_difficulty: total_difficulty, uncles: vec![], transactions: vec![] }; diff --git a/src/client.rs b/src/client.rs index 50c4e3f81..0d0fcae95 100644 --- a/src/client.rs +++ b/src/client.rs @@ -13,7 +13,6 @@ use service::NetSyncMessage; use env_info::LastHashes; use verification::*; use block::*; -use extras::BlockDetails; /// General block status #[derive(Debug)] @@ -67,8 +66,8 @@ pub trait BlockChainClient : Sync + Send { /// Get block status by block header hash. fn block_status(&self, hash: &H256) -> BlockStatus; - /// Get familial details concerning a block. - fn block_details(&self, hash: &H256) -> Option; + /// Get block total difficulty. + fn block_total_difficulty(&self, hash: &H256) -> Option; /// Get raw block header data by block number. fn block_header_at(&self, n: BlockNumber) -> Option; @@ -83,6 +82,9 @@ pub trait BlockChainClient : Sync + Send { /// Get block status by block number. fn block_status_at(&self, n: BlockNumber) -> BlockStatus; + /// Get block total difficulty. + fn block_total_difficulty_at(&self, n: BlockNumber) -> Option; + /// Get a tree route between `from` and `to`. /// See `BlockChain::tree_route`. fn tree_route(&self, from: &H256, to: &H256) -> Option; @@ -321,8 +323,8 @@ impl BlockChainClient for Client { if self.chain.read().unwrap().is_known(&hash) { BlockStatus::InChain } else { BlockStatus::Unknown } } - fn block_details(&self, hash: &H256) -> Option { - self.chain.read().unwrap().block_details(hash) + fn block_total_difficulty(&self, hash: &H256) -> Option { + self.chain.read().unwrap().block_details(hash).map(|d| d.total_difficulty) } fn block_header_at(&self, n: BlockNumber) -> Option { @@ -344,6 +346,10 @@ impl BlockChainClient for Client { } } + fn block_total_difficulty_at(&self, n: BlockNumber) -> Option { + self.chain.read().unwrap().block_hash(n).and_then(|h| self.block_total_difficulty(&h)) + } + fn tree_route(&self, from: &H256, to: &H256) -> Option { self.chain.read().unwrap().tree_route(from.clone(), to.clone()) }