Skip to content

Commit

Permalink
Merge pull request #97 from rustaceanrob/builder-err-1-20
Browse files Browse the repository at this point in the history
Remove custom builder error
  • Loading branch information
rustaceanrob authored Jan 21, 2025
2 parents 3a51016 + 1a99765 commit a5c9643
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 47 deletions.
44 changes: 2 additions & 42 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
use std::{path::PathBuf, time::Duration};

use bdk_wallet::chain::local_chain::MissingGenesisError;
use bdk_wallet::Wallet;
use kyoto::NodeBuilder;
pub use kyoto::{
Expand Down Expand Up @@ -112,7 +111,7 @@ impl LightClientBuilder {
}

/// Build a light client node and a client to interact with the node.
pub fn build(self, wallet: &Wallet) -> Result<LightClient, BuilderError> {
pub fn build(self, wallet: &Wallet) -> Result<LightClient, SqlInitializationError> {
let network = wallet.network();
let mut node_builder = NodeBuilder::new(network);
if let Some(whitelist) = self.peers {
Expand Down Expand Up @@ -165,7 +164,7 @@ impl LightClientBuilder {
wallet.local_chain().tip(),
wallet.spk_index().clone(),
event_rx,
)?;
);
Ok(LightClient {
requester,
log_subscriber: LogSubscriber::new(log_rx),
Expand All @@ -181,42 +180,3 @@ impl Default for LightClientBuilder {
Self::new()
}
}

/// Errors thrown by the [`LightClientBuilder`].
#[derive(Debug)]
pub enum BuilderError {
/// The `LocalChain` was not initialized with a genesis block.
Chain(MissingGenesisError),
/// The database encountered a fatal error.
Database(SqlInitializationError),
}

impl std::fmt::Display for BuilderError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BuilderError::Chain(e) => write!(f, "genesis block not found: {e}"),
BuilderError::Database(e) => write!(f, "fatal database error: {e}"),
}
}
}

impl std::error::Error for BuilderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
BuilderError::Chain(e) => Some(e),
BuilderError::Database(e) => Some(e),
}
}
}

impl From<MissingGenesisError> for BuilderError {
fn from(value: MissingGenesisError) -> Self {
BuilderError::Chain(value)
}
}

impl From<SqlInitializationError> for BuilderError {
fn from(value: SqlInitializationError) -> Self {
BuilderError::Database(value)
}
}
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use std::collections::HashSet;

type FutureResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'a>>;

pub use bdk_wallet::chain::local_chain::MissingGenesisError;
pub use bdk_wallet::Update;

use bdk_wallet::chain::{
Expand Down Expand Up @@ -107,13 +106,13 @@ impl UpdateSubscriber {
cp: CheckPoint,
index: KeychainTxOutIndex<KeychainKind>,
receiver: UnboundedReceiver<Event>,
) -> Result<Self, MissingGenesisError> {
Ok(Self {
) -> Self {
Self {
receiver,
chain: LocalChain::from_tip(cp)?,
chain: LocalChain::from_tip(cp).expect("chain was initialized with genesis"),
graph: IndexedTxGraph::new(index.clone()),
chain_changeset: BTreeMap::new(),
})
}
}

/// Return the most recent update from the node once it has synced to the network's tip.
Expand Down

0 comments on commit a5c9643

Please sign in to comment.