Add --outfile option to solana-keygen

This commit is contained in:
Greg Fitzgerald 2018-07-12 16:29:49 -06:00 committed by Greg Fitzgerald
parent cea29ed772
commit 97372b8e63
5 changed files with 33 additions and 5 deletions

View File

@ -23,7 +23,7 @@ fi
client_json="$SOLANA_CONFIG_CLIENT_DIR"/client.json
if [[ ! -r $client_json ]]; then
$solana_keygen > "$client_json"
$solana_keygen -o "$client_json"
fi
# shellcheck disable=SC2086 # $solana_client_demo should not be quoted

View File

@ -84,7 +84,7 @@ if $node_type_leader; then
mkdir -p "$SOLANA_CONFIG_PRIVATE_DIR"
echo "Creating $SOLANA_CONFIG_DIR/mint.json with $num_tokens tokens"
$solana_keygen > "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json
$solana_keygen -o "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json
echo "Creating $SOLANA_CONFIG_DIR/genesis.log"
$solana_genesis --tokens="$num_tokens" < "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json > "$SOLANA_CONFIG_DIR"/genesis.log

View File

@ -38,7 +38,7 @@ fi
client_json="$SOLANA_CONFIG_CLIENT_DIR"/client.json
if [[ ! -r $client_json ]]; then
$solana_keygen > "$client_json"
$solana_keygen -o "$client_json"
fi
set -x

View File

@ -23,7 +23,6 @@ fn main() -> Result<(), Box<error::Error>> {
.value_name("NUMBER")
.takes_value(true)
.required(true)
.default_value("0")
.help("Number of tokens with which to initialize mint"),
)
.get_matches();

View File

@ -1,14 +1,43 @@
extern crate clap;
extern crate ring;
extern crate serde_json;
use clap::{App, Arg};
use ring::rand::SystemRandom;
use ring::signature::Ed25519KeyPair;
use std::error;
use std::fs::{self, File};
use std::io::Write;
use std::path::Path;
fn main() -> Result<(), Box<error::Error>> {
let matches = App::new("solana-genesis")
.arg(
Arg::with_name("outfile")
.short("o")
.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();
let rnd = SystemRandom::new();
let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8(&rnd)?;
let serialized = serde_json::to_string(&pkcs8_bytes.to_vec())?;
println!("{}", serialized);
let outfile = matches.value_of("outfile").unwrap();
if outfile == "-" {
println!("{}", serialized);
} else {
if let Some(outdir) = Path::new(outfile).parent() {
fs::create_dir_all(outdir)?;
}
let mut f = File::create(outfile)?;
f.write_all(&serialized.into_bytes())?;
}
Ok(())
}