Client api cleaning - uncles are returned as rlp (#1516)

* uncle as rlp in the api

* uncle rlp in block view

* fix warning
This commit is contained in:
Nikolay Volf
2016-07-01 22:37:17 +04:00
committed by Gav Wood
parent d8a4cca817
commit 8102fb9306
6 changed files with 53 additions and 42 deletions

View File

@@ -41,6 +41,7 @@ use v1::traits::Eth;
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, OptionalValue, Index, Filter, Log, Receipt};
use v1::impls::{default_gas_price, dispatch_transaction, error_codes};
use serde;
use ethcore::header::Header as BlockHeader;
/// Eth rpc implementation.
pub struct EthClient<C, S, M, EM> where
@@ -126,33 +127,38 @@ impl<C, S, M, EM> EthClient<C, S, M, EM> where
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.parent_hash().clone())).map(|diff| (diff, u))) {
Some((parent_difficulty, uncle)) => {
let block = Block {
hash: OptionalValue::Value(uncle.hash()),
parent_hash: uncle.parent_hash,
uncles_hash: uncle.uncles_hash,
author: uncle.author,
miner: uncle.author,
state_root: uncle.state_root,
transactions_root: uncle.transactions_root,
number: OptionalValue::Value(U256::from(uncle.number)),
gas_used: uncle.gas_used,
gas_limit: uncle.gas_limit,
logs_bloom: uncle.log_bloom,
timestamp: U256::from(uncle.timestamp),
difficulty: uncle.difficulty,
total_difficulty: uncle.difficulty + parent_difficulty,
receipts_root: uncle.receipts_root,
extra_data: Bytes::new(uncle.extra_data),
seal_fields: uncle.seal.into_iter().map(|f| decode(&f)).map(Bytes::new).collect(),
uncles: vec![],
transactions: BlockTransactions::Hashes(vec![]),
};
to_value(&block)
},
None => Ok(Value::Null)
}
let uncle: BlockHeader = match client.uncle(id) {
Some(rlp) => decode(&rlp),
None => { return Ok(Value::Null); }
};
let parent_difficulty = match client.block_total_difficulty(BlockID::Hash(uncle.parent_hash().clone())) {
Some(difficulty) => difficulty,
None => { return Ok(Value::Null); }
};
let block = Block {
hash: OptionalValue::Value(uncle.hash()),
parent_hash: uncle.parent_hash,
uncles_hash: uncle.uncles_hash,
author: uncle.author,
miner: uncle.author,
state_root: uncle.state_root,
transactions_root: uncle.transactions_root,
number: OptionalValue::Value(U256::from(uncle.number)),
gas_used: uncle.gas_used,
gas_limit: uncle.gas_limit,
logs_bloom: uncle.log_bloom,
timestamp: U256::from(uncle.timestamp),
difficulty: uncle.difficulty,
total_difficulty: uncle.difficulty + parent_difficulty,
receipts_root: uncle.receipts_root,
extra_data: Bytes::new(uncle.extra_data),
seal_fields: uncle.seal.into_iter().map(|f| decode(&f)).map(Bytes::new).collect(),
uncles: vec![],
transactions: BlockTransactions::Hashes(vec![]),
};
to_value(&block)
}
fn sign_call(&self, request: CallRequest) -> Result<SignedTransaction, Error> {
@@ -435,12 +441,12 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn uncle_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> {
from_params::<(H256, Index)>(params)
.and_then(|(hash, index)| self.uncle(UncleID(BlockID::Hash(hash), index.value())))
.and_then(|(hash, index)| self.uncle(UncleID { block: BlockID::Hash(hash), position: index.value() }))
}
fn uncle_by_block_number_and_index(&self, params: Params) -> Result<Value, Error> {
from_params::<(BlockNumber, Index)>(params)
.and_then(|(number, index)| self.uncle(UncleID(number.into(), index.value())))
.and_then(|(number, index)| self.uncle(UncleID { block: number.into(), position: index.value() }))
}
fn compilers(&self, params: Params) -> Result<Value, Error> {