Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom builder error #97

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading