Skip to content

Commit

Permalink
Add flag for interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ligustah committed Apr 11, 2024
1 parent a5a6071 commit 458fa87
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
const-hex = "1.11.3"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "fmt"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "fmt", "json"] }
test-log = { version = "0.2.15", features = ["trace"] }
libp2p = { version = "0.53.2", features = [
"tokio",
Expand Down
13 changes: 10 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::chain_list::CHAINS;
use crate::types::PremintName;
use envconfig::Envconfig;
use std::collections::HashMap;
use std::env;
use std::error::Error;
use std::str::FromStr;

use envconfig::Envconfig;

use crate::chain_list::CHAINS;
use crate::types::PremintName;

#[derive(Envconfig, Debug)]
pub struct Config {
#[envconfig(from = "SEED")]
Expand Down Expand Up @@ -52,6 +54,9 @@ pub struct Config {

#[envconfig(from = "EXTERNAL_ADDRESS")]
pub external_address: Option<String>,

#[envconfig(from = "INTERACTIVE", default = "false")]
pub interactive: bool,
}

#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -156,6 +161,7 @@ mod test {
trusted_peers: None,
node_id: None,
external_address: None,
interactive: false,
};

let names = config.premint_names();
Expand All @@ -178,6 +184,7 @@ mod test {
trusted_peers: None,
node_id: None,
external_address: None,
interactive: false,
};

let names = config.premint_names();
Expand Down
34 changes: 27 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
use clap::Parser;
use tokio::signal::unix::{signal, SignalKind};
use tracing_subscriber::EnvFilter;

use mintpool::api;
use mintpool::run::start_services;
use mintpool::stdin::watch_stdin;
use tracing_subscriber::EnvFilter;

#[tokio::main]
async fn main() -> eyre::Result<()> {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.pretty()
.try_init();

let config = mintpool::config::init();

if config.interactive {}
let subscriber = tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env());

match config.interactive {
true => subscriber.pretty().try_init(),
false => subscriber.json().try_init(),
}
.expect("Unable to initialize logger");

tracing::info!("Starting mintpool with config: {:?}", config);

let ctl = start_services(&config).await?;

let router = api::make_router(&config, ctl.clone()).await;
api::start_api(&config, router).await?;

watch_stdin(ctl).await;
if config.interactive {
watch_stdin(ctl).await;
} else {
let mut sigint = signal(SignalKind::interrupt())?;
let mut sigterm = signal(SignalKind::terminate())?;

tokio::select! {
_ = sigint.recv() => {
tracing::info!("Received SIGINT, shutting down");
}
_ = sigterm.recv() => {
tracing::info!("Received SIGTERM, shutting down");
}
}
}

Ok(())
}
Expand Down

0 comments on commit 458fa87

Please sign in to comment.