From 60297403e68e8d996306f3f4883f6002051a1b5a Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Wed, 8 Nov 2017 21:09:43 -0700 Subject: [PATCH] Add `new` tool to repository for initializing the first challenge file. --- src/bin/new.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/new.rs diff --git a/src/bin/new.rs b/src/bin/new.rs new file mode 100644 index 0000000..a5bb301 --- /dev/null +++ b/src/bin/new.rs @@ -0,0 +1,24 @@ +extern crate powersoftau; +use powersoftau::*; + +use std::fs::OpenOptions; +use std::io::{Write, BufWriter}; + +fn main() { + let writer = OpenOptions::new() + .read(false) + .write(true) + .create_new(true) + .open("challenge").expect("unable to create `./challenge`"); + + let mut writer = BufWriter::new(writer); + + // Write a blank BLAKE2b hash: + writer.write_all(&blank_hash().as_slice()).expect("unable to write blank hash to `./challenge`"); + + let acc = Accumulator::new(); + acc.serialize(&mut writer, UseCompression::No).expect("unable to write fresh accumulator to `./challenge`"); + writer.flush().expect("unable to flush accumulator to disk"); + + println!("Wrote a fresh accumulator to `./challenge`"); +}