Transaction broadcast (#209)

* Add transaction broadcast to all known peers once they have been
accepted by our own transaction pool.
* Some debug log

Fixes #200
This commit is contained in:
Ignotus Peverell
2017-10-25 21:06:24 +00:00
committed by GitHub
parent 7178b400b8
commit e2e24bc38e
7 changed files with 76 additions and 2 deletions
+5 -1
View File
@@ -43,6 +43,7 @@ pub struct TransactionPool<T> {
// blockchain is a DummyChain, for now, which mimics what the future
// chain will offer to the pool
blockchain: Arc<T>,
adapter: Arc<PoolAdapter>,
}
impl<T> TransactionPool<T>
@@ -50,13 +51,14 @@ where
T: BlockChain,
{
/// Create a new transaction pool
pub fn new(config: PoolConfig, chain: Arc<T>) -> TransactionPool<T> {
pub fn new(config: PoolConfig, chain: Arc<T>, adapter: Arc<PoolAdapter>) -> TransactionPool<T> {
TransactionPool {
config: config,
transactions: HashMap::new(),
pool: Pool::empty(),
orphans: Orphans::empty(),
blockchain: chain,
adapter: adapter,
}
}
@@ -241,6 +243,7 @@ where
);
self.reconcile_orphans().unwrap();
self.adapter.tx_accepted(&tx);
self.transactions.insert(tx_hash, Box::new(tx));
Ok(())
@@ -1196,6 +1199,7 @@ mod tests {
pool: Pool::empty(),
orphans: Orphans::empty(),
blockchain: dummy_chain.clone(),
adapter: Arc::new(NoopAdapter{}),
}
}