checking tx queue
This commit is contained in:
parent
f608db3a68
commit
254ac6f253
@ -105,6 +105,9 @@ pub trait MinerService : Send + Sync {
|
||||
/// Submit `seal` as a valid solution for the header of `pow_hash`.
|
||||
/// Will check the seal, but not actually insert the block into the chain.
|
||||
fn submit_seal(&self, chain: &BlockChainClient, pow_hash: H256, seal: Vec<Bytes>) -> Result<(), Error>;
|
||||
|
||||
/// Query pending transactions for hash
|
||||
fn transaction(&self, hash: &H256) -> Option<SignedTransaction>;
|
||||
}
|
||||
|
||||
/// Mining status
|
||||
|
@ -164,6 +164,11 @@ impl MinerService for Miner {
|
||||
transaction_queue.pending_hashes()
|
||||
}
|
||||
|
||||
fn transaction(&self, hash: &H256) -> Option<SignedTransaction> {
|
||||
let queue = self.transaction_queue.lock().unwrap();
|
||||
queue.find(hash)
|
||||
}
|
||||
|
||||
fn update_sealing(&self, chain: &BlockChainClient) {
|
||||
if self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||
let current_no = chain.chain_info().best_block_number;
|
||||
|
@ -504,6 +504,11 @@ impl TransactionQueue {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Finds transaction in the queue by hash (if any)
|
||||
pub fn find(&self, hash: &H256) -> Option<SignedTransaction> {
|
||||
match self.by_hash.get(hash) { Some(transaction_ref) => Some(transaction_ref.transaction.clone()), None => None }
|
||||
}
|
||||
|
||||
/// Removes all elements (in any state) from the queue
|
||||
pub fn clear(&mut self) {
|
||||
self.current.clear();
|
||||
|
@ -348,7 +348,13 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
|
||||
|
||||
fn transaction_by_hash(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(H256,)>(params)
|
||||
.and_then(|(hash,)| self.transaction(TransactionId::Hash(hash)))
|
||||
.and_then(|(hash,)| {
|
||||
let miner = take_weak!(self.miner);
|
||||
match miner.transaction(&hash) {
|
||||
Some(pending_tx) => to_value(&Transaction::from(pending_tx)),
|
||||
None => self.transaction(TransactionId::Hash(hash))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn transaction_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> {
|
||||
|
@ -73,6 +73,10 @@ impl MinerService for TestMinerService {
|
||||
&self.latest_closed_block
|
||||
}
|
||||
|
||||
fn transaction(&self, _hash: &H256) -> Option<SignedTransaction> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
/// Submit `seal` as a valid solution for the header of `pow_hash`.
|
||||
/// Will check the seal, but not actually insert the block into the chain.
|
||||
fn submit_seal(&self, _chain: &BlockChainClient, _pow_hash: H256, _seal: Vec<Bytes>) -> Result<(), Error> { unimplemented!(); }
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use util::numbers::*;
|
||||
use ethcore::transaction::{LocalizedTransaction, Action};
|
||||
use ethcore::transaction::{LocalizedTransaction, Action, SignedTransaction};
|
||||
use v1::types::{Bytes, OptionalValue};
|
||||
|
||||
#[derive(Debug, Default, Serialize)]
|
||||
@ -58,6 +58,27 @@ impl From<LocalizedTransaction> for Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SignedTransaction> for Transaction {
|
||||
fn from(t: SignedTransaction) -> Transaction {
|
||||
Transaction {
|
||||
hash: t.hash(),
|
||||
nonce: t.nonce,
|
||||
block_hash: OptionalValue::Null,
|
||||
block_number: OptionalValue::Null,
|
||||
transaction_index: OptionalValue::Null,
|
||||
from: t.sender().unwrap(),
|
||||
to: match t.action {
|
||||
Action::Create => OptionalValue::Null,
|
||||
Action::Call(ref address) => OptionalValue::Value(address.clone())
|
||||
},
|
||||
value: t.value,
|
||||
gas_price: t.gas_price,
|
||||
gas: t.gas,
|
||||
input: Bytes::new(t.data.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Loading…
Reference in New Issue
Block a user