2018-03-03 13:41:36 -08:00
|
|
|
//! A command-line executable for generating the chain's genesis block.
|
|
|
|
|
2018-06-13 15:07:36 -07:00
|
|
|
extern crate atty;
|
2018-07-12 14:42:01 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate clap;
|
2018-03-03 13:41:36 -08:00
|
|
|
extern crate serde_json;
|
2018-03-27 15:24:05 -07:00
|
|
|
extern crate solana;
|
2018-03-03 13:41:36 -08:00
|
|
|
|
2018-06-13 15:07:36 -07:00
|
|
|
use atty::{is, Stream};
|
2018-07-12 14:42:01 -07:00
|
|
|
use clap::{App, Arg};
|
2018-08-03 10:13:00 -07:00
|
|
|
use solana::entry_writer::EntryWriter;
|
2018-03-27 15:24:05 -07:00
|
|
|
use solana::mint::Mint;
|
2018-07-01 08:04:41 -07:00
|
|
|
use std::error;
|
2018-08-03 10:13:00 -07:00
|
|
|
use std::io::{stdin, stdout, Read};
|
2018-04-19 07:55:47 -07:00
|
|
|
use std::process::exit;
|
2018-03-03 13:41:36 -08:00
|
|
|
|
2018-07-01 08:04:41 -07:00
|
|
|
fn main() -> Result<(), Box<error::Error>> {
|
2018-07-12 14:42:01 -07:00
|
|
|
let matches = App::new("solana-genesis")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("tokens")
|
|
|
|
.short("t")
|
|
|
|
.long("tokens")
|
|
|
|
.value_name("NUMBER")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("Number of tokens with which to initialize mint"),
|
|
|
|
)
|
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
let tokens = value_t_or_exit!(matches, "tokens", i64);
|
|
|
|
|
2018-06-13 15:07:36 -07:00
|
|
|
if is(Stream::Stdin) {
|
2018-04-21 06:12:57 -07:00
|
|
|
eprintln!("nothing found on stdin, expected a json file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut buffer = String::new();
|
2018-07-01 08:04:41 -07:00
|
|
|
let num_bytes = stdin().read_to_string(&mut buffer)?;
|
2018-04-21 06:12:57 -07:00
|
|
|
if num_bytes == 0 {
|
|
|
|
eprintln!("empty file on stdin, expected a json file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2018-07-12 14:42:01 -07:00
|
|
|
let pkcs8: Vec<u8> = serde_json::from_str(&buffer)?;
|
|
|
|
let mint = Mint::new_with_pkcs8(tokens, pkcs8);
|
|
|
|
|
2018-08-03 10:13:00 -07:00
|
|
|
let mut writer = stdout();
|
|
|
|
EntryWriter::write_entries(&mut writer, mint.create_entries())?;
|
2018-07-01 08:04:41 -07:00
|
|
|
Ok(())
|
2018-03-03 13:41:36 -08:00
|
|
|
}
|