Skip to content

Commit

Permalink
Merge pull request #4 from mel-project/custom-networks
Browse files Browse the repository at this point in the history
add support for custom bootstraps using MELBOOTSTRAP; update mainnet …
  • Loading branch information
nullchinchilla authored May 9, 2024
2 parents e0344f5 + f4f781c commit 8aa9ae0
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::net::{SocketAddr, ToSocketAddrs};
use std::{env, net::{SocketAddr, ToSocketAddrs}};

use once_cell::sync::Lazy;

Expand All @@ -20,6 +20,19 @@ static TESTNET_DNS_SEEDS: Lazy<Vec<SocketAddr>> = Lazy::new(|| {
.unwrap_or_default()
});

static CUSTOM_BOOTSTRAP: Lazy<Vec<(NetID, Checkpoint)>> = Lazy::new(|| {
match env::var("MELBOOTSTRAP") {
Ok(bootstrap) => bootstrap.split(',').filter_map(|s| {
let mut split = s.splitn(2, ':');
Some((
split.next()?.parse::<NetID>().ok()?,
split.next()?.parse::<Checkpoint>().ok()?,
))
}).collect(),
Err(_) => vec![],
}
});

/// Obtains bootstrap nodes for a given NetID.
pub fn bootstrap_routes(network: NetID) -> Vec<SocketAddr> {
match network {
Expand All @@ -31,9 +44,14 @@ pub fn bootstrap_routes(network: NetID) -> Vec<SocketAddr> {

/// Obtains a checkpoint for a given NetID.
pub fn checkpoint_height(network: NetID) -> Option<Checkpoint> {
let custom_bootstrap = CUSTOM_BOOTSTRAP.iter().find(|(id, _)| *id == network);
if let Some((_, checkpoint)) = custom_bootstrap {
return Some(checkpoint.clone());
}

match network {
NetID::Mainnet => Some(
"1959796:3790ffdfd3fb5e46432732a5433b18d2e9847d6e80b229f85a139c81aead75af"
"3210987:ad52471737a6024eca60a5b6e0ab6e699b8a653ec3851cb329bd6459e96e131c"
.parse()
.unwrap(),
),
Expand Down

0 comments on commit 8aa9ae0

Please sign in to comment.