Skip to content

Commit 8991768

Browse files
committed
Add NetworkMismatch error type
Return specific error if the node is restarted with a different network from the one it was first created with. This will be caught when trying to load the `BDK` wallet.
1 parent 22cb1df commit 8991768

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

bindings/ldk_node.udl

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ enum BuildError {
321321
"KVStoreSetupFailed",
322322
"WalletSetupFailed",
323323
"LoggerSetupFailed",
324+
"NetworkMismatch",
324325
};
325326

326327
[Trait]

src/builder.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ pub enum BuildError {
168168
WalletSetupFailed,
169169
/// We failed to setup the logger.
170170
LoggerSetupFailed,
171+
/// The given network does not match.
172+
NetworkMismatch,
171173
}
172174

173175
impl fmt::Display for BuildError {
@@ -189,6 +191,7 @@ impl fmt::Display for BuildError {
189191
Self::WalletSetupFailed => write!(f, "Failed to setup onchain wallet."),
190192
Self::LoggerSetupFailed => write!(f, "Failed to setup the logger."),
191193
Self::InvalidNodeAlias => write!(f, "Given node alias is invalid."),
194+
Self::NetworkMismatch => write!(f, "Given network does match."),
192195
}
193196
}
194197
}
@@ -899,9 +902,14 @@ fn build_with_store_internal(
899902
.extract_keys()
900903
.check_network(config.network)
901904
.load_wallet(&mut wallet_persister)
902-
.map_err(|e| {
903-
log_error!(logger, "Failed to set up wallet: {}", e);
904-
BuildError::WalletSetupFailed
905+
.map_err(|e| match e {
906+
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
907+
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network { .. }),
908+
) => BuildError::NetworkMismatch,
909+
_ => {
910+
log_error!(logger, "Failed to set up wallet: {}", e);
911+
BuildError::WalletSetupFailed
912+
},
905913
})?;
906914
let bdk_wallet = match wallet_opt {
907915
Some(wallet) => wallet,

0 commit comments

Comments
 (0)