light: get local transactions by hash

This commit is contained in:
Robert Habermeier 2017-10-24 07:09:48 +02:00
parent 42e23a9633
commit 965dff3d32
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> {