uncle as rlp in the api

This commit is contained in:
NikVolf 2016-07-01 13:26:44 +03:00
parent 7ae0eb8137
commit 7ad8599324
5 changed files with 49 additions and 42 deletions

View File

@ -22,7 +22,7 @@ use util::*;
use util::panics::*; use util::panics::*;
use views::BlockView; use views::BlockView;
use error::{Error, ImportError, ExecutionError, BlockError, ImportResult}; use error::{Error, ImportError, ExecutionError, BlockError, ImportResult};
use header::{BlockNumber, Header}; use header::{BlockNumber};
use state::State; use state::State;
use spec::Spec; use spec::Spec;
use engine::Engine; use engine::Engine;
@ -50,6 +50,7 @@ pub use types::blockchain_info::BlockChainInfo;
pub use types::block_status::BlockStatus; pub use types::block_status::BlockStatus;
use evm::Factory as EvmFactory; use evm::Factory as EvmFactory;
use miner::{Miner, MinerService, TransactionImportResult, AccountDetails}; use miner::{Miner, MinerService, TransactionImportResult, AccountDetails};
use basic_types::*;
const MAX_TX_QUEUE_SIZE: usize = 4096; const MAX_TX_QUEUE_SIZE: usize = 4096;
@ -579,9 +580,9 @@ impl BlockChainClient for Client {
self.transaction_address(id).and_then(|address| self.chain.transaction(&address)) self.transaction_address(id).and_then(|address| self.chain.transaction(&address))
} }
fn uncle(&self, id: UncleID) -> Option<Header> { fn uncle(&self, id: UncleID) -> Option<Bytes> {
let index = id.1; let index = id.position;
self.block(id.0).and_then(|block| BlockView::new(&block).uncle_at(index)) self.block(id.block).and_then(|block| BlockView::new(&block).uncle_at(index).and_then(|u| Some(u.rlp(Seal::With))))
} }
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt> { fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt> {

View File

@ -38,7 +38,7 @@ use util::Itertools;
use blockchain::TreeRoute; use blockchain::TreeRoute;
use block_queue::BlockQueueInfo; use block_queue::BlockQueueInfo;
use block::{OpenBlock, SealedBlock}; use block::{OpenBlock, SealedBlock};
use header::{BlockNumber, Header}; use header::{BlockNumber};
use transaction::{LocalizedTransaction, SignedTransaction}; use transaction::{LocalizedTransaction, SignedTransaction};
use log_entry::LocalizedLogEntry; use log_entry::LocalizedLogEntry;
use filter::Filter; use filter::Filter;
@ -126,7 +126,7 @@ pub trait BlockChainClient : Sync + Send {
fn transaction(&self, id: TransactionID) -> Option<LocalizedTransaction>; fn transaction(&self, id: TransactionID) -> Option<LocalizedTransaction>;
/// Get uncle with given id. /// Get uncle with given id.
fn uncle(&self, id: UncleID) -> Option<Header>; fn uncle(&self, id: UncleID) -> Option<Bytes>;
/// Get transaction receipt with given hash. /// Get transaction receipt with given hash.
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt>; fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt>;

View File

@ -244,7 +244,7 @@ impl MiningBlockChainClient for TestBlockChainClient {
fn prepare_open_block(&self, _author: Address, _gas_range_target: (U256, U256), _extra_data: Bytes) -> OpenBlock { fn prepare_open_block(&self, _author: Address, _gas_range_target: (U256, U256), _extra_data: Bytes) -> OpenBlock {
unimplemented!(); unimplemented!();
} }
fn vm_factory(&self) -> &EvmFactory { fn vm_factory(&self) -> &EvmFactory {
unimplemented!(); unimplemented!();
} }
@ -298,7 +298,7 @@ impl BlockChainClient for TestBlockChainClient {
unimplemented!(); unimplemented!();
} }
fn uncle(&self, _id: UncleID) -> Option<BlockHeader> { fn uncle(&self, _id: UncleID) -> Option<Bytes> {
unimplemented!(); unimplemented!();
} }

View File

@ -55,10 +55,10 @@ pub struct TraceId {
} }
/// Uniquely identifies Uncle. /// Uniquely identifies Uncle.
#[derive(Debug)] #[derive(Debug, Binary)]
pub struct UncleID ( pub struct UncleID {
/// Block id. /// Block id.
pub BlockID, pub block: BlockID,
/// Position in block. /// Position in block.
pub usize pub position: usize
); }

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::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 v1::impls::{default_gas_price, dispatch_transaction, error_codes};
use serde; use serde;
use ethcore::header::Header as BlockHeader;
/// Eth rpc implementation. /// Eth rpc implementation.
pub struct EthClient<C, S, M, EM> where 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> { fn uncle(&self, id: UncleID) -> Result<Value, Error> {
let client = take_weak!(self.client); 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 uncle: BlockHeader = match client.uncle(id) {
let block = Block { Some(rlp) => decode(&rlp),
hash: OptionalValue::Value(uncle.hash()), None => { return Ok(Value::Null); }
parent_hash: uncle.parent_hash, };
uncles_hash: uncle.uncles_hash, let parent_difficulty = match client.block_total_difficulty(BlockID::Hash(uncle.parent_hash().clone())) {
author: uncle.author, Some(difficulty) => difficulty,
miner: uncle.author, None => { return Ok(Value::Null); }
state_root: uncle.state_root, };
transactions_root: uncle.transactions_root,
number: OptionalValue::Value(U256::from(uncle.number)), let block = Block {
gas_used: uncle.gas_used, hash: OptionalValue::Value(uncle.hash()),
gas_limit: uncle.gas_limit, parent_hash: uncle.parent_hash,
logs_bloom: uncle.log_bloom, uncles_hash: uncle.uncles_hash,
timestamp: U256::from(uncle.timestamp), author: uncle.author,
difficulty: uncle.difficulty, miner: uncle.author,
total_difficulty: uncle.difficulty + parent_difficulty, state_root: uncle.state_root,
receipts_root: uncle.receipts_root, transactions_root: uncle.transactions_root,
extra_data: Bytes::new(uncle.extra_data), number: OptionalValue::Value(U256::from(uncle.number)),
seal_fields: uncle.seal.into_iter().map(|f| decode(&f)).map(Bytes::new).collect(), gas_used: uncle.gas_used,
uncles: vec![], gas_limit: uncle.gas_limit,
transactions: BlockTransactions::Hashes(vec![]), logs_bloom: uncle.log_bloom,
}; timestamp: U256::from(uncle.timestamp),
to_value(&block) difficulty: uncle.difficulty,
}, total_difficulty: uncle.difficulty + parent_difficulty,
None => Ok(Value::Null) 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> { 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> { fn uncle_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> {
from_params::<(H256, Index)>(params) 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> { fn uncle_by_block_number_and_index(&self, params: Params) -> Result<Value, Error> {
from_params::<(BlockNumber, Index)>(params) 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> { fn compilers(&self, params: Params) -> Result<Value, Error> {