Merge pull request #6874 from paritytech/light-local-tx

Get local transactions by hash in the light client
This commit is contained in:
Robert Habermeier 2017-11-07 11:23:40 -06:00 committed by GitHub
commit d701ed7262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -321,6 +321,11 @@ impl TransactionQueue {
self.by_hash.remove(&hash);
}
}
/// Get a transaction by hash.
pub fn get(&self, hash: &H256) -> Option<&PendingTransaction> {
self.by_hash.get(&hash)
}
}
#[cfg(test)]

View File

@ -392,8 +392,21 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
}
fn transaction_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<Transaction>, Error> {
let hash = hash.into();
let eip86 = self.client.eip86_transition();
Box::new(self.fetcher().transaction_by_hash(hash.into(), eip86).map(|x| x.map(|(tx, _)| tx)))
{
let tx_queue = self.transaction_queue.read();
if let Some(tx) = tx_queue.get(&hash) {
return Box::new(future::ok(Some(Transaction::from_pending(
tx.clone(),
self.client.chain_info().best_block_number,
eip86,
))));
}
}
Box::new(self.fetcher().transaction_by_hash(hash, eip86).map(|x| x.map(|(tx, _)| tx)))
}
fn transaction_by_block_hash_and_index(&self, hash: RpcH256, idx: Index) -> BoxFuture<Option<Transaction>, Error> {