@@ -63,7 +63,7 @@ use bdk_wallet::Wallet as BdkWallet;
63
63
use bip39:: Mnemonic ;
64
64
65
65
use bitcoin:: secp256k1:: PublicKey ;
66
- use bitcoin:: { BlockHash , Network } ;
66
+ use bitcoin:: { constants , BlockHash , Network } ;
67
67
68
68
use bitcoin:: bip32:: { ChildNumber , Xpriv } ;
69
69
use std:: collections:: HashMap ;
@@ -168,6 +168,8 @@ pub enum BuildError {
168
168
WalletSetupFailed ,
169
169
/// We failed to setup the logger.
170
170
LoggerSetupFailed ,
171
+ /// The given network does not match the node's previously configured network.
172
+ NetworkMismatch ,
171
173
}
172
174
173
175
impl fmt:: Display for BuildError {
@@ -189,6 +191,9 @@ impl fmt::Display for BuildError {
189
191
Self :: WalletSetupFailed => write ! ( f, "Failed to setup onchain wallet." ) ,
190
192
Self :: LoggerSetupFailed => write ! ( f, "Failed to setup the logger." ) ,
191
193
Self :: InvalidNodeAlias => write ! ( f, "Given node alias is invalid." ) ,
194
+ Self :: NetworkMismatch => {
195
+ write ! ( f, "Given network does not match the node's previously configured network." )
196
+ } ,
192
197
}
193
198
}
194
199
}
@@ -903,10 +908,19 @@ fn build_with_store_internal(
903
908
. descriptor ( KeychainKind :: Internal , Some ( change_descriptor. clone ( ) ) )
904
909
. extract_keys ( )
905
910
. check_network ( config. network )
911
+ . check_genesis_hash ( constants:: genesis_block ( config. network ) . block_hash ( ) )
906
912
. load_wallet ( & mut wallet_persister)
907
- . map_err ( |e| {
908
- log_error ! ( logger, "Failed to set up wallet: {}" , e) ;
909
- BuildError :: WalletSetupFailed
913
+ . map_err ( |e| match e {
914
+ bdk_wallet:: LoadWithPersistError :: InvalidChangeSet (
915
+ bdk_wallet:: LoadError :: Mismatch ( bdk_wallet:: LoadMismatch :: Network { .. } ) ,
916
+ ) => BuildError :: NetworkMismatch ,
917
+ bdk_wallet:: LoadWithPersistError :: InvalidChangeSet (
918
+ bdk_wallet:: LoadError :: Mismatch ( bdk_wallet:: LoadMismatch :: Genesis { .. } ) ,
919
+ ) => BuildError :: NetworkMismatch ,
920
+ _ => {
921
+ log_error ! ( logger, "Failed to set up wallet: {}" , e) ;
922
+ BuildError :: WalletSetupFailed
923
+ } ,
910
924
} ) ?;
911
925
let bdk_wallet = match wallet_opt {
912
926
Some ( wallet) => wallet,
0 commit comments