bark/config.rs
1
2use std::path::PathBuf;
3
4use bitcoin::{FeeRate, Network};
5
6use bitcoin_ext::{BlockDelta, BlockHeight};
7
8
9/// Configuration of the Bark wallet.
10///
11/// - [Config::esplora_address] or [Config::bitcoind_address] must be provided.
12/// - If you use [Config::bitcoind_address], you must also provide:
13/// - [Config::bitcoind_cookiefile] or
14/// - [Config::bitcoind_user] and [Config::bitcoind_pass]
15/// - Other optional fields can be omitted.
16///
17/// # Example
18/// Configure the wallet using defaults, then override endpoints for public signet:
19///
20/// ```rust
21/// use bark::Config;
22///
23/// let cfg = Config {
24/// server_address: "https://ark.signet.2nd.dev".into(),
25/// esplora_address: Some("https://esplora.signet.2nd.dev".into()),
26/// ..Config::network_default(bitcoin::Network::Bitcoin)
27/// };
28/// // cfg now has all other fields from the default configuration
29/// ```
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct Config {
32 /// The address of your ark server.
33 pub server_address: String,
34
35 /// The address of the Esplora HTTP REST server to use.
36 ///
37 /// Either this or the `bitcoind_address` field has to be provided.
38 pub esplora_address: Option<String>,
39
40 /// The address of the bitcoind RPC server to use.
41 ///
42 /// Either this or the `esplora_address` field has to be provided.
43 /// Either `bitcoind_cookiefile` or `bitcoind_user` and `bitcoind_pass` has to be provided.
44 pub bitcoind_address: Option<String>,
45
46 /// The path to the bitcoind rpc cookie file.
47 ///
48 /// Only used with `bitcoind_address`.
49 pub bitcoind_cookiefile: Option<PathBuf>,
50
51 /// The bitcoind RPC username.
52 ///
53 /// Only used with `bitcoind_address`.
54 pub bitcoind_user: Option<String>,
55
56 /// The bitcoind RPC password.
57 ///
58 /// Only used with `bitcoind_address`.
59 pub bitcoind_pass: Option<String>,
60
61 /// The number of blocks before expiration to refresh vtxos.
62 ///
63 /// Default value: 288 (48 hrs)
64 pub vtxo_refresh_expiry_threshold: BlockHeight,
65
66 /// An upper limit of the number of blocks we expect to need to
67 /// safely exit the vtxos.
68 ///
69 /// Default value: 12
70 pub vtxo_exit_margin: BlockDelta,
71
72 /// The number of blocks to claim a HTLC-recv VTXO.
73 ///
74 /// Default value: 18
75 pub htlc_recv_claim_delta: BlockDelta,
76
77 /// A fallback fee rate to use in sat/kWu when we fail to retrieve a fee rate from the
78 /// configured bitcoind/esplora connection.
79 ///
80 /// Example for 1 sat/vB: --fallback-fee-rate 250
81 pub fallback_fee_rate: Option<FeeRate>,
82
83 // TODO: we set this to 0 by default for now to avoid breaking UX,
84 // but we should increase it eventually
85 /// The number of blocks after which a round tx is considered deeply confirmed.
86 ///
87 /// Default value: 0 (disabled)
88 pub deep_round_confirmations: BlockDelta,
89}
90
91impl Config {
92 /// A network-dependent default config that sets some useful defaults
93 ///
94 /// The [Default::default] provides a sane default for mainnet
95 pub fn network_default(network: Network) -> Self {
96 let mut ret = Self {
97 server_address: "http://127.0.0.1:3535".to_owned(),
98 esplora_address: None,
99 bitcoind_address: None,
100 bitcoind_cookiefile: None,
101 bitcoind_user: None,
102 bitcoind_pass: None,
103 vtxo_refresh_expiry_threshold: 144,
104 vtxo_exit_margin: 12,
105 htlc_recv_claim_delta: 18,
106 fallback_fee_rate: None,
107 deep_round_confirmations: 0,
108 };
109
110 if network != Network::Bitcoin {
111 ret.vtxo_refresh_expiry_threshold = 12;
112 ret.fallback_fee_rate = Some(FeeRate::from_sat_per_vb_unchecked(1));
113 }
114 ret
115 }
116}
117