Use one error_chain definition

This commit is contained in:
Roman Zeyde 2018-05-25 12:00:39 +03:00
parent a30f492d28
commit 0d56b2ecc6
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
7 changed files with 15 additions and 15 deletions

View File

@ -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<Sha256dHash> {
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)?;
}
}

View File

@ -13,7 +13,7 @@ use std::net::TcpStream;
use util::{HeaderList, HeaderMap};
error_chain!{}
use errors::*;
#[derive(Debug, Copy, Clone)]
pub enum Network {

5
src/errors.rs Normal file
View File

@ -0,0 +1,5 @@
error_chain!{
types {
Error, ErrorKind, ResultExt, Result;
}
}

View File

@ -27,6 +27,7 @@ extern crate serde_json;
pub mod app;
mod daemon;
mod errors;
mod index;
mod mempool;
mod query;

View File

@ -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

View File

@ -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).

View File

@ -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<Sha256dHash> {