Add --outfile option to solana-keygen
This commit is contained in:
committed by
Greg Fitzgerald
parent
cea29ed772
commit
97372b8e63
@ -23,7 +23,7 @@ fi
|
|||||||
|
|
||||||
client_json="$SOLANA_CONFIG_CLIENT_DIR"/client.json
|
client_json="$SOLANA_CONFIG_CLIENT_DIR"/client.json
|
||||||
if [[ ! -r $client_json ]]; then
|
if [[ ! -r $client_json ]]; then
|
||||||
$solana_keygen > "$client_json"
|
$solana_keygen -o "$client_json"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2086 # $solana_client_demo should not be quoted
|
# shellcheck disable=SC2086 # $solana_client_demo should not be quoted
|
||||||
|
@ -84,7 +84,7 @@ if $node_type_leader; then
|
|||||||
mkdir -p "$SOLANA_CONFIG_PRIVATE_DIR"
|
mkdir -p "$SOLANA_CONFIG_PRIVATE_DIR"
|
||||||
|
|
||||||
echo "Creating $SOLANA_CONFIG_DIR/mint.json with $num_tokens tokens"
|
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"
|
echo "Creating $SOLANA_CONFIG_DIR/genesis.log"
|
||||||
$solana_genesis --tokens="$num_tokens" < "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json > "$SOLANA_CONFIG_DIR"/genesis.log
|
$solana_genesis --tokens="$num_tokens" < "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json > "$SOLANA_CONFIG_DIR"/genesis.log
|
||||||
|
@ -38,7 +38,7 @@ fi
|
|||||||
|
|
||||||
client_json="$SOLANA_CONFIG_CLIENT_DIR"/client.json
|
client_json="$SOLANA_CONFIG_CLIENT_DIR"/client.json
|
||||||
if [[ ! -r $client_json ]]; then
|
if [[ ! -r $client_json ]]; then
|
||||||
$solana_keygen > "$client_json"
|
$solana_keygen -o "$client_json"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
@ -23,7 +23,6 @@ fn main() -> Result<(), Box<error::Error>> {
|
|||||||
.value_name("NUMBER")
|
.value_name("NUMBER")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(true)
|
.required(true)
|
||||||
.default_value("0")
|
|
||||||
.help("Number of tokens with which to initialize mint"),
|
.help("Number of tokens with which to initialize mint"),
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
@ -1,14 +1,43 @@
|
|||||||
|
extern crate clap;
|
||||||
extern crate ring;
|
extern crate ring;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
|
use clap::{App, Arg};
|
||||||
use ring::rand::SystemRandom;
|
use ring::rand::SystemRandom;
|
||||||
use ring::signature::Ed25519KeyPair;
|
use ring::signature::Ed25519KeyPair;
|
||||||
use std::error;
|
use std::error;
|
||||||
|
use std::fs::{self, File};
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<error::Error>> {
|
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 rnd = SystemRandom::new();
|
||||||
let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8(&rnd)?;
|
let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8(&rnd)?;
|
||||||
let serialized = serde_json::to_string(&pkcs8_bytes.to_vec())?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user