best_block_header function
This commit is contained in:
parent
c7d83bd88a
commit
4f1afccf97
@ -31,8 +31,7 @@ use ethcore::service::ClientIoMessage;
|
|||||||
use ethcore::encoded;
|
use ethcore::encoded;
|
||||||
use io::IoChannel;
|
use io::IoChannel;
|
||||||
|
|
||||||
use util::hash::H256;
|
use util::{Bytes, H256, Mutex, RwLock};
|
||||||
use util::{Bytes, Mutex, RwLock};
|
|
||||||
|
|
||||||
use self::header_chain::HeaderChain;
|
use self::header_chain::HeaderChain;
|
||||||
|
|
||||||
@ -60,6 +59,9 @@ pub trait LightChainClient: Send + Sync {
|
|||||||
/// Attempt to get block header by block id.
|
/// Attempt to get block header by block id.
|
||||||
fn block_header(&self, id: BlockId) -> Option<encoded::Header>;
|
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.
|
/// Query whether a block is known.
|
||||||
fn is_known(&self, hash: &H256) -> bool;
|
fn is_known(&self, hash: &H256) -> bool;
|
||||||
|
|
||||||
@ -157,6 +159,11 @@ impl Client {
|
|||||||
self.chain.block_header(id)
|
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.
|
/// Flush the header queue.
|
||||||
pub fn flush_queue(&self) {
|
pub fn flush_queue(&self) {
|
||||||
self.queue.flush()
|
self.queue.flush()
|
||||||
@ -223,6 +230,10 @@ impl LightChainClient for Client {
|
|||||||
Client::block_header(self, id)
|
Client::block_header(self, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn best_block_header(&self) -> encoded::Header {
|
||||||
|
Client::best_block_header(self)
|
||||||
|
}
|
||||||
|
|
||||||
fn is_known(&self, hash: &H256) -> bool {
|
fn is_known(&self, hash: &H256) -> bool {
|
||||||
self.status(hash) == BlockStatus::InChain
|
self.status(hash) == BlockStatus::InChain
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ use util::sha3::Hashable;
|
|||||||
|
|
||||||
use ethkey::Signature;
|
use ethkey::Signature;
|
||||||
use ethsync::LightSync;
|
use ethsync::LightSync;
|
||||||
use ethcore::ids::BlockId;
|
|
||||||
use ethcore::miner::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
use ethcore::client::MiningBlockChainClient;
|
use ethcore::client::MiningBlockChainClient;
|
||||||
use ethcore::transaction::{Action, SignedTransaction, PendingTransaction, Transaction};
|
use ethcore::transaction::{Action, SignedTransaction, PendingTransaction, Transaction};
|
||||||
@ -190,8 +189,7 @@ impl Dispatcher for LightDispatcher {
|
|||||||
-> BoxFuture<FilledTransactionRequest, Error>
|
-> BoxFuture<FilledTransactionRequest, Error>
|
||||||
{
|
{
|
||||||
let request = request;
|
let request = request;
|
||||||
let gas_limit = self.client.block_header(BlockId::Latest)
|
let gas_limit = self.client.best_block_header().gas_limit();
|
||||||
.expect("Best block header always kept; qed").gas_limit();
|
|
||||||
|
|
||||||
future::ok(FilledTransactionRequest {
|
future::ok(FilledTransactionRequest {
|
||||||
from: request.from.unwrap_or(default_sender),
|
from: request.from.unwrap_or(default_sender),
|
||||||
@ -211,8 +209,7 @@ impl Dispatcher for LightDispatcher {
|
|||||||
{
|
{
|
||||||
let network_id = None; // TODO: fetch from client.
|
let network_id = None; // TODO: fetch from client.
|
||||||
let address = filled.from;
|
let address = filled.from;
|
||||||
let best_header = self.client.block_header(BlockId::Latest)
|
let best_header = self.client.best_block_header();
|
||||||
.expect("Best block header always kept; qed");
|
|
||||||
|
|
||||||
let with_nonce = move |filled: FilledTransactionRequest, nonce| {
|
let with_nonce = move |filled: FilledTransactionRequest, nonce| {
|
||||||
let t = Transaction {
|
let t = Transaction {
|
||||||
|
@ -305,8 +305,7 @@ impl Eth for EthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn send_raw_transaction(&self, raw: Bytes) -> Result<RpcH256, Error> {
|
fn send_raw_transaction(&self, raw: Bytes) -> Result<RpcH256, Error> {
|
||||||
let best_header = self.client.block_header(BlockId::Latest)
|
let best_header = self.client.best_block_header().decode();
|
||||||
.expect("best block header always stored; qed").decode();
|
|
||||||
|
|
||||||
UntrustedRlp::new(&raw.into_vec()).as_val()
|
UntrustedRlp::new(&raw.into_vec()).as_val()
|
||||||
.map_err(errors::from_rlp_error)
|
.map_err(errors::from_rlp_error)
|
||||||
|
Loading…
Reference in New Issue
Block a user