TransactionPool uses non-dummy chain trait

Introduced new non-dummy trait for the blockchain as seen from the
pool that just produces a UTXO. Made to pool parametric on that
trait to get rid of the Box wrapper and still allow the test
implementation.
This commit is contained in:
Ignotus Peverell
2017-06-10 11:31:05 -07:00
parent 384554fc46
commit 172c5e840b
4 changed files with 39 additions and 17 deletions
+7 -3
View File
@@ -18,6 +18,8 @@ use secp::pedersen::Commitment;
use std::sync::RwLock;
use types::BlockChain;
/// A DummyUtxoSet for mocking up the chain
pub struct DummyUtxoSet {
outputs : HashMap<Commitment, transaction::Output>
@@ -84,10 +86,13 @@ impl DummyChainImpl {
}
}
impl DummyChain for DummyChainImpl {
impl BlockChain for DummyChainImpl {
fn get_unspent(&self, commitment: &Commitment) -> Option<transaction::Output> {
self.utxo.read().unwrap().get_output(commitment).cloned()
}
}
impl DummyChain for DummyChainImpl {
fn update_utxo_set(&mut self, new_utxo: DummyUtxoSet) {
self.utxo = RwLock::new(new_utxo);
}
@@ -96,8 +101,7 @@ impl DummyChain for DummyChainImpl {
}
}
pub trait DummyChain {
fn get_unspent(&self, commitment: &Commitment) -> Option<transaction::Output>;
pub trait DummyChain: BlockChain {
fn update_utxo_set(&mut self, new_utxo: DummyUtxoSet);
fn apply_block(&self, b: &block::Block);
}