best_block_header function

This commit is contained in:
Robert Habermeier 2017-02-13 16:49:01 +01:00
parent c7d83bd88a
commit 4f1afccf97
3 changed files with 16 additions and 9 deletions

View File

@ -31,8 +31,7 @@ use ethcore::service::ClientIoMessage;
use ethcore::encoded;
use io::IoChannel;
use util::hash::H256;
use util::{Bytes, Mutex, RwLock};
use util::{Bytes, H256, Mutex, RwLock};
use self::header_chain::HeaderChain;
@ -60,6 +59,9 @@ pub trait LightChainClient: Send + Sync {
/// Attempt to get block header by block id.
fn block_header(&self, id: BlockId) -> Option<encoded::Header>;
/// Get the best block header.
fn best_block_header(&self) -> encoded::Header;
/// Query whether a block is known.
fn is_known(&self, hash: &H256) -> bool;
@ -157,6 +159,11 @@ impl Client {
self.chain.block_header(id)
}
/// Get the best block header.
pub fn best_block_header(&self) -> encoded::Header {
self.chain.best_header()
}
/// Flush the header queue.
pub fn flush_queue(&self) {
self.queue.flush()
@ -223,6 +230,10 @@ impl LightChainClient for Client {
Client::block_header(self, id)
}
fn best_block_header(&self) -> encoded::Header {
Client::best_block_header(self)
}
fn is_known(&self, hash: &H256) -> bool {
self.status(hash) == BlockStatus::InChain
}

View File

@ -30,7 +30,6 @@ use util::sha3::Hashable;
use ethkey::Signature;
use ethsync::LightSync;
use ethcore::ids::BlockId;
use ethcore::miner::MinerService;
use ethcore::client::MiningBlockChainClient;
use ethcore::transaction::{Action, SignedTransaction, PendingTransaction, Transaction};
@ -190,8 +189,7 @@ impl Dispatcher for LightDispatcher {
-> BoxFuture<FilledTransactionRequest, Error>
{
let request = request;
let gas_limit = self.client.block_header(BlockId::Latest)
.expect("Best block header always kept; qed").gas_limit();
let gas_limit = self.client.best_block_header().gas_limit();
future::ok(FilledTransactionRequest {
from: request.from.unwrap_or(default_sender),
@ -211,8 +209,7 @@ impl Dispatcher for LightDispatcher {
{
let network_id = None; // TODO: fetch from client.
let address = filled.from;
let best_header = self.client.block_header(BlockId::Latest)
.expect("Best block header always kept; qed");
let best_header = self.client.best_block_header();
let with_nonce = move |filled: FilledTransactionRequest, nonce| {
let t = Transaction {

View File

@ -305,8 +305,7 @@ impl Eth for EthClient {
}
fn send_raw_transaction(&self, raw: Bytes) -> Result<RpcH256, Error> {
let best_header = self.client.block_header(BlockId::Latest)
.expect("best block header always stored; qed").decode();
let best_header = self.client.best_block_header().decode();
UntrustedRlp::new(&raw.into_vec()).as_val()
.map_err(errors::from_rlp_error)