1use std::net::{SocketAddr, IpAddr, Ipv4Addr};
4use std::time::Duration;
5
6#[derive(Debug, Clone)]
8pub struct ResolverConfig {
9 pub dns_resolver: SocketAddr,
11
12 pub enforce_dnssec: bool,
14
15 pub timeout_ms: u64,
17
18 pub allow_http_fallback: bool,
21
22 pub network: bitcoin::Network,
24}
25
26impl Default for ResolverConfig {
27 fn default() -> Self {
28 Self {
29 dns_resolver: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)), 53),
31 enforce_dnssec: true,
32 timeout_ms: 5000, allow_http_fallback: true,
34 network: bitcoin::Network::Bitcoin,
35 }
36 }
37}
38
39impl ResolverConfig {
40 pub fn testnet() -> Self {
42 Self {
43 network: bitcoin::Network::Testnet,
44 ..Default::default()
45 }
46 }
47
48 pub fn signet() -> Self {
50 Self {
51 network: bitcoin::Network::Signet,
52 ..Default::default()
53 }
54 }
55
56 pub fn regtest() -> Self {
58 Self {
59 network: bitcoin::Network::Regtest,
60 ..Default::default()
61 }
62 }
63
64 pub fn with_dns_resolver(mut self, resolver: SocketAddr) -> Self {
66 self.dns_resolver = resolver;
67 self
68 }
69
70 pub fn with_dnssec(mut self, enforce: bool) -> Self {
72 self.enforce_dnssec = enforce;
73 self
74 }
75
76 pub fn with_timeout(mut self, timeout: Duration) -> Self {
78 self.timeout_ms = timeout.as_millis() as u64;
79 self
80 }
81
82 pub fn with_http_fallback(mut self, allow: bool) -> Self {
84 self.allow_http_fallback = allow;
85 self
86 }
87
88 pub fn with_network(mut self, network: bitcoin::Network) -> Self {
90 self.network = network;
91 self
92 }
93
94 pub fn timeout(&self) -> Duration {
96 Duration::from_millis(self.timeout_ms)
97 }
98}