From 77543d83ffb7578773513ca24632f95f7af9af4f Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 12 Jul 2018 17:04:42 -0600 Subject: [PATCH] Fix default keypair paths --- src/bin/keygen.rs | 10 ++++++++-- src/bin/wallet.rs | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/bin/keygen.rs b/src/bin/keygen.rs index 8b172428dd..9b65c0d881 100644 --- a/src/bin/keygen.rs +++ b/src/bin/keygen.rs @@ -5,6 +5,7 @@ extern crate serde_json; use clap::{App, Arg}; use ring::rand::SystemRandom; use ring::signature::Ed25519KeyPair; +use std::env; use std::error; use std::fs::{self, File}; use std::io::Write; @@ -18,7 +19,6 @@ fn main() -> Result<(), Box> { .long("outfile") .value_name("PATH") .takes_value(true) - .default_value("~/.config/solana/id.json") .help("Number of tokens with which to initialize mint"), ) .get_matches(); @@ -27,7 +27,13 @@ fn main() -> Result<(), Box> { let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8(&rnd)?; let serialized = serde_json::to_string(&pkcs8_bytes.to_vec())?; - let outfile = matches.value_of("outfile").unwrap(); + let mut path = env::home_dir().expect("home directory"); + let outfile = if matches.is_present("outfile") { + matches.value_of("outfile").unwrap() + } else { + path.extend(&[".config", "solana", "id.json"]); + path.to_str().unwrap() + }; if outfile == "-" { println!("{}", serialized); diff --git a/src/bin/wallet.rs b/src/bin/wallet.rs index fc167848a7..0b320fd8a2 100644 --- a/src/bin/wallet.rs +++ b/src/bin/wallet.rs @@ -13,6 +13,7 @@ use solana::drone::DroneRequest; use solana::fullnode::Config; use solana::signature::{read_keypair, KeyPair, KeyPairUtil, PublicKey, Signature}; use solana::thin_client::ThinClient; +use std::env; use std::error; use std::fmt; use std::fs::File; @@ -88,7 +89,6 @@ fn parse_args() -> Result> { .long("keypair") .value_name("PATH") .takes_value(true) - .default_value("~/.config/solana/id.json") .help("/path/to/id.json"), ) .subcommand( @@ -148,7 +148,14 @@ fn parse_args() -> Result> { leader = NodeInfo::new_leader(&server_addr); }; - let id = read_keypair(matches.value_of("keypair").unwrap()).expect("client keypair"); + let mut path = env::home_dir().expect("home directory"); + let id_path = if matches.is_present("keypair") { + matches.value_of("keypair").unwrap() + } else { + path.extend(&[".config", "solana", "id.json"]); + path.to_str().unwrap() + }; + let id = read_keypair(id_path).expect("client keypair"); let mut drone_addr = leader.contact_info.tpu; drone_addr.set_port(9900);