@@ -331,6 +331,11 @@ pub trait WalletApi {
331331 where
332332 Self : Sized ;
333333
334+ /// Allow creating the wallet at the specified path
335+ fn new_with_dir ( path : & str , password : & str , network : Network ) -> anyhow:: Result < Self >
336+ where
337+ Self : Sized ;
338+
334339 fn load_wallet ( network : Network , password : & str ) -> anyhow:: Result < Self >
335340 where
336341 Self : Sized ;
@@ -642,6 +647,14 @@ impl WalletApi for BMPWallet<Connection> {
642647 } )
643648 }
644649
650+ fn new_with_dir ( path : & str , password : & str , network : Network ) -> anyhow:: Result < Self >
651+ where
652+ Self : Sized ,
653+ {
654+ std:: env:: set_current_dir ( path) . unwrap ( ) ;
655+ Self :: new ( password, network)
656+ }
657+
645658 // For already created wallets this will load stored data
646659 // This will also load the imported keys
647660 fn load_wallet ( network : Network , password : & str ) -> anyhow:: Result < Self > {
@@ -1152,4 +1165,28 @@ mod tests {
11521165
11531166 Ok ( ( ) )
11541167 }
1168+
1169+ #[ test]
1170+ fn test_wallet_with_path_creation ( ) -> anyhow:: Result < ( ) > {
1171+ let _permit = SEMAPHORE . acquire ( ) ;
1172+ let dir_one = TempDir :: with_prefix ( "one-" ) ?;
1173+ let dir_two = TempDir :: with_prefix ( "two-" ) ?;
1174+
1175+ let client = MockedBDKElectrum { } ;
1176+
1177+ tracing:: debug!( "Wallet path {:?}" , dir_one) ;
1178+ tracing:: debug!( "Wallet 2 path {:?}" , dir_two) ;
1179+
1180+ let mut w1 =
1181+ BMPWallet :: new_with_dir ( dir_one. path ( ) . to_str ( ) . unwrap ( ) , "" , Network :: Regtest ) ?;
1182+ let w2 = BMPWallet :: new_with_dir ( dir_two. path ( ) . to_str ( ) . unwrap ( ) , "" , Network :: Regtest ) ?;
1183+
1184+ tracing:: debug!( "Wallet one balance before syncing {}" , w1. balance( ) ) ;
1185+ assert_eq ! ( w1. balance( ) , Amount :: from_int_btc( 0 ) ) ;
1186+ let _ = w1. sync_all ( & client) ;
1187+
1188+ assert_eq ! ( w1. balance( ) , Amount :: from_int_btc( 1 ) ) ;
1189+ assert_eq ! ( w2. balance( ) , Amount :: ZERO ) ;
1190+ Ok ( ( ) )
1191+ }
11551192}
0 commit comments