poa-bridge/src/main.rs

83 lines
1.5 KiB
Rust
Raw Normal View History

2017-06-25 04:21:13 -07:00
#[macro_use]
extern crate futures;
2017-08-02 03:45:15 -07:00
extern crate futures_after;
2017-06-25 04:21:13 -07:00
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate toml;
extern crate web3;
extern crate docopt;
2017-08-01 02:36:48 -07:00
extern crate tokio_core;
2017-08-02 03:45:15 -07:00
#[macro_use]
extern crate log;
extern crate env_logger;
#[macro_use]
extern crate error_chain;
2017-06-25 04:21:13 -07:00
2017-08-01 02:36:48 -07:00
mod api;
mod app;
2017-06-25 04:21:13 -07:00
mod config;
2017-08-01 02:36:48 -07:00
mod database;
2017-08-02 03:45:15 -07:00
pub mod error;
2017-08-01 02:36:48 -07:00
//mod l;
pub mod actions;
2017-06-25 04:21:13 -07:00
use std::env;
use std::path::PathBuf;
use docopt::Docopt;
2017-08-01 02:36:48 -07:00
use app::App;
2017-06-25 04:21:13 -07:00
use config::Config;
use error::Error;
const USAGE: &'static str = r#"
Ethereum-Kovan bridge.
Copyright 2017 Parity Technologies (UK) Limited
Usage:
bridge --config <config> --database <database>
bridge -h | --help
Options:
-h, --help Display help message and exit.
"#;
#[derive(Debug, Deserialize)]
pub struct Args {
arg_config: Option<PathBuf>,
arg_database: PathBuf,
}
fn main() {
2017-08-02 03:45:15 -07:00
let _ = env_logger::init();
2017-06-25 04:21:13 -07:00
let result = execute(env::args());
match result {
Ok(s) => println!("{}", s),
2017-08-02 03:45:15 -07:00
Err(err) => print_err(err),
2017-06-25 04:21:13 -07:00
}
}
2017-08-02 03:45:15 -07:00
fn print_err(err: Error) {
let message = err.iter().map(|e| e.to_string()).collect::<Vec<_>>().join("\n\nCaused by:\n ");
println!("{}", message);
}
2017-06-25 04:21:13 -07:00
fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item=S>, S: AsRef<str> {
let args: Args = Docopt::new(USAGE)
.and_then(|d| d.argv(command).deserialize())?;
let config = match args.arg_config {
Some(path) => Config::load(path)?,
None => Config::default(),
};
2017-08-01 02:36:48 -07:00
let app = App::new_ipc(config, args.arg_database)?;
2017-06-25 04:21:13 -07:00
Ok("Done".into())
}
#[cfg(test)]
mod tests {
}