2018-03-03 14:41:36 -07:00
|
|
|
//! A command-line executable for generating the chain's genesis block.
|
|
|
|
|
2018-06-13 18:07:36 -04:00
|
|
|
extern crate atty;
|
2018-03-03 14:41:36 -07:00
|
|
|
extern crate serde_json;
|
2018-03-27 16:24:05 -06:00
|
|
|
extern crate solana;
|
2018-03-03 14:41:36 -07:00
|
|
|
|
2018-06-13 18:07:36 -04:00
|
|
|
use atty::{is, Stream};
|
2018-03-27 16:24:05 -06:00
|
|
|
use solana::mint::Mint;
|
2018-04-21 21:12:57 +08:00
|
|
|
use std::io::{stdin, Read};
|
2018-04-19 22:55:47 +08:00
|
|
|
use std::process::exit;
|
2018-03-03 14:41:36 -07:00
|
|
|
|
|
|
|
fn main() {
|
2018-06-13 18:07:36 -04:00
|
|
|
if is(Stream::Stdin) {
|
2018-04-21 21:12:57 +08:00
|
|
|
eprintln!("nothing found on stdin, expected a json file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut buffer = String::new();
|
|
|
|
let num_bytes = stdin().read_to_string(&mut buffer).unwrap();
|
|
|
|
if num_bytes == 0 {
|
|
|
|
eprintln!("empty file on stdin, expected a json file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mint: Mint = serde_json::from_str(&buffer).unwrap_or_else(|e| {
|
2018-04-19 22:55:47 +08:00
|
|
|
eprintln!("failed to parse json: {}", e);
|
|
|
|
exit(1);
|
|
|
|
});
|
2018-03-07 17:08:12 -07:00
|
|
|
for x in mint.create_entries() {
|
2018-04-19 22:55:47 +08:00
|
|
|
let serialized = serde_json::to_string(&x).unwrap_or_else(|e| {
|
|
|
|
eprintln!("failed to serialize: {}", e);
|
|
|
|
exit(1);
|
|
|
|
});
|
|
|
|
println!("{}", serialized);
|
2018-03-03 14:41:36 -07:00
|
|
|
}
|
|
|
|
}
|