Files
nym/explorer-api/src/main.rs
T
Dave Hrycyszyn b36ca2c4f1 Add Network Explorer API (#720)
* Adding the explorer API

* Added explorer-api to workspace

* Re-jigged explorer api cargo paths

* Fixed compiler warnings

* Removing unused code

* network-explorer-api: configure state with env var API_STATE_FILE or fall back to default value of `explorer-api-state.json`

* network-explorer-api: updates to `Cargo.lock` file after rebasing

* network-explorer-api: make clippy happy
2021-08-04 12:38:35 +01:00

73 lines
1.9 KiB
Rust

#[macro_use]
extern crate rocket;
#[macro_use]
extern crate rocket_okapi;
use log::info;
mod country_statistics;
mod http;
mod ping;
mod state;
const VALIDATOR_API: &str = "http://testnet-milhon-validator1.nymtech.net:8080";
const CONTRACT: &str = "punk10pyejy66429refv3g35g2t7am0was7yalwrzen";
const GEO_IP_SERVICE: &str = "https://freegeoip.app/json/";
#[tokio::main]
async fn main() {
setup_logging();
let mut explorer_api = ExplorerApi::new();
explorer_api.run().await;
}
pub struct ExplorerApi {
state: state::ExplorerApiStateContext,
}
impl ExplorerApi {
fn new() -> ExplorerApi {
ExplorerApi {
state: state::ExplorerApiStateContext::new(),
}
}
async fn run(&mut self) {
info!("Explorer API starting up...");
// spawn concurrent tasks
country_statistics::CountryStatistics::new(self.state.clone()).start();
http::start(self.state.clone());
// wait for user to press ctrl+C
self.wait_for_interrupt().await
}
async fn wait_for_interrupt(&self) {
if let Err(e) = tokio::signal::ctrl_c().await {
error!(
"There was an error while capturing SIGINT - {:?}. We will terminate regardless",
e
);
}
info!(
"Received SIGINT - the mixnode will terminate now (threads are not yet nicely stopped, if you see stack traces that's alright)."
);
}
}
fn setup_logging() {
let mut log_builder = pretty_env_logger::formatted_timed_builder();
if let Ok(s) = ::std::env::var("RUST_LOG") {
log_builder.parse_filters(&s);
} else {
// default to 'Info'
log_builder.filter(None, log::LevelFilter::Info);
}
log_builder
.filter_module("tokio_reactor", log::LevelFilter::Warn)
.filter_module("reqwest", log::LevelFilter::Warn)
.init();
}