Merge pull request #609 from ethcore/tx-rpc-expose

Expose transaction insertion in sync lib
This commit is contained in:
Gav Wood 2016-03-10 15:28:43 +01:00
commit 5764ec5ddc
2 changed files with 17 additions and 0 deletions

View File

@ -43,6 +43,7 @@ use io::SyncIo;
use transaction_queue::TransactionQueue;
use time;
use super::SyncConfig;
use ethcore;
known_heap_size!(0, PeerInfo, Header, HeaderId);
@ -1301,6 +1302,13 @@ impl ChainSync {
// TODO [todr] propagate transactions?
}
/// Add transaction to the transaction queue
pub fn insert_transaction<T>(&self, transaction: ethcore::transaction::SignedTransaction, fetch_nonce: &T)
where T: Fn(&Address) -> U256
{
let mut queue = self.transaction_queue.lock().unwrap();
queue.add(transaction, fetch_nonce);
}
}
#[cfg(test)]

View File

@ -129,6 +129,15 @@ impl EthSync {
pub fn restart(&mut self, io: &mut NetworkContext<SyncMessage>) {
self.sync.write().unwrap().restart(&mut NetSyncIo::new(io, self.chain.deref()));
}
/// Insert transaction in transaction queue
pub fn insert_transaction(&self, transaction: ethcore::transaction::SignedTransaction) {
use util::numbers::*;
let nonce_fn = |a: &Address| self.chain.state().nonce(a) + U256::one();
let sync = self.sync.write().unwrap();
sync.insert_transaction(transaction, &nonce_fn);
}
}
impl NetworkProtocolHandler<SyncMessage> for EthSync {