From 0d56b2ecc6ed9b3a7d2677cca1007c31857b058a Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 25 May 2018 12:00:39 +0300 Subject: [PATCH] Use one error_chain definition --- src/app.rs | 10 ++++------ src/daemon.rs | 2 +- src/errors.rs | 5 +++++ src/lib.rs | 1 + src/mempool.rs | 2 +- src/query.rs | 8 ++------ src/rpc.rs | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 src/errors.rs diff --git a/src/app.rs b/src/app.rs index 6580ec5..8bbcebd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -11,7 +11,7 @@ use std::time::Duration; use daemon::Network; use {daemon, index, query, rpc, store}; -error_chain!{} +use errors::*; #[derive(Debug)] struct Config { @@ -83,7 +83,7 @@ impl App { &self.daemon } fn update_index(&self, mut tip: Sha256dHash) -> Result { - if tip != self.daemon.getbestblockhash().chain_err(|| "daemon error")? { + if tip != self.daemon.getbestblockhash()? { tip = self.index.update(&self.store, &self.daemon); } Ok(tip) @@ -92,7 +92,7 @@ impl App { fn run_server(config: &Config) -> Result<()> { let index = index::Index::new(); - let daemon = daemon::Daemon::new(config.network_type).chain_err(|| "cannot connect to daemon")?; + let daemon = daemon::Daemon::new(config.network_type)?; let store = store::DBStore::open( config.db_path, @@ -117,9 +117,7 @@ fn run_server(config: &Config) -> Result<()> { rpc::start(&config.rpc_addr, query.clone()); loop { thread::sleep(poll_delay); - query - .update_mempool() - .chain_err(|| "mempool update failed")?; + query.update_mempool()?; tip = app.update_index(tip)?; } } diff --git a/src/daemon.rs b/src/daemon.rs index 24cd7e2..755da25 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -13,7 +13,7 @@ use std::net::TcpStream; use util::{HeaderList, HeaderMap}; -error_chain!{} +use errors::*; #[derive(Debug, Copy, Clone)] pub enum Network { diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..154c1e6 --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,5 @@ +error_chain!{ + types { + Error, ErrorKind, ResultExt, Result; + } +} diff --git a/src/lib.rs b/src/lib.rs index c9cb6ee..4d23d28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,7 @@ extern crate serde_json; pub mod app; mod daemon; +mod errors; mod index; mod mempool; mod query; diff --git a/src/mempool.rs b/src/mempool.rs index d0553c5..8076ef6 100644 --- a/src/mempool.rs +++ b/src/mempool.rs @@ -12,7 +12,7 @@ use index::index_transaction; use store::{ReadStore, Row}; use util::Bytes; -error_chain!{} +use errors::*; const VSIZE_BIN_WIDTH: u32 = 100_000; // in vbytes diff --git a/src/query.rs b/src/query.rs index 501d043..2437f22 100644 --- a/src/query.rs +++ b/src/query.rs @@ -13,7 +13,7 @@ use mempool::Tracker; use store::ReadStore; use util::{FullHash, HashPrefix, HeaderEntry}; -error_chain!{} +use errors::*; struct FundingOutput { txn_id: Sha256dHash, @@ -308,11 +308,7 @@ impl Query { } pub fn update_mempool(&self) -> Result<()> { - self.tracker - .write() - .unwrap() - .update(self.app.daemon()) - .chain_err(|| "failed to update mempool") + self.tracker.write().unwrap().update(self.app.daemon()) } /// Returns [vsize, fee_rate] pairs (measured in vbytes and satoshis). diff --git a/src/rpc.rs b/src/rpc.rs index 1f46712..7717b5a 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -16,7 +16,7 @@ use std::time::Duration; use query::Query; use util::HeaderEntry; -error_chain!{} +use errors::*; // TODO: Sha256dHash should be a generic hash-container (since script hash is single SHA256) fn hash_from_value(val: Option<&Value>) -> Result {