⚙️ examples
This commit is contained in:
parent
2b1aeba534
commit
cda8f39b4c
|
@ -1653,6 +1653,7 @@ dependencies = [
|
|||
"consensus",
|
||||
"execution",
|
||||
"eyre",
|
||||
"home",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
@ -1680,6 +1681,15 @@ dependencies = [
|
|||
"digest 0.10.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "home"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "0.2.8"
|
||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -27,9 +27,17 @@ ethers = { git = "https://github.com/ncitron/ethers-rs", branch = "fix-retry" }
|
|||
[dev-dependencies]
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
eyre = "0.6.8"
|
||||
home = "0.5.4"
|
||||
|
||||
[[example]]
|
||||
name = "checkpoints"
|
||||
path = "examples/checkpoints.rs"
|
||||
required-features = []
|
||||
|
||||
[[example]]
|
||||
name = "client"
|
||||
path = "examples/client.rs"
|
||||
|
||||
[[example]]
|
||||
name = "config"
|
||||
path = "examples/config.rs"
|
||||
|
||||
|
|
|
@ -142,6 +142,8 @@ async fn main() -> Result<()> {
|
|||
// Fetch the latest mainnet checkpoint
|
||||
let mainnet_checkpoint = cf.fetch_latest_checkpoint(&networks::Network::MAINNET).await.unwrap();
|
||||
println!("Fetched latest mainnet checkpoint: {}", mainnet_checkpoint);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -53,7 +53,8 @@ impl ClientBuilder {
|
|||
}
|
||||
|
||||
pub fn checkpoint(mut self, checkpoint: &str) -> Self {
|
||||
let checkpoint = hex::decode(checkpoint).expect("cannot parse checkpoint");
|
||||
let checkpoint = hex::decode(checkpoint.strip_prefix("0x").unwrap_or(checkpoint))
|
||||
.expect("cannot parse checkpoint");
|
||||
self.checkpoint = Some(checkpoint);
|
||||
self
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
use figment::{providers::Serialized, value::Value};
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Cli Config
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct CliConfig {
|
||||
pub execution_rpc: Option<String>,
|
||||
pub consensus_rpc: Option<String>,
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use eyre::Result;
|
||||
|
||||
use helios::prelude::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Create a new Helios Client Builder
|
||||
let mut builder = ClientBuilder::new();
|
||||
|
||||
// Set the network to mainnet
|
||||
builder = builder.network(networks::Network::MAINNET);
|
||||
|
||||
// Set the consensus rpc url
|
||||
builder = builder.consensus_rpc("https://www.lightclientdata.org");
|
||||
|
||||
// Set the execution rpc url
|
||||
builder = builder.execution_rpc("https://eth-mainnet.g.alchemy.com/v2/XXXXX");
|
||||
|
||||
// Set the checkpoint to the last known checkpoint
|
||||
builder =
|
||||
builder.checkpoint("85e6151a246e8fdba36db27a0c7678a575346272fe978c9281e13a8b26cdfa68");
|
||||
|
||||
// Set the rpc port
|
||||
builder = builder.rpc_port(8545);
|
||||
|
||||
// Set the data dir
|
||||
builder = builder.data_dir(PathBuf::from("/tmp/helios"));
|
||||
|
||||
// Set the fallback service
|
||||
builder = builder.fallback("https://sync-mainnet.beaconcha.in");
|
||||
|
||||
// Enable lazy checkpoints
|
||||
builder = builder.load_external_fallback();
|
||||
|
||||
// Build the client
|
||||
let _client = builder.build().unwrap();
|
||||
println!("Constructed client!");
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
use config::CliConfig;
|
||||
use eyre::Result;
|
||||
|
||||
use helios::prelude::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Load the config from the global config file
|
||||
let config_path = home::home_dir().unwrap().join(".helios/helios.toml");
|
||||
let config = Config::from_file(&config_path, "mainnet", &CliConfig::default());
|
||||
println!("Constructed config: {:#?}", config);
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue