Skip to main content

urma_node/
config.rs

1//! Built-in defaults that need one home. Seeds are DNS names whose records the
2//! operator publishes; the daemon dials whatever they resolve to. Regtest and
3//! Bitcoin test chains have no seeds.
4use crate::Error;
5use libp2p::Multiaddr;
6use urma_chain::observation::Chain;
7
8pub const SEEDS: &[(Chain, &str)] = &[
9    (Chain::LitecoinMainnet, "/dnsaddr/ltc-seed.urma.rosint.org"),
10    (Chain::LitecoinTestnet, "/dnsaddr/tltc-seed.urma.rosint.org"),
11];
12
13/// Parsed built-in seeds for `chain`.
14pub fn seeds(chain: Chain) -> Result<Vec<Multiaddr>, Error> {
15    let genesis = |chain: Chain| {
16        chain
17            .genesis()
18            .map(|identity| identity.0)
19            .map_err(|error| Error::Invalid(error.to_string()))
20    };
21    let wanted = genesis(chain)?;
22    let mut seeds = Vec::new();
23    for (seeded, address) in SEEDS {
24        if genesis(*seeded)? == wanted {
25            let parsed = address
26                .parse()
27                .map_err(|error| Error::Invalid(format!("built-in seed {address}: {error}")))?;
28            seeds.push(parsed);
29        }
30    }
31    Ok(seeds)
32}