From 0aad8a87ae2e16d78525c6ae89dee68f80263d17 Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Mon, 20 Feb 2017 16:19:43 +0100 Subject: [PATCH] Added pending transaction info to eth_getTransactionByHash (#4570) * Return condition info for pending transactions * Fixed warnings --- ethcore/src/miner/miner.rs | 6 +++--- ethcore/src/miner/mod.rs | 2 +- ethcore/src/miner/transaction_queue.rs | 4 ++-- rpc/src/v1/tests/helpers/miner_service.rs | 4 ++-- util/bigint/src/hash.rs | 1 - util/network/src/discovery.rs | 1 - 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 06949f4bd..b4a7f2327 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -984,7 +984,7 @@ impl MinerService for Miner { } } - fn transaction(&self, best_block: BlockNumber, hash: &H256) -> Option { + fn transaction(&self, best_block: BlockNumber, hash: &H256) -> Option { let queue = self.transaction_queue.lock(); match self.options.pending_set { PendingSet::AlwaysQueue => queue.find(hash), @@ -992,14 +992,14 @@ impl MinerService for Miner { self.from_pending_block( best_block, || queue.find(hash), - |sealing| sealing.transactions().iter().find(|t| &t.hash() == hash).cloned() + |sealing| sealing.transactions().iter().find(|t| &t.hash() == hash).cloned().map(Into::into) ) }, PendingSet::AlwaysSealing => { self.from_pending_block( best_block, || None, - |sealing| sealing.transactions().iter().find(|t| &t.hash() == hash).cloned() + |sealing| sealing.transactions().iter().find(|t| &t.hash() == hash).cloned().map(Into::into) ) }, } diff --git a/ethcore/src/miner/mod.rs b/ethcore/src/miner/mod.rs index d88a261f3..eee9d1c5c 100644 --- a/ethcore/src/miner/mod.rs +++ b/ethcore/src/miner/mod.rs @@ -148,7 +148,7 @@ pub trait MinerService : Send + Sync { where F: FnOnce(&ClosedBlock) -> T, Self: Sized; /// Query pending transactions for hash. - fn transaction(&self, best_block: BlockNumber, hash: &H256) -> Option; + fn transaction(&self, best_block: BlockNumber, hash: &H256) -> Option; /// Get a list of all pending transactions in the queue. fn pending_transactions(&self) -> Vec; diff --git a/ethcore/src/miner/transaction_queue.rs b/ethcore/src/miner/transaction_queue.rs index ef7094a90..d937c15fc 100644 --- a/ethcore/src/miner/transaction_queue.rs +++ b/ethcore/src/miner/transaction_queue.rs @@ -1137,8 +1137,8 @@ impl TransactionQueue { } /// Finds transaction in the queue by hash (if any) - pub fn find(&self, hash: &H256) -> Option { - self.by_hash.get(hash).map(|tx| tx.transaction.clone()) + pub fn find(&self, hash: &H256) -> Option { + self.by_hash.get(hash).map(|tx| PendingTransaction { transaction: tx.transaction.clone(), condition: tx.condition.clone() }) } /// Removes all elements (in any state) from the queue diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index 82b776d00..75ca928b4 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -200,8 +200,8 @@ impl MinerService for TestMinerService { Some(f(&open_block.close())) } - fn transaction(&self, _best_block: BlockNumber, hash: &H256) -> Option { - self.pending_transactions.lock().get(hash).cloned() + fn transaction(&self, _best_block: BlockNumber, hash: &H256) -> Option { + self.pending_transactions.lock().get(hash).cloned().map(Into::into) } fn pending_transactions(&self) -> Vec { diff --git a/util/bigint/src/hash.rs b/util/bigint/src/hash.rs index 1eca9860c..cf74ea0cb 100644 --- a/util/bigint/src/hash.rs +++ b/util/bigint/src/hash.rs @@ -504,7 +504,6 @@ pub type H256FastSet = HashSet>; #[cfg(test)] mod tests { use hash::*; - use bigint::*; use std::str::FromStr; #[test] diff --git a/util/network/src/discovery.rs b/util/network/src/discovery.rs index 5cbe3f09e..04ad0b7ce 100644 --- a/util/network/src/discovery.rs +++ b/util/network/src/discovery.rs @@ -556,7 +556,6 @@ impl Discovery { mod tests { use super::*; use std::net::{SocketAddr}; - use util::sha3::Hashable; use util::FixedHash; use node_table::{Node, NodeId, NodeEndpoint};