@@ -15,6 +15,7 @@ const CONFIG_DIR: &str = "payjoin-cli";
1515
1616type Builder = config:: builder:: ConfigBuilder < DefaultState > ;
1717
18+ #[ cfg( all( feature = "bitcoind" , not( feature = "esplora" ) ) ) ]
1819#[ derive( Debug , Clone , Deserialize ) ]
1920pub struct BitcoindConfig {
2021 pub rpchost : Url ,
@@ -23,6 +24,15 @@ pub struct BitcoindConfig {
2324 pub rpcpassword : String ,
2425}
2526
27+ #[ cfg( feature = "esplora" ) ]
28+ #[ derive( Debug , Clone , Deserialize ) ]
29+ pub struct BdkWalletConfig {
30+ pub descriptor : Option < String > ,
31+ pub change_descriptor : Option < String > ,
32+ pub esplora_url : Option < String > ,
33+ pub network : Option < String > ,
34+ }
35+
2636#[ cfg( feature = "v1" ) ]
2737#[ derive( Debug , Clone , Deserialize ) ]
2838pub struct V1Config {
@@ -55,7 +65,10 @@ pub enum VersionConfig {
5565pub struct Config {
5666 pub db_path : PathBuf ,
5767 pub max_fee_rate : Option < FeeRate > ,
68+ #[ cfg( all( feature = "bitcoind" , not( feature = "esplora" ) ) ) ]
5869 pub bitcoind : BitcoindConfig ,
70+ #[ cfg( feature = "esplora" ) ]
71+ pub wallet : Option < BdkWalletConfig > ,
5972 #[ serde( skip) ]
6073 pub version : Option < VersionConfig > ,
6174 #[ cfg( feature = "_manual-tls" ) ]
@@ -102,7 +115,7 @@ impl Config {
102115
103116 pub ( crate ) fn new ( cli : & Cli ) -> Result < Self , ConfigError > {
104117 let mut config = config:: Config :: builder ( ) ;
105- config = add_bitcoind_defaults ( config, cli) ?;
118+ config = add_wallet_defaults ( config, cli) ?;
106119 config = add_common_defaults ( config, cli) ?;
107120
108121 let version = Self :: determine_version ( cli) ?;
@@ -143,7 +156,10 @@ impl Config {
143156 let mut config = Config {
144157 db_path : built_config. get ( "db_path" ) ?,
145158 max_fee_rate : built_config. get ( "max_fee_rate" ) . ok ( ) ,
159+ #[ cfg( all( feature = "bitcoind" , not( feature = "esplora" ) ) ) ]
146160 bitcoind : built_config. get ( "bitcoind" ) ?,
161+ #[ cfg( feature = "esplora" ) ]
162+ wallet : built_config. get ( "wallet" ) . ok ( ) ,
147163 version : None ,
148164 #[ cfg( feature = "_manual-tls" ) ]
149165 root_certificate : built_config. get ( "root_certificate" ) . ok ( ) ,
@@ -223,16 +239,35 @@ impl Config {
223239 }
224240}
225241
226- /// Set up default values and CLI overrides for Bitcoin RPC connection settings
227- fn add_bitcoind_defaults ( config : Builder , cli : & Cli ) -> Result < Builder , ConfigError > {
228- // Set default values
242+ /// Set up default values and CLI overrides for wallet settings
243+ #[ cfg( feature = "esplora" ) ]
244+ fn add_wallet_defaults ( config : Builder , cli : & Cli ) -> Result < Builder , ConfigError > {
245+ let config = config
246+ . set_default ( "wallet.descriptor" , None :: < String > ) ?
247+ . set_default ( "wallet.change_descriptor" , None :: < String > ) ?
248+ . set_default ( "wallet.esplora_url" , None :: < String > ) ?
249+ . set_default ( "wallet.network" , None :: < String > ) ?;
250+
251+ let descriptor = cli. descriptor . as_deref ( ) ;
252+ let change_descriptor = cli. change_descriptor . as_deref ( ) ;
253+ let esplora_url = cli. esplora_url . as_deref ( ) ;
254+ let network = cli. network . as_deref ( ) ;
255+
256+ config
257+ . set_override_option ( "wallet.descriptor" , descriptor) ?
258+ . set_override_option ( "wallet.change_descriptor" , change_descriptor) ?
259+ . set_override_option ( "wallet.esplora_url" , esplora_url) ?
260+ . set_override_option ( "wallet.network" , network)
261+ }
262+
263+ #[ cfg( all( feature = "bitcoind" , not( feature = "esplora" ) ) ) ]
264+ fn add_wallet_defaults ( config : Builder , cli : & Cli ) -> Result < Builder , ConfigError > {
229265 let config = config
230266 . set_default ( "bitcoind.rpchost" , "http://localhost:18443" ) ?
231267 . set_default ( "bitcoind.cookie" , None :: < String > ) ?
232268 . set_default ( "bitcoind.rpcuser" , "bitcoin" ) ?
233269 . set_default ( "bitcoind.rpcpassword" , "" ) ?;
234270
235- // Override config values with command line arguments if applicable
236271 let rpchost = cli. rpchost . as_ref ( ) . map ( |s| s. as_str ( ) ) ;
237272 let cookie_file = cli. cookie_file . as_ref ( ) . map ( |p| p. to_string_lossy ( ) . into_owned ( ) ) ;
238273 let rpcuser = cli. rpcuser . as_deref ( ) ;
@@ -245,6 +280,9 @@ fn add_bitcoind_defaults(config: Builder, cli: &Cli) -> Result<Builder, ConfigEr
245280 . set_override_option ( "bitcoind.rpcpassword" , rpcpassword)
246281}
247282
283+ #[ cfg( all( not( feature = "esplora" ) , not( feature = "bitcoind" ) ) ) ]
284+ fn add_wallet_defaults ( config : Builder , _cli : & Cli ) -> Result < Builder , ConfigError > { Ok ( config) }
285+
248286fn add_common_defaults ( config : Builder , cli : & Cli ) -> Result < Builder , ConfigError > {
249287 let db_path = cli. db_path . as_ref ( ) . map ( |p| p. to_string_lossy ( ) . into_owned ( ) ) ;
250288 config. set_default ( "db_path" , db:: DB_PATH ) ?. set_override_option ( "db_path" , db_path)
0 commit comments