Added pending transaction info to eth_getTransactionByHash (#4570)

* Return condition info for pending transactions

* Fixed warnings
This commit is contained in:
Arkadiy Paronyan 2017-02-20 16:19:43 +01:00 committed by Gav Wood
parent b9665c7cfe
commit 0aad8a87ae
6 changed files with 8 additions and 10 deletions

View File

@ -984,7 +984,7 @@ impl MinerService for Miner {
} }
} }
fn transaction(&self, best_block: BlockNumber, hash: &H256) -> Option<SignedTransaction> { fn transaction(&self, best_block: BlockNumber, hash: &H256) -> Option<PendingTransaction> {
let queue = self.transaction_queue.lock(); let queue = self.transaction_queue.lock();
match self.options.pending_set { match self.options.pending_set {
PendingSet::AlwaysQueue => queue.find(hash), PendingSet::AlwaysQueue => queue.find(hash),
@ -992,14 +992,14 @@ impl MinerService for Miner {
self.from_pending_block( self.from_pending_block(
best_block, best_block,
|| queue.find(hash), || 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 => { PendingSet::AlwaysSealing => {
self.from_pending_block( self.from_pending_block(
best_block, best_block,
|| None, || None,
|sealing| sealing.transactions().iter().find(|t| &t.hash() == hash).cloned() |sealing| sealing.transactions().iter().find(|t| &t.hash() == hash).cloned().map(Into::into)
) )
}, },
} }

View File

@ -148,7 +148,7 @@ pub trait MinerService : Send + Sync {
where F: FnOnce(&ClosedBlock) -> T, Self: Sized; where F: FnOnce(&ClosedBlock) -> T, Self: Sized;
/// Query pending transactions for hash. /// Query pending transactions for hash.
fn transaction(&self, best_block: BlockNumber, hash: &H256) -> Option<SignedTransaction>; fn transaction(&self, best_block: BlockNumber, hash: &H256) -> Option<PendingTransaction>;
/// Get a list of all pending transactions in the queue. /// Get a list of all pending transactions in the queue.
fn pending_transactions(&self) -> Vec<PendingTransaction>; fn pending_transactions(&self) -> Vec<PendingTransaction>;

View File

@ -1137,8 +1137,8 @@ impl TransactionQueue {
} }
/// Finds transaction in the queue by hash (if any) /// Finds transaction in the queue by hash (if any)
pub fn find(&self, hash: &H256) -> Option<SignedTransaction> { pub fn find(&self, hash: &H256) -> Option<PendingTransaction> {
self.by_hash.get(hash).map(|tx| tx.transaction.clone()) 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 /// Removes all elements (in any state) from the queue

View File

@ -200,8 +200,8 @@ impl MinerService for TestMinerService {
Some(f(&open_block.close())) Some(f(&open_block.close()))
} }
fn transaction(&self, _best_block: BlockNumber, hash: &H256) -> Option<SignedTransaction> { fn transaction(&self, _best_block: BlockNumber, hash: &H256) -> Option<PendingTransaction> {
self.pending_transactions.lock().get(hash).cloned() self.pending_transactions.lock().get(hash).cloned().map(Into::into)
} }
fn pending_transactions(&self) -> Vec<PendingTransaction> { fn pending_transactions(&self) -> Vec<PendingTransaction> {

View File

@ -504,7 +504,6 @@ pub type H256FastSet = HashSet<H256, BuildHasherDefault<PlainHasher>>;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use hash::*; use hash::*;
use bigint::*;
use std::str::FromStr; use std::str::FromStr;
#[test] #[test]

View File

@ -556,7 +556,6 @@ impl Discovery {
mod tests { mod tests {
use super::*; use super::*;
use std::net::{SocketAddr}; use std::net::{SocketAddr};
use util::sha3::Hashable;
use util::FixedHash; use util::FixedHash;
use node_table::{Node, NodeId, NodeEndpoint}; use node_table::{Node, NodeId, NodeEndpoint};