replaced client block_details with block_total_difficulty

This commit is contained in:
debris 2016-01-27 14:43:43 +01:00
parent 1402fd5c4c
commit 7ffe9344ed
2 changed files with 14 additions and 8 deletions

View File

@ -69,8 +69,8 @@ impl Eth for EthClient {
fn block(&self, params: Params) -> Result<Value, Error> { fn block(&self, params: Params) -> Result<Value, Error> {
match from_params::<(H256, bool)>(params) { match from_params::<(H256, bool)>(params) {
Ok((hash, _include_txs)) => match (self.client.block_header(&hash), self.client.block_details(&hash)) { Ok((hash, _include_txs)) => match (self.client.block_header(&hash), self.client.block_total_difficulty(&hash)) {
(Some(bytes), Some(details)) => { (Some(bytes), Some(total_difficulty)) => {
let view = HeaderView::new(&bytes); let view = HeaderView::new(&bytes);
let block = Block { let block = Block {
hash: view.sha3(), hash: view.sha3(),
@ -87,7 +87,7 @@ impl Eth for EthClient {
logs_bloom: view.log_bloom(), logs_bloom: view.log_bloom(),
timestamp: U256::from(view.timestamp()), timestamp: U256::from(view.timestamp()),
difficulty: view.difficulty(), difficulty: view.difficulty(),
total_difficulty: details.total_difficulty, total_difficulty: total_difficulty,
uncles: vec![], uncles: vec![],
transactions: vec![] transactions: vec![]
}; };

View File

@ -13,7 +13,6 @@ use service::NetSyncMessage;
use env_info::LastHashes; use env_info::LastHashes;
use verification::*; use verification::*;
use block::*; use block::*;
use extras::BlockDetails;
/// General block status /// General block status
#[derive(Debug)] #[derive(Debug)]
@ -67,8 +66,8 @@ pub trait BlockChainClient : Sync + Send {
/// Get block status by block header hash. /// Get block status by block header hash.
fn block_status(&self, hash: &H256) -> BlockStatus; fn block_status(&self, hash: &H256) -> BlockStatus;
/// Get familial details concerning a block. /// Get block total difficulty.
fn block_details(&self, hash: &H256) -> Option<BlockDetails>; fn block_total_difficulty(&self, hash: &H256) -> Option<U256>;
/// Get raw block header data by block number. /// Get raw block header data by block number.
fn block_header_at(&self, n: BlockNumber) -> Option<Bytes>; fn block_header_at(&self, n: BlockNumber) -> Option<Bytes>;
@ -83,6 +82,9 @@ pub trait BlockChainClient : Sync + Send {
/// Get block status by block number. /// Get block status by block number.
fn block_status_at(&self, n: BlockNumber) -> BlockStatus; fn block_status_at(&self, n: BlockNumber) -> BlockStatus;
/// Get block total difficulty.
fn block_total_difficulty_at(&self, n: BlockNumber) -> Option<U256>;
/// Get a tree route between `from` and `to`. /// Get a tree route between `from` and `to`.
/// See `BlockChain::tree_route`. /// See `BlockChain::tree_route`.
fn tree_route(&self, from: &H256, to: &H256) -> Option<TreeRoute>; fn tree_route(&self, from: &H256, to: &H256) -> Option<TreeRoute>;
@ -321,8 +323,8 @@ impl BlockChainClient for Client {
if self.chain.read().unwrap().is_known(&hash) { BlockStatus::InChain } else { BlockStatus::Unknown } if self.chain.read().unwrap().is_known(&hash) { BlockStatus::InChain } else { BlockStatus::Unknown }
} }
fn block_details(&self, hash: &H256) -> Option<BlockDetails> { fn block_total_difficulty(&self, hash: &H256) -> Option<U256> {
self.chain.read().unwrap().block_details(hash) self.chain.read().unwrap().block_details(hash).map(|d| d.total_difficulty)
} }
fn block_header_at(&self, n: BlockNumber) -> Option<Bytes> { fn block_header_at(&self, n: BlockNumber) -> Option<Bytes> {
@ -344,6 +346,10 @@ impl BlockChainClient for Client {
} }
} }
fn block_total_difficulty_at(&self, n: BlockNumber) -> Option<U256> {
self.chain.read().unwrap().block_hash(n).and_then(|h| self.block_total_difficulty(&h))
}
fn tree_route(&self, from: &H256, to: &H256) -> Option<TreeRoute> { fn tree_route(&self, from: &H256, to: &H256) -> Option<TreeRoute> {
self.chain.read().unwrap().tree_route(from.clone(), to.clone()) self.chain.read().unwrap().tree_route(from.clone(), to.clone())
} }