feat: works
This commit is contained in:
24
__crypto/simple_contract/src/cmd_genkey.rs
Normal file
24
__crypto/simple_contract/src/cmd_genkey.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use rust_util::failure;
|
||||
use crate::{cmd::{Command, CommandError}, util::{JsonKeyPair, make_key_pair}};
|
||||
pub struct CommandImpl;
|
||||
impl Command for CommandImpl {
|
||||
fn name(&self) -> &str { "genkey" }
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
SubCommand::with_name(self.name()).about("Generate key pair subcommand")
|
||||
.arg(Arg::with_name("output").long("output").short("o").required(true).takes_value(true).help("Key pair output"))
|
||||
}
|
||||
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
|
||||
let output = sub_arg_matches.value_of("output").unwrap();
|
||||
if let Ok(_) = File::open(output) {
|
||||
failure!("Output file exists: {}", output);
|
||||
return Ok(());
|
||||
}
|
||||
let (pri_key, pub_key) = make_key_pair();
|
||||
let json_key_pair = JsonKeyPair::from(pri_key, pub_key);
|
||||
fs::write(output, json_key_pair.to_json()?.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user