RPC: parity_allTransactionHashes (#9745)
* rpc: add parity_allTransactionHashes * Add light_all_transactionst to helpers * Remove extra parentheses * Move light_all_transactions to light_fetch * Remove LightDispatcher import in light_fetch
This commit is contained in:
committed by
Niklas Adolfsson
parent
6643b6a306
commit
f8f8bf0fea
@@ -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<dispatch::LightDispatcher>) -> impl Iterator<Item=PendingTransaction> {
|
||||
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)]
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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<Vec<Transaction>> {
|
||||
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::<Vec<_>>()
|
||||
.collect()
|
||||
)
|
||||
}
|
||||
|
||||
fn all_transaction_hashes(&self) -> Result<Vec<H256>> {
|
||||
Ok(
|
||||
light_all_transactions(&self.light_dispatch)
|
||||
.map(|tx| tx.transaction.hash().into())
|
||||
.collect()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -305,6 +305,16 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
|
||||
)
|
||||
}
|
||||
|
||||
fn all_transaction_hashes(&self) -> Result<Vec<H256>> {
|
||||
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<Vec<Transaction>> {
|
||||
Err(errors::deprecated("Use `parity_allTransaction` instead."))
|
||||
}
|
||||
|
||||
@@ -230,6 +230,10 @@ impl MinerService for TestMinerService {
|
||||
}).collect()
|
||||
}
|
||||
|
||||
fn queued_transaction_hashes(&self) -> Vec<H256> {
|
||||
self.pending_transactions.lock().keys().cloned().map(|hash| hash).collect()
|
||||
}
|
||||
|
||||
fn pending_receipts(&self, _best_block: BlockNumber) -> Option<Vec<RichReceipt>> {
|
||||
Some(self.pending_receipts.lock().clone())
|
||||
}
|
||||
|
||||
@@ -148,6 +148,10 @@ build_rpc_trait! {
|
||||
#[rpc(name = "parity_allTransactions")]
|
||||
fn all_transactions(&self) -> Result<Vec<Transaction>>;
|
||||
|
||||
/// Same as parity_allTransactions, but return only transactions hashes.
|
||||
#[rpc(name = "parity_allTransactionHashes")]
|
||||
fn all_transaction_hashes(&self) -> Result<Vec<H256>>;
|
||||
|
||||
/// Returns all future transactions from transaction queue (deprecated)
|
||||
#[rpc(name = "parity_futureTransactions")]
|
||||
fn future_transactions(&self) -> Result<Vec<Transaction>>;
|
||||
|
||||
Reference in New Issue
Block a user