Skip to content

Commit

Permalink
feat: wrap up v0
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Feb 2, 2025
1 parent b8f1d73 commit a17a31d
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 121 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ clap_generate = "3.0.3"
clap_complete = "4.5.44"
crossterm = "0.28.1"
ratatui = "0.29.0"
chrono = "0.4"

[features]
default = ["cli"]
Expand Down
7 changes: 5 additions & 2 deletions crates/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{CommandFactory, Parser, Subcommand};
use clap::{ArgAction, CommandFactory, Parser, Subcommand};
use clap_complete::{Generator, Shell};
use hiro_system_kit::{self, Logger};
use std::{fs::File, process};
Expand Down Expand Up @@ -69,9 +69,12 @@ pub struct StartSimnet {
/// Set the ip
#[arg(long = "ip", short = 'i', default_value = DEFAULT_BINDING_ADDRESS )]
pub network_binding_ip_address: String,
/// Display streams of logs instead of terminal UI dashboard
/// Display streams of logs instead of terminal UI dashboard (default: false)
#[clap(long = "no-tui")]
pub no_tui: bool,
/// Include debug logs (default: false)
#[clap(long = "debug", action=ArgAction::SetTrue)]
pub debug: bool,
}

#[derive(Parser, PartialEq, Clone, Debug)]
Expand Down
29 changes: 21 additions & 8 deletions crates/cli/src/cli/simnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,52 @@ pub fn handle_start_simnet_command(cmd: &StartSimnet, ctx: &Context) -> Result<(
.map_err(|e| format!("{}", e))?;
// Start frontend - kept on main thread
if cmd.no_tui {
log_events(simnet_events_rx, ctx);
log_events(simnet_events_rx, cmd.debug, ctx);
} else {
tui::simnet::start_app(simnet_events_rx).map_err(|e| format!("{}", e))?;
tui::simnet::start_app(simnet_events_rx, cmd.debug).map_err(|e| format!("{}", e))?;
}
handle.join().map_err(|_e| format!("unable to terminate"))?
}

fn log_events(simnet_events_rx: Receiver<SimnetEvent>, ctx: &Context) {
fn log_events(simnet_events_rx: Receiver<SimnetEvent>, include_debug_logs: bool, ctx: &Context) {
info!(
ctx.expect_logger(),
"Surfpool: The best place to train before surfing Solana"
);
while let Ok(event) = simnet_events_rx.recv() {
match event {
SimnetEvent::AccountUpdate(account) => {
SimnetEvent::AccountUpdate(_, account) => {
info!(
ctx.expect_logger(),
"Account retrieved from Mainnet {}", account
);
}
SimnetEvent::EpochInfoUpdate(epoch_info) => {
info!(
ctx.expect_logger(),
"Connection established. Epoch {}, Slot {}.",
epoch_info.epoch,
epoch_info.slot_index
);
}
SimnetEvent::ClockUpdate(clock) => {
info!(ctx.expect_logger(), "Slot #{} ", clock.slot);
}
SimnetEvent::ErroLog(log) => {
SimnetEvent::ErroLog(_, log) => {
error!(ctx.expect_logger(), "{} ", log);
}
SimnetEvent::InfoLog(log) => {
SimnetEvent::InfoLog(_, log) => {
info!(ctx.expect_logger(), "{} ", log);
}
SimnetEvent::WarnLog(log) => {
SimnetEvent::WarnLog(_, log) => {
warn!(ctx.expect_logger(), "{} ", log);
}
SimnetEvent::TransactionReceived(transaction) => {
SimnetEvent::DebugLog(_, log) => {
if include_debug_logs {
debug!(ctx.expect_logger(), "{} ", log);
}
}
SimnetEvent::TransactionReceived(_, _transaction) => {
info!(ctx.expect_logger(), "Transaction received");
}
SimnetEvent::BlockHashExpired => {}
Expand Down
Loading

0 comments on commit a17a31d

Please sign in to comment.