get signing network ID for light client

This commit is contained in:
Robert Habermeier 2017-02-16 16:08:58 +01:00
parent 39d4e46073
commit 2b91c922c1
2 changed files with 41 additions and 2 deletions

View File

@ -20,7 +20,7 @@ use std::sync::Arc;
use ethcore::block_import_error::BlockImportError;
use ethcore::block_status::BlockStatus;
use ethcore::client::ClientReport;
use ethcore::client::{ClientReport, EnvInfo};
use ethcore::engines::Engine;
use ethcore::ids::BlockId;
use ethcore::header::Header;
@ -62,6 +62,9 @@ pub trait LightChainClient: Send + Sync {
/// Get the best block header.
fn best_block_header(&self) -> encoded::Header;
/// Get the signing network ID.
fn signing_network_id(&self) -> Option<u64>;
/// Query whether a block is known.
fn is_known(&self, hash: &H256) -> bool;
@ -164,6 +167,11 @@ impl Client {
self.chain.best_header()
}
/// Get the signing network id.
pub fn signing_network_id(&self) -> Option<u64> {
self.engine.signing_network_id(&self.latest_env_info())
}
/// Flush the header queue.
pub fn flush_queue(&self) {
self.queue.flush()
@ -217,6 +225,33 @@ impl Client {
pub fn engine(&self) -> &Engine {
&*self.engine
}
fn latest_env_info(&self) -> EnvInfo {
let header = self.best_block_header();
EnvInfo {
number: header.number(),
author: header.author(),
timestamp: header.timestamp(),
difficulty: header.difficulty(),
last_hashes: self.build_last_hashes(header.hash()),
gas_used: Default::default(),
gas_limit: header.gas_limit(),
}
}
fn build_last_hashes(&self, mut parent_hash: H256) -> Arc<Vec<H256>> {
let mut v = Vec::with_capacity(256);
for _ in 0..255 {
v.push(parent_hash);
match self.block_header(BlockId::Hash(parent_hash)) {
Some(header) => parent_hash = header.hash(),
None => break,
}
}
Arc::new(v)
}
}
impl LightChainClient for Client {
@ -234,6 +269,10 @@ impl LightChainClient for Client {
Client::best_block_header(self)
}
fn signing_network_id(&self) -> Option<u64> {
Client::signing_network_id(self)
}
fn is_known(&self, hash: &H256) -> bool {
self.status(hash) == BlockStatus::InChain
}

View File

@ -207,7 +207,7 @@ impl Dispatcher for LightDispatcher {
fn sign(&self, accounts: Arc<AccountProvider>, filled: FilledTransactionRequest, password: SignWith)
-> BoxFuture<WithToken<SignedTransaction>, Error>
{
let network_id = None; // TODO: fetch from client.
let network_id = self.client.signing_network_id();
let address = filled.from;
let best_header = self.client.best_block_header();