From f4d5c7b48e0cf2ed9f5407674d32b8e309a26164 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 16 May 2016 12:46:09 +0200 Subject: [PATCH] Fix uncle getter Uncle blocks don't necessarily have BlockDetails, so can't get total difficulty directly. Closes #1057 --- ethcore/src/client/ids.rs | 1 + rpc/src/v1/impls/eth.rs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ethcore/src/client/ids.rs b/ethcore/src/client/ids.rs index 39a19c82d..693cab528 100644 --- a/ethcore/src/client/ids.rs +++ b/ethcore/src/client/ids.rs @@ -53,6 +53,7 @@ pub struct TraceId { } /// Uniquely identifies Uncle. +#[derive(Debug)] pub struct UncleId ( /// Block id. pub BlockId, diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 51946b97b..b6abbaa47 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -123,8 +123,8 @@ impl EthClient fn uncle(&self, id: UncleId) -> Result { let client = take_weak!(self.client); - match client.uncle(id).and_then(|u| client.block_total_difficulty(BlockId::Hash(u.hash())).map(|diff| (diff, u))) { - Some((difficulty, uncle)) => { + match client.uncle(id).and_then(|u| client.block_total_difficulty(BlockId::Hash(u.parent_hash().clone())).map(|diff| (diff, u))) { + Some((parent_difficulty, uncle)) => { let block = Block { hash: OptionalValue::Value(uncle.hash()), parent_hash: uncle.parent_hash, @@ -138,8 +138,8 @@ impl EthClient gas_limit: uncle.gas_limit, logs_bloom: uncle.log_bloom, timestamp: U256::from(uncle.timestamp), - difficulty: uncle.difficulty, - total_difficulty: difficulty, + difficulty: uncle.difficulty + parent_difficulty, + total_difficulty: uncle.difficulty, receipts_root: uncle.receipts_root, extra_data: Bytes::new(uncle.extra_data), seal_fields: uncle.seal.into_iter().map(Bytes::new).collect(),