forked from paradigmxyz/reth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use chrono::{DateTime, Utc}; | ||
use clap::{Parser, Subcommand}; | ||
use discv5::enr::Enr; | ||
use secp256k1::SecretKey; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{collections::HashMap, fs::File, io::Read, path::PathBuf}; | ||
|
||
/// The arguments for the `reth p2p nodeset` command | ||
#[derive(Parser, Debug)] | ||
pub struct Command { | ||
#[clap(subcommand)] | ||
subcommand: Subcommands, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Record { | ||
seq: u64, | ||
record: Enr<SecretKey>, | ||
score: i64, | ||
firstResponse: DateTime<Utc>, | ||
lastResponse: DateTime<Utc>, | ||
lastCheck: DateTime<Utc>, | ||
} | ||
|
||
impl Command { | ||
/// Execute `p2p nodeset` command | ||
pub fn execute(self) -> eyre::Result<()> { | ||
match self.subcommand { | ||
Subcommands::Info { file } => { | ||
let mut f = File::open(file)?; | ||
let mut content = String::new(); | ||
f.read_to_string(&mut content).expect("failed to read file"); | ||
|
||
let nodes: HashMap<String, Record> = | ||
serde_json::from_str(&content).expect("failed to deserialize json"); | ||
|
||
for (key, node) in nodes.iter() { | ||
println!("id: {}, node: {:#?}", key, node); | ||
} | ||
} | ||
Subcommands::Filter => { | ||
println!("Filter not implemented yet"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
enum Subcommands { | ||
/// Show statics about a node set | ||
Info { | ||
/// The path of the JSON file used to store node set. | ||
#[arg(long, value_name = "FILE", verbatim_doc_comment)] | ||
file: PathBuf, | ||
}, | ||
/// Filters a node set | ||
Filter, | ||
} |