Cleanup solana-genesis

This commit is contained in:
Greg Fitzgerald 2018-07-01 08:04:41 -07:00 committed by Greg Fitzgerald
parent 1d812e78d5
commit b05e6ce3db
1 changed files with 8 additions and 12 deletions

View File

@ -6,31 +6,27 @@ extern crate solana;
use atty::{is, Stream};
use solana::mint::Mint;
use std::io::{stdin, Read};
use std::error;
use std::io::{stdin, stdout, Read, Write};
use std::process::exit;
fn main() {
fn main() -> Result<(), Box<error::Error>> {
if is(Stream::Stdin) {
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();
let num_bytes = stdin().read_to_string(&mut buffer)?;
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| {
eprintln!("failed to parse json: {}", e);
exit(1);
});
let mint: Mint = serde_json::from_str(&buffer)?;
let mut writer = stdout();
for x in mint.create_entries() {
let serialized = serde_json::to_string(&x).unwrap_or_else(|e| {
eprintln!("failed to serialize: {}", e);
exit(1);
});
println!("{}", serialized);
writeln!(writer, "{}", serde_json::to_string(&x)?)?;
}
Ok(())
}