Skip to content

Commit

Permalink
update error handling.
Browse files Browse the repository at this point in the history
use the new error structure accross module. After this commit there should not
be any dangling unwrap left.
  • Loading branch information
rajarshimaitra committed Feb 14, 2024
1 parent d6d228d commit 9d24952
Show file tree
Hide file tree
Showing 10 changed files with 510 additions and 1,039 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
//! Refer to tests/ folder for usage
//! THIS LIBRARY IS IN EARLY ALPHA. TEST AND REVIEW BEFORE USING IN PRODUCTION.

#![allow(unused)]
/// Error Module
mod error;
/// Blockchain Network module. Currently only contains electrum interface.
pub mod network;
/// core swap logic
pub mod swaps;
Expand Down
11 changes: 4 additions & 7 deletions src/network/electrum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// use electrum_client::raw_client::RawClient;

use crate::util::error::{ErrorKind, S5Error};
use crate::error::Error;

use super::Chain;

Expand All @@ -16,7 +16,7 @@ enum ElectrumUrl {
}

impl ElectrumUrl {
pub fn build_client(&self, timeout: u8) -> Result<electrum_client::Client, S5Error> {
pub fn build_client(&self, timeout: u8) -> Result<electrum_client::Client, Error> {
let builder = electrum_client::ConfigBuilder::new();
let builder = builder.timeout(Some(timeout));
let (url, builder) = match self {
Expand All @@ -25,10 +25,7 @@ impl ElectrumUrl {
}
ElectrumUrl::Plaintext(url) => (format!("tcp://{}", url), builder),
};
match electrum_client::Client::from_config(&url, builder.build()) {
Ok(result) => Ok(result),
Err(e) => Err(S5Error::new(ErrorKind::Network, &e.to_string())),
}
Ok(electrum_client::Client::from_config(&url, builder.build())?)
}
}

Expand Down Expand Up @@ -81,7 +78,7 @@ impl ElectrumConfig {
self.network.clone()
}
/// Builds an electrum_client::Client which can be used to make calls to electrum api
pub fn build_client(&self) -> Result<electrum_client::Client, S5Error> {
pub fn build_client(&self) -> Result<electrum_client::Client, Error> {
self.url.clone().build_client(self.timeout)
}
}
Expand Down
Loading

0 comments on commit 9d24952

Please sign in to comment.