diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 987d895ab..ca5d5f7b5 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -938,6 +938,10 @@ impl miner::MinerService for Miner { self.transaction_queue.all_transactions() } + fn queued_transaction_hashes(&self) -> Vec { + self.transaction_queue.all_transaction_hashes() + } + fn pending_transaction_hashes(&self, chain: &C) -> BTreeSet where C: ChainInfo + Sync, { diff --git a/ethcore/src/miner/mod.rs b/ethcore/src/miner/mod.rs index 4ba1b0361..cca6e8c30 100644 --- a/ethcore/src/miner/mod.rs +++ b/ethcore/src/miner/mod.rs @@ -185,6 +185,9 @@ pub trait MinerService : Send + Sync { /// Get a list of all transactions in the pool (some of them might not be ready for inclusion yet). fn queued_transactions(&self) -> Vec>; + /// Get a list of all transaction hashes in the pool (some of them might not be ready for inclusion yet). + fn queued_transaction_hashes(&self) -> Vec; + /// Get a list of local transactions with statuses. fn local_transactions(&self) -> BTreeMap; diff --git a/miner/src/pool/queue.rs b/miner/src/pool/queue.rs index 09696d248..612ec1af0 100644 --- a/miner/src/pool/queue.rs +++ b/miner/src/pool/queue.rs @@ -315,6 +315,12 @@ impl TransactionQueue { self.pool.read().unordered_pending(ready).collect() } + /// Returns all transaction hashes in the queue without explicit ordering. + pub fn all_transaction_hashes(&self) -> Vec { + let ready = |_tx: &pool::VerifiedTransaction| txpool::Readiness::Ready; + self.pool.read().unordered_pending(ready).map(|tx| tx.hash).collect() + } + /// Computes unordered set of pending hashes. /// /// Since strict nonce-checking is not required, you may get some false positive future transactions as well. diff --git a/rpc/src/v1/helpers/light_fetch.rs b/rpc/src/v1/helpers/light_fetch.rs index df46d5916..50f4e1df6 100644 --- a/rpc/src/v1/helpers/light_fetch.rs +++ b/rpc/src/v1/helpers/light_fetch.rs @@ -45,7 +45,7 @@ use ethereum_types::{U256, Address}; use hash::H256; use parking_lot::Mutex; use fastmap::H256FastMap; -use transaction::{Action, Transaction as EthTransaction, SignedTransaction, LocalizedTransaction}; +use transaction::{Action, Transaction as EthTransaction, PendingTransaction, SignedTransaction, LocalizedTransaction}; use v1::helpers::{CallRequest as CallRequestHelper, errors, dispatch}; use v1::types::{BlockNumber, CallRequest, Log, Transaction}; @@ -54,6 +54,15 @@ const NO_INVALID_BACK_REFS_PROOF: &str = "Fails only on invalid back-references; const WRONG_RESPONSE_AMOUNT_TYPE_PROOF: &str = "responses correspond directly with requests in amount and type; qed"; +pub fn light_all_transactions(dispatch: &Arc) -> impl Iterator { + let txq = dispatch.transaction_queue.read(); + let chain_info = dispatch.client.chain_info(); + + let current = txq.ready_transactions(chain_info.best_block_number, chain_info.best_block_timestamp); + let future = txq.future_transactions(chain_info.best_block_number, chain_info.best_block_timestamp); + current.into_iter().chain(future.into_iter()) +} + /// Helper for fetching blockchain data either from the light client or the network /// as necessary. #[derive(Clone)] diff --git a/rpc/src/v1/helpers/mod.rs b/rpc/src/v1/helpers/mod.rs index be845821d..5098eca89 100644 --- a/rpc/src/v1/helpers/mod.rs +++ b/rpc/src/v1/helpers/mod.rs @@ -36,7 +36,7 @@ mod subscribers; mod subscription_manager; mod work; -pub use self::dispatch::{Dispatcher, FullDispatcher}; +pub use self::dispatch::{Dispatcher, FullDispatcher, LightDispatcher}; pub use self::network_settings::NetworkSettings; pub use self::poll_manager::PollManager; pub use self::poll_filter::{PollFilter, SyncPollFilter, limit_logs}; diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index c64d5a050..90bf077a2 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -32,7 +32,7 @@ use jsonrpc_core::futures::Future; use jsonrpc_macros::Trailing; use v1::helpers::{self, errors, ipfs, SigningQueue, SignerService, NetworkSettings}; use v1::helpers::dispatch::LightDispatcher; -use v1::helpers::light_fetch::LightFetch; +use v1::helpers::light_fetch::{LightFetch, light_all_transactions}; use v1::metadata::Metadata; use v1::traits::Parity; use v1::types::{ @@ -258,17 +258,18 @@ impl Parity for ParityClient { } fn all_transactions(&self) -> Result> { - let txq = self.light_dispatch.transaction_queue.read(); - let chain_info = self.light_dispatch.client.chain_info(); - - let current = txq.ready_transactions(chain_info.best_block_number, chain_info.best_block_timestamp); - let future = txq.future_transactions(chain_info.best_block_number, chain_info.best_block_timestamp); Ok( - current - .into_iter() - .chain(future.into_iter()) + light_all_transactions(&self.light_dispatch) .map(|tx| Transaction::from_pending(tx)) - .collect::>() + .collect() + ) + } + + fn all_transaction_hashes(&self) -> Result> { + Ok( + light_all_transactions(&self.light_dispatch) + .map(|tx| tx.transaction.hash().into()) + .collect() ) } diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index a003b3c11..8982b73e1 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -305,6 +305,16 @@ impl Parity for ParityClient where ) } + fn all_transaction_hashes(&self) -> Result> { + let all_transaction_hashes = self.miner.queued_transaction_hashes(); + + Ok(all_transaction_hashes + .into_iter() + .map(|hash| hash.into()) + .collect() + ) + } + fn future_transactions(&self) -> Result> { Err(errors::deprecated("Use `parity_allTransaction` instead.")) } diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index 088b1d45d..c867e6854 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -230,6 +230,10 @@ impl MinerService for TestMinerService { }).collect() } + fn queued_transaction_hashes(&self) -> Vec { + self.pending_transactions.lock().keys().cloned().map(|hash| hash).collect() + } + fn pending_receipts(&self, _best_block: BlockNumber) -> Option> { Some(self.pending_receipts.lock().clone()) } diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index a14369581..c54489e07 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -148,6 +148,10 @@ build_rpc_trait! { #[rpc(name = "parity_allTransactions")] fn all_transactions(&self) -> Result>; + /// Same as parity_allTransactions, but return only transactions hashes. + #[rpc(name = "parity_allTransactionHashes")] + fn all_transaction_hashes(&self) -> Result>; + /// Returns all future transactions from transaction queue (deprecated) #[rpc(name = "parity_futureTransactions")] fn future_transactions(&self) -> Result>;