solana/src/bin/genesis.rs

32 lines
838 B
Rust
Raw Normal View History

//! A command-line executable for generating the chain's genesis block.
2018-06-13 15:07:36 -07:00
extern crate atty;
extern crate serde_json;
2018-03-27 15:24:05 -07:00
extern crate solana;
2018-06-13 15:07:36 -07:00
use atty::{is, Stream};
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;
use std::io::{stdin, stdout, Read};
2018-04-19 07:55:47 -07:00
use std::process::exit;
2018-07-01 08:04:41 -07:00
fn main() -> Result<(), Box<error::Error>> {
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-01 08:04:41 -07:00
let mint: Mint = serde_json::from_str(&buffer)?;
2018-07-01 13:31:13 -07:00
let mut writer = stdout();
EntryWriter::write_entries(&mut writer, mint.create_entries())?;
2018-07-01 08:04:41 -07:00
Ok(())
}