Skip to content

Add NetworkMismatch error type #485

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

Merged
merged 1 commit into from
Mar 25, 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
1 change: 1 addition & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ enum BuildError {
"KVStoreSetupFailed",
"WalletSetupFailed",
"LoggerSetupFailed",
"NetworkMismatch",
};

[Trait]
Expand Down
27 changes: 24 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ pub enum BuildError {
WalletSetupFailed,
/// We failed to setup the logger.
LoggerSetupFailed,
/// The given network does not match the node's previously configured network.
NetworkMismatch,
}

impl fmt::Display for BuildError {
Expand All @@ -189,6 +191,9 @@ impl fmt::Display for BuildError {
Self::WalletSetupFailed => write!(f, "Failed to setup onchain wallet."),
Self::LoggerSetupFailed => write!(f, "Failed to setup the logger."),
Self::InvalidNodeAlias => write!(f, "Given node alias is invalid."),
Self::NetworkMismatch => {
write!(f, "Given network does not match the node's previously configured network.")
},
}
}
}
Expand Down Expand Up @@ -904,9 +909,25 @@ fn build_with_store_internal(
.extract_keys()
.check_network(config.network)
.load_wallet(&mut wallet_persister)
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
loaded,
expected,
}),
) => {
log_error!(
logger,
"Failed to setup wallet: Networks do not match. Expected {} but got {}",
expected,
loaded
);
BuildError::NetworkMismatch
},
_ => {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
},
})?;
let bdk_wallet = match wallet_opt {
Some(wallet) => wallet,
Expand Down
Loading