diff --git a/pbtc/cli.yml b/pbtc/cli.yml index 34617693..5e8f67a6 100644 --- a/pbtc/cli.yml +++ b/pbtc/cli.yml @@ -29,9 +29,10 @@ args: - diskdb: long: diskdb help: Use disk storage instead of in-memory one +subcommands: - import: - long: import - value_name: PATH - help: Import blocks from bitcoin core database - takes_value: true - + about: Import blocks from bitcoin core database + args: + - PATH: + required: true + help: Path of the bitcoin core database diff --git a/pbtc/config.rs b/pbtc/config.rs index dfc4db50..20065a65 100644 --- a/pbtc/config.rs +++ b/pbtc/config.rs @@ -9,7 +9,6 @@ pub struct Config { pub seednode: Option, pub print_to_console: bool, pub use_disk_database: bool, - pub import_path: Option, } pub fn parse(matches: &clap::ArgMatches) -> Result { @@ -40,11 +39,6 @@ pub fn parse(matches: &clap::ArgMatches) -> Result { None => None, }; - let import_path = match matches.value_of("import") { - Some(s) => Some(try!(s.parse().map_err(|_| "Invalid import path".to_owned()))), - None => None, - }; - let config = Config { print_to_console: print_to_console, magic: magic, @@ -52,7 +46,6 @@ pub fn parse(matches: &clap::ArgMatches) -> Result { connect: connect, seednode: seednode, use_disk_database: use_disk_database, - import_path: import_path, }; Ok(config) diff --git a/pbtc/main.rs b/pbtc/main.rs index bb46e607..459f6624 100644 --- a/pbtc/main.rs +++ b/pbtc/main.rs @@ -54,21 +54,27 @@ fn init_db(db: &Arc) { } } -fn import_blockchain(db_path: &str) { - for (_i, _blk) in import::open_blk_dir(db_path).expect("TODO").enumerate() { - // import logic goes here - } -} - fn run() -> Result<(), String> { let yaml = load_yaml!("cli.yml"); let matches = clap::App::from_yaml(yaml).get_matches(); - let cfg = try!(config::parse(&matches)); - if let Some(ref import_path) = cfg.import_path { - import_blockchain(import_path); - return Ok(()) + match matches.subcommand() { + ("import", Some(import_matches)) => import_blockchain(import_matches), + _ => start_pbtc(&matches), } +} + +fn import_blockchain(matches: &clap::ArgMatches) -> Result<(), String> { + let db_path = matches.value_of("PATH").expect("PATH is required in cli.yml; qed"); + let blk_dir = try!(import::open_blk_dir(db_path).map_err(|_| "Import directory does not exist".to_owned())); + for (_i, _blk) in blk_dir.enumerate() { + // import logic goes here + } + Ok(()) +} + +fn start_pbtc(matches: &clap::ArgMatches) -> Result<(), String> { + let cfg = try!(config::parse(matches)); let mut el = event_loop();