|
| 1 | +use alto_client::{consensus::Message, Client}; |
| 2 | +use clap::{value_parser, Arg, Command}; |
| 3 | +use commonware_cryptography::bls12381::PublicKey; |
| 4 | +use commonware_utils::from_hex_formatted; |
| 5 | +use futures::StreamExt; |
| 6 | +use tracing::info; |
| 7 | + |
| 8 | +#[tokio::main] |
| 9 | +async fn main() { |
| 10 | + // Parse arguments |
| 11 | + let matches = Command::new("inspector") |
| 12 | + .about("Monitor alto activity.") |
| 13 | + .arg( |
| 14 | + Arg::new("indexer") |
| 15 | + .long("indexer") |
| 16 | + .required(false) |
| 17 | + .value_parser(value_parser!(String)), |
| 18 | + ) |
| 19 | + .arg( |
| 20 | + Arg::new("identity") |
| 21 | + .long("identity") |
| 22 | + .required(false) |
| 23 | + .value_parser(value_parser!(String)), |
| 24 | + ) |
| 25 | + .get_matches(); |
| 26 | + |
| 27 | + // Create logger |
| 28 | + tracing_subscriber::fmt().init(); |
| 29 | + |
| 30 | + // Parse the identity |
| 31 | + let identity = matches.get_one::<String>("identity").unwrap(); |
| 32 | + let identity = from_hex_formatted(identity).unwrap(); |
| 33 | + let identity = PublicKey::try_from(identity).expect("Invalid identity"); |
| 34 | + |
| 35 | + // Connect to the indexer |
| 36 | + let indexer = matches.get_one::<String>("indexer").unwrap(); |
| 37 | + let client = Client::new(indexer, identity); |
| 38 | + |
| 39 | + // Stream the chain |
| 40 | + let mut stream = client |
| 41 | + .register() |
| 42 | + .await |
| 43 | + .expect("Failed to connect to indexer"); |
| 44 | + while let Some(message) = stream.next().await { |
| 45 | + let message = message.expect("Failed to receive message"); |
| 46 | + match message { |
| 47 | + Message::Seed(seed) => { |
| 48 | + info!(view = seed.view, "seed"); |
| 49 | + } |
| 50 | + Message::Notarization(notarized) => { |
| 51 | + info!( |
| 52 | + view = notarized.proof.view, |
| 53 | + height = notarized.block.height, |
| 54 | + timestamp = notarized.block.timestamp, |
| 55 | + digest = ?notarized.block.digest(), |
| 56 | + "notarized"); |
| 57 | + } |
| 58 | + Message::Finalization(finalized) => { |
| 59 | + info!( |
| 60 | + view = finalized.proof.view, |
| 61 | + height = finalized.block.height, |
| 62 | + timestamp = finalized.block.timestamp, |
| 63 | + digest = ?finalized.block.digest(), |
| 64 | + "finalized" |
| 65 | + ); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments