@@ -66,8 +66,8 @@ pub struct ServerInfo {
66
66
67
67
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
68
68
pub struct ChainInfo {
69
- blocks : u32 ,
70
- headers : u32 ,
69
+ pub blocks : u32 ,
70
+ pub headers : u32 ,
71
71
}
72
72
73
73
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -199,6 +199,9 @@ pub trait Rpc {
199
199
#[ method( name = "gettxmeta" ) ]
200
200
async fn get_tx_meta ( & self , txid : Txid ) -> Result < Option < TxEntry > , ErrorObjectOwned > ;
201
201
202
+ #[ method( name = "listwallets" ) ]
203
+ async fn list_wallets ( & self ) -> Result < Vec < String > , ErrorObjectOwned > ;
204
+
202
205
#[ method( name = "walletload" ) ]
203
206
async fn wallet_load ( & self , name : & str ) -> Result < ( ) , ErrorObjectOwned > ;
204
207
@@ -575,6 +578,21 @@ impl WalletManager {
575
578
( network, genesis_hash)
576
579
}
577
580
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
+
578
596
pub async fn load_wallet ( & self , name : & str ) -> anyhow:: Result < ( ) > {
579
597
if self . wallets . read ( ) . await . contains_key ( name) {
580
598
return Ok ( ( ) ) ;
@@ -820,6 +838,15 @@ impl RpcServer for RpcServerImpl {
820
838
Ok ( data)
821
839
}
822
840
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
+
823
850
async fn wallet_load ( & self , name : & str ) -> Result < ( ) , ErrorObjectOwned > {
824
851
self . wallet_manager
825
852
. load_wallet ( name)
@@ -1593,4 +1620,4 @@ async fn get_server_info(client: &reqwest::Client, rpc: &BitcoinRpc, tip: ChainA
1593
1620
} ,
1594
1621
progress : calc_progress ( start_block, tip. height , info. headers ) ,
1595
1622
} )
1596
- }
1623
+ }
0 commit comments