Support 'pending' block in RPC (#1007)

* Support `pending` block in RPC

* Forward calls from miner to client in case no pending block is available
This commit is contained in:
Arkadiy Paronyan
2016-04-28 21:47:44 +02:00
committed by Gav Wood
parent ea669ac6b6
commit 8f7624f5cb
9 changed files with 175 additions and 34 deletions

View File

@@ -702,6 +702,10 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
})
.collect()
}
fn last_hashes(&self) -> LastHashes {
self.build_last_hashes(self.chain.best_block_hash())
}
}
impl MayPanic for Client {

View File

@@ -25,7 +25,8 @@ pub use self::client::*;
pub use self::config::{ClientConfig, BlockQueueConfig, BlockChainConfig};
pub use self::ids::{BlockId, TransactionId, UncleId};
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
pub use executive::Executed;
pub use executive::{Executed, Executive, TransactOptions};
pub use env_info::{LastHashes, EnvInfo};
use std::collections::HashSet;
use util::bytes::Bytes;
@@ -132,5 +133,8 @@ pub trait BlockChainClient : Sync + Send {
/// Executes a function providing it with a reference to an engine.
fn engine(&self) -> &Engine;
/// Get last hashes starting from best block.
fn last_hashes(&self) -> LastHashes;
}

View File

@@ -20,7 +20,7 @@ use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder};
use util::*;
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
use blockchain::TreeRoute;
use client::{BlockChainClient, BlockChainInfo, BlockStatus, BlockId, TransactionId, UncleId};
use client::{BlockChainClient, BlockChainInfo, BlockStatus, BlockId, TransactionId, UncleId, LastHashes};
use header::{Header as BlockHeader, BlockNumber};
use filter::Filter;
use log_entry::LocalizedLogEntry;
@@ -268,6 +268,10 @@ impl BlockChainClient for TestBlockChainClient {
unimplemented!();
}
fn last_hashes(&self) -> LastHashes {
unimplemented!();
}
fn prepare_sealing(&self, _author: Address, _gas_floor_target: U256, _extra_data: Bytes, _transactions: Vec<SignedTransaction>) -> (Option<ClosedBlock>, HashSet<H256>) {
(None, HashSet::new())
}

View File

@@ -117,7 +117,7 @@ impl<'a> Executive<'a> {
Externalities::new(self.state, self.info, self.engine, self.depth, origin_info, substate, output, tracer)
}
/// This funtion should be used to execute transaction.
/// This function should be used to execute transaction.
pub fn transact(&'a mut self, t: &SignedTransaction, options: TransactOptions) -> Result<Executed, Error> {
let check = options.check_nonce;
match options.tracing {
@@ -126,6 +126,7 @@ impl<'a> Executive<'a> {
}
}
/// Execute transaction/call with tracing enabled
pub fn transact_with_tracer<T>(&'a mut self, t: &SignedTransaction, check_nonce: bool, mut tracer: T) -> Result<Executed, Error> where T: Tracer {
let sender = try!(t.sender());
let nonce = self.state.nonce(&sender);