From 965dff3d3218180aa62d034bd31f93e0827b562a Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 24 Oct 2017 07:09:48 +0200 Subject: [PATCH] light: get local transactions by hash --- ethcore/light/src/transaction_queue.rs | 5 +++++ rpc/src/v1/impls/light/eth.rs | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ethcore/light/src/transaction_queue.rs b/ethcore/light/src/transaction_queue.rs index 090919245..7f67c3718 100644 --- a/ethcore/light/src/transaction_queue.rs +++ b/ethcore/light/src/transaction_queue.rs @@ -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)] diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index b797e76c2..d498c6ccd 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -392,8 +392,21 @@ impl Eth for EthClient { } fn transaction_by_hash(&self, hash: RpcH256) -> BoxFuture, 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, Error> {