@@ -66,8 +66,8 @@ pub struct ServerInfo {
6666
6767#[ derive( Debug , Clone , Serialize , Deserialize ) ]
6868pub struct ChainInfo {
69- blocks : u32 ,
70- headers : u32 ,
69+ pub blocks : u32 ,
70+ pub headers : u32 ,
7171}
7272
7373#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -199,6 +199,9 @@ pub trait Rpc {
199199 #[ method( name = "gettxmeta" ) ]
200200 async fn get_tx_meta ( & self , txid : Txid ) -> Result < Option < TxEntry > , ErrorObjectOwned > ;
201201
202+ #[ method( name = "listwallets" ) ]
203+ async fn list_wallets ( & self ) -> Result < Vec < String > , ErrorObjectOwned > ;
204+
202205 #[ method( name = "walletload" ) ]
203206 async fn wallet_load ( & self , name : & str ) -> Result < ( ) , ErrorObjectOwned > ;
204207
@@ -575,6 +578,21 @@ impl WalletManager {
575578 ( network, genesis_hash)
576579 }
577580
581+ pub async fn list_wallets ( & self ) -> anyhow:: Result < Vec < String > > {
582+ let wallets = std:: fs:: read_dir ( & self . data_dir ) ?
583+ . filter_map ( Result :: ok)
584+ . filter ( |entry| entry. path ( ) . is_dir ( ) )
585+ . filter_map ( |entry| {
586+ entry. path ( )
587+ . file_name ( )
588+ . and_then ( |name| name. to_str ( ) )
589+ . map ( String :: from)
590+ } )
591+ . collect ( ) ;
592+
593+ Ok ( wallets)
594+ }
595+
578596 pub async fn load_wallet ( & self , name : & str ) -> anyhow:: Result < ( ) > {
579597 if self . wallets . read ( ) . await . contains_key ( name) {
580598 return Ok ( ( ) ) ;
@@ -820,6 +838,15 @@ impl RpcServer for RpcServerImpl {
820838 Ok ( data)
821839 }
822840
841+ async fn list_wallets ( & self ) -> Result < Vec < String > , ErrorObjectOwned > {
842+ self . wallet_manager
843+ . list_wallets ( )
844+ . await
845+ . map_err ( |error| {
846+ ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > )
847+ } )
848+ }
849+
823850 async fn wallet_load ( & self , name : & str ) -> Result < ( ) , ErrorObjectOwned > {
824851 self . wallet_manager
825852 . load_wallet ( name)
@@ -1593,4 +1620,4 @@ async fn get_server_info(client: &reqwest::Client, rpc: &BitcoinRpc, tip: ChainA
15931620 } ,
15941621 progress : calc_progress ( start_block, tip. height , info. headers ) ,
15951622 } )
1596- }
1623+ }
0 commit comments