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

View File

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