Refactor the Keychain to be based on a trait (#1146)

* First pass at restructuring the keychain crate and introducing a Keychain trait
* Parameterized everything that had to. Stuff compiles.
* More stuff compiles, fix most tests
* Big merge, pushing down opening the keychain forced adding factory methods on trait
* Test fixes for pool and servers crate
This commit is contained in:
Ignotus Peverell
2018-06-08 06:21:54 +01:00
committed by GitHub
parent a6590ea0ae
commit af178f82f8
43 changed files with 840 additions and 678 deletions
+3 -3
View File
@@ -29,19 +29,19 @@ use std::sync::{Arc, RwLock};
use core::core::{Block, BlockHeader};
use chain::ChainStore;
use chain::txhashset;
use chain::types::Tip;
use chain::ChainStore;
use core::core::target::Difficulty;
use keychain::Keychain;
use keychain::{ExtKeychain, Keychain};
use wallet::libtx;
use common::*;
#[test]
fn test_transaction_pool_block_building() {
let keychain = Keychain::from_random_seed().unwrap();
let keychain: ExtKeychain = Keychain::from_random_seed().unwrap();
let db_root = ".grin_block_building".to_string();
clean_output_dir(db_root.clone());
+3 -3
View File
@@ -29,19 +29,19 @@ use std::sync::{Arc, RwLock};
use core::core::{Block, BlockHeader};
use chain::ChainStore;
use chain::txhashset;
use chain::types::Tip;
use chain::ChainStore;
use core::core::target::Difficulty;
use keychain::Keychain;
use keychain::{ExtKeychain, Keychain};
use wallet::libtx;
use common::*;
#[test]
fn test_transaction_pool_block_reconciliation() {
let keychain = Keychain::from_random_seed().unwrap();
let keychain: ExtKeychain = Keychain::from_random_seed().unwrap();
let db_root = ".grin_block_reconcilliation".to_string();
clean_output_dir(db_root.clone());
+2 -2
View File
@@ -29,7 +29,7 @@ use std::sync::{Arc, RwLock};
use core::core::Transaction;
use keychain::Keychain;
use keychain::{ExtKeychain, Keychain};
use pool::TransactionPool;
use pool::types::*;
@@ -82,7 +82,7 @@ impl BlockChain for CoinbaseMaturityErrorChainAdapter {
/// Test we correctly verify coinbase maturity when adding txs to the pool.
#[test]
fn test_coinbase_maturity() {
let keychain = Keychain::from_random_seed().unwrap();
let keychain: ExtKeychain = Keychain::from_random_seed().unwrap();
// Mocking this up with an adapter that will raise an error for coinbase
// maturity.
+16 -10
View File
@@ -30,10 +30,10 @@ use std::sync::{Arc, RwLock};
use core::core::{BlockHeader, Transaction};
use chain::ChainStore;
use chain::store::ChainKVStore;
use chain::txhashset;
use chain::txhashset::TxHashSet;
use chain::ChainStore;
use core::core::hash::Hashed;
use core::core::pmmr::MerkleProof;
use pool::*;
@@ -41,8 +41,8 @@ use pool::*;
use keychain::Keychain;
use wallet::libtx;
use pool::types::*;
use pool::TransactionPool;
use pool::types::*;
#[derive(Clone)]
pub struct ChainAdapter {
@@ -105,11 +105,14 @@ pub fn test_setup(chain: &Arc<ChainAdapter>) -> TransactionPool<ChainAdapter> {
)
}
pub fn test_transaction_spending_coinbase(
keychain: &Keychain,
pub fn test_transaction_spending_coinbase<K>(
keychain: &K,
header: &BlockHeader,
output_values: Vec<u64>,
) -> Transaction {
) -> Transaction
where
K: Keychain,
{
let output_sum = output_values.iter().sum::<u64>() as i64;
let coinbase_reward: u64 = 60_000_000_000;
@@ -137,14 +140,17 @@ pub fn test_transaction_spending_coinbase(
tx_elements.push(libtx::build::with_fee(fees as u64));
libtx::build::transaction(tx_elements, &keychain).unwrap()
libtx::build::transaction(tx_elements, keychain).unwrap()
}
pub fn test_transaction(
keychain: &Keychain,
pub fn test_transaction<K>(
keychain: &K,
input_values: Vec<u64>,
output_values: Vec<u64>,
) -> Transaction {
) -> Transaction
where
K: Keychain,
{
let input_sum = input_values.iter().sum::<u64>() as i64;
let output_sum = output_values.iter().sum::<u64>() as i64;
@@ -164,7 +170,7 @@ pub fn test_transaction(
}
tx_elements.push(libtx::build::with_fee(fees as u64));
libtx::build::transaction(tx_elements, &keychain).unwrap()
libtx::build::transaction(tx_elements, keychain).unwrap()
}
pub fn test_source() -> TxSource {
+3 -3
View File
@@ -29,13 +29,13 @@ use std::sync::{Arc, RwLock};
use core::core::{Block, BlockHeader};
use chain::ChainStore;
use chain::txhashset;
use chain::types::Tip;
use chain::ChainStore;
use core::core::target::Difficulty;
use core::core::transaction;
use keychain::Keychain;
use keychain::{ExtKeychain, Keychain};
use wallet::libtx;
use common::*;
@@ -43,7 +43,7 @@ use common::*;
/// Test we can add some txs to the pool (both stempool and txpool).
#[test]
fn test_the_transaction_pool() {
let keychain = Keychain::from_random_seed().unwrap();
let keychain: ExtKeychain = Keychain::from_random_seed().unwrap();
let db_root = ".grin_transaction_pool".to_string();
clean_output_dir(db_root.clone());