@@ -513,14 +513,13 @@ impl WalletManager {
513513 . map_err ( |_| anyhow ! ( "Mnemonic generation error" ) ) ?;
514514
515515 let start_block = self . get_wallet_start_block ( client) . await ?;
516- self . setup_new_wallet ( name. to_string ( ) , mnemonic. to_string ( ) , start_block) ?;
516+ self . setup_new_wallet ( name. to_string ( ) , mnemonic. to_string ( ) , Some ( start_block. height ) ) ?;
517517 self . load_wallet ( name) . await ?;
518518 Ok ( mnemonic. to_string ( ) )
519519 }
520520
521- pub async fn recover_wallet ( & self , client : & reqwest:: Client , name : & str , mnemonic : & str ) -> anyhow:: Result < ( ) > {
522- let start_block = self . get_wallet_start_block ( client) . await ?;
523- self . setup_new_wallet ( name. to_string ( ) , mnemonic. to_string ( ) , start_block) ?;
521+ pub async fn recover_wallet ( & self , name : & str , mnemonic : & str ) -> anyhow:: Result < ( ) > {
522+ self . setup_new_wallet ( name. to_string ( ) , mnemonic. to_string ( ) , None ) ?;
524523 self . load_wallet ( name) . await ?;
525524 Ok ( ( ) )
526525 }
@@ -529,14 +528,14 @@ impl WalletManager {
529528 & self ,
530529 name : String ,
531530 mnemonic : String ,
532- start_block : BlockId ,
531+ start_block_height : Option < u32 > ,
533532 ) -> anyhow:: Result < ( ) > {
534533 let wallet_path = self . data_dir . join ( & name) ;
535534 if wallet_path. exists ( ) {
536535 return Err ( anyhow ! ( format!( "Wallet `{}` already exists" , name) ) ) ;
537536 }
538537
539- let export = self . wallet_from_mnemonic ( name. clone ( ) , mnemonic, start_block ) ?;
538+ let export = self . wallet_from_mnemonic ( name. clone ( ) , mnemonic, start_block_height ) ?;
540539 fs:: create_dir_all ( & wallet_path) ?;
541540 let wallet_export_path = wallet_path. join ( "wallet.json" ) ;
542541 let mut file = fs:: File :: create ( wallet_export_path) ?;
@@ -548,7 +547,7 @@ impl WalletManager {
548547 & self ,
549548 name : String ,
550549 mnemonic : String ,
551- start_block : BlockId ,
550+ start_block_height : Option < u32 > ,
552551 ) -> anyhow:: Result < WalletExport > {
553552 let ( network, _) = self . fallback_network ( ) ;
554553 let xpriv = Self :: descriptor_from_mnemonic ( network, & mnemonic) ?;
@@ -557,8 +556,14 @@ impl WalletManager {
557556 let tmp = bdk:: Wallet :: create ( external, internal)
558557 . network ( network)
559558 . create_wallet_no_persist ( ) ?;
559+
560+ let start_block_height = match start_block_height {
561+ Some ( height) => height,
562+ None => self . network . genesis ( ) . height ,
563+ } ;
564+
560565 let export =
561- WalletExport :: export_wallet ( & tmp, & name, start_block . height ) . map_err ( |e| anyhow ! ( e) ) ?;
566+ WalletExport :: export_wallet ( & tmp, & name, start_block_height ) . map_err ( |e| anyhow ! ( e) ) ?;
562567
563568 Ok ( export)
564569 }
@@ -946,7 +951,7 @@ impl RpcServer for RpcServerImpl {
946951
947952 async fn wallet_recover ( & self , name : & str , mnemonic : String ) -> Result < ( ) , ErrorObjectOwned > {
948953 self . wallet_manager
949- . recover_wallet ( & self . client , name, & mnemonic)
954+ . recover_wallet ( name, & mnemonic)
950955 . await
951956 . map_err ( |error| {
952957 ErrorObjectOwned :: owned ( RPC_WALLET_NOT_LOADED , error. to_string ( ) , None :: < String > )
0 commit comments