2019-03-19 14:19:50 -07:00
|
|
|
use clap::{crate_description, crate_name, crate_version, App, Arg, SubCommand};
|
|
|
|
use solana_sdk::pubkey::write_pubkey;
|
|
|
|
use solana_sdk::signature::{gen_keypair_file, read_keypair, KeypairUtil};
|
2018-07-12 10:59:40 -07:00
|
|
|
use std::error;
|
|
|
|
|
2018-12-08 21:44:20 -08:00
|
|
|
fn main() -> Result<(), Box<dyn error::Error>> {
|
2019-03-13 20:54:30 -07:00
|
|
|
let matches = App::new(crate_name!())
|
|
|
|
.about(crate_description!())
|
2018-08-06 20:51:12 -07:00
|
|
|
.version(crate_version!())
|
2018-07-12 15:29:49 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("outfile")
|
|
|
|
.short("o")
|
|
|
|
.long("outfile")
|
|
|
|
.value_name("PATH")
|
|
|
|
.takes_value(true)
|
2018-09-14 15:32:57 -07:00
|
|
|
.help("Path to generated file"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
2019-03-19 14:19:50 -07:00
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("new")
|
|
|
|
.about("Generate new keypair file")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("outfile")
|
|
|
|
.short("o")
|
|
|
|
.long("outfile")
|
|
|
|
.value_name("PATH")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Path to generated file"),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("pubkey")
|
2019-04-23 19:24:42 -07:00
|
|
|
.about("Display the pubkey from a keypair file")
|
2019-03-19 14:19:50 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("infile")
|
|
|
|
.index(1)
|
|
|
|
.value_name("PATH")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Path to keypair file"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("outfile")
|
|
|
|
.short("o")
|
|
|
|
.long("outfile")
|
|
|
|
.value_name("PATH")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Path to generated file"),
|
|
|
|
),
|
|
|
|
)
|
2018-12-07 19:01:28 -08:00
|
|
|
.get_matches();
|
2018-07-12 15:29:49 -07:00
|
|
|
|
2019-03-19 14:19:50 -07:00
|
|
|
match matches.subcommand() {
|
|
|
|
("pubkey", Some(pubkey_matches)) => {
|
|
|
|
let mut path = dirs::home_dir().expect("home directory");
|
|
|
|
let infile = if pubkey_matches.is_present("infile") {
|
|
|
|
pubkey_matches.value_of("infile").unwrap()
|
|
|
|
} else {
|
|
|
|
path.extend(&[".config", "solana", "id.json"]);
|
|
|
|
path.to_str().unwrap()
|
|
|
|
};
|
|
|
|
let keypair = read_keypair(infile)?;
|
|
|
|
|
|
|
|
if pubkey_matches.is_present("outfile") {
|
|
|
|
let outfile = pubkey_matches.value_of("outfile").unwrap();
|
|
|
|
write_pubkey(outfile, keypair.pubkey())?;
|
|
|
|
} else {
|
|
|
|
println!("{}", keypair.pubkey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match_tuple => {
|
|
|
|
let working_matches = if let (_, Some(new_matches)) = match_tuple {
|
|
|
|
new_matches
|
|
|
|
} else {
|
|
|
|
&matches
|
|
|
|
};
|
2018-07-12 15:29:49 -07:00
|
|
|
|
2019-03-19 14:19:50 -07:00
|
|
|
let mut path = dirs::home_dir().expect("home directory");
|
|
|
|
let outfile = if working_matches.is_present("outfile") {
|
|
|
|
working_matches.value_of("outfile").unwrap()
|
|
|
|
} else {
|
|
|
|
path.extend(&[".config", "solana", "id.json"]);
|
|
|
|
path.to_str().unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
let serialized_keypair = gen_keypair_file(outfile.to_string())?;
|
|
|
|
if outfile == "-" {
|
|
|
|
println!("{}", serialized_keypair);
|
|
|
|
}
|
|
|
|
}
|
2018-07-12 15:29:49 -07:00
|
|
|
}
|
2019-03-19 14:19:50 -07:00
|
|
|
|
2018-07-12 10:59:40 -07:00
|
|
|
Ok(())
|
|
|
|
}
|