keyfork/keyforkd/src/main.rs

48 lines
1.3 KiB
Rust
Raw Normal View History

2023-08-25 06:32:21 +00:00
use keyfork_mnemonic_util::Mnemonic;
use tokio::io::{self, AsyncBufReadExt, BufReader};
#[cfg(feature = "tracing")]
use tracing::debug;
#[cfg(feature = "tracing")]
use tracing_subscriber::{
filter::{EnvFilter, LevelFilter},
fmt::{format::FmtSpan, layer},
prelude::*,
registry,
};
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
async fn load_mnemonic() -> Result<Mnemonic> {
let mut stdin = BufReader::new(io::stdin());
let mut line = String::new();
stdin.read_line(&mut line).await?;
Ok(line.parse()?)
}
#[cfg(feature = "tracing")]
fn setup_registry() {
let envfilter = EnvFilter::builder()
.with_default_directive(LevelFilter::DEBUG.into())
.from_env_lossy();
registry()
.with(envfilter)
.with(layer().with_span_events(FmtSpan::CLOSE))
.with(tracing_error::ErrorLayer::default())
.init();
}
#[cfg_attr(feature = "multithread", tokio::main)]
#[cfg_attr(not(feature = "multithread"), tokio::main(flavor = "current_thread"))]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "tracing")]
setup_registry();
#[cfg(feature = "tracing")]
debug!("reading mnemonic from standard input");
let mnemonic = load_mnemonic().await?;
keyforkd::start_and_run_server(mnemonic).await
2023-08-25 06:32:21 +00:00
}