Fix uncle getter
Uncle blocks don't necessarily have BlockDetails, so can't get total difficulty directly. Closes #1057
This commit is contained in:
parent
354ac7d6e5
commit
f4d5c7b48e
@ -53,6 +53,7 @@ pub struct TraceId {
|
||||
}
|
||||
|
||||
/// Uniquely identifies Uncle.
|
||||
#[derive(Debug)]
|
||||
pub struct UncleId (
|
||||
/// Block id.
|
||||
pub BlockId,
|
||||
|
@ -123,8 +123,8 @@ impl<C, S, A, M, EM> EthClient<C, S, A, M, EM>
|
||||
|
||||
fn uncle(&self, id: UncleId) -> Result<Value, Error> {
|
||||
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<C, S, A, M, EM> EthClient<C, S, A, M, EM>
|
||||
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(),
|
||||
|
Loading…
Reference in New Issue
Block a user