From 58e68a867e981c12a0b323f785161584e2a4f350 Mon Sep 17 00:00:00 2001 From: eupn <36292692+eupn@users.noreply.github.com> Date: Thu, 25 Oct 2018 17:00:39 +0300 Subject: [PATCH] Remove unwrap() and add tx. pool error member to Error enum (#1839) --- servers/src/common/types.rs | 8 ++++++++ servers/src/mining/mine_block.rs | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/servers/src/common/types.rs b/servers/src/common/types.rs index 79d2c583c..fe4a6e93a 100644 --- a/servers/src/common/types.rs +++ b/servers/src/common/types.rs @@ -44,6 +44,8 @@ pub enum Error { Wallet(wallet::Error), /// Error originating from the cuckoo miner Cuckoo(pow::Error), + /// Error originating from the transaction pool. + Pool(pool::PoolError), } impl From for Error { @@ -87,6 +89,12 @@ impl From for Error { } } +impl From for Error { + fn from(e: pool::PoolError) -> Error { + Error::Pool(e) + } +} + /// Type of seeding the server will use to find other peers on the network. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub enum ChainValidationMode { diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index aa89cdc49..d61f71088 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -108,8 +108,7 @@ fn build_block( let difficulty = consensus::next_difficulty(head.height + 1, chain.difficulty_iter()); // extract current transaction from the pool - // TODO - we have a lot of unwrap() going on in this fn... - let txs = tx_pool.read().prepare_mineable_transactions().unwrap(); + let txs = tx_pool.read().prepare_mineable_transactions()?; // build the coinbase and the block itself let fees = txs.iter().map(|tx| tx.fee()).sum();