2018-03-22 19:53:47 +03:00
|
|
|
extern crate grin_core;
|
|
|
|
extern crate grin_keychain;
|
|
|
|
|
2019-03-15 17:32:14 +03:00
|
|
|
use grin_core::core::{Block, CompactBlock, Transaction};
|
2018-06-14 15:16:14 +03:00
|
|
|
use grin_core::ser;
|
|
|
|
use std::fs::{self, File};
|
2019-03-15 17:32:14 +03:00
|
|
|
use std::path::Path;
|
2018-03-22 19:53:47 +03:00
|
|
|
|
|
|
|
fn main() {
|
2019-03-15 17:32:14 +03:00
|
|
|
generate("transaction_read", Transaction::default()).unwrap();
|
|
|
|
generate("block_read", Block::default()).unwrap();
|
|
|
|
generate("compact_block_read", CompactBlock::from(Block::default())).unwrap();
|
2018-03-22 19:53:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn generate<W: ser::Writeable>(target: &str, obj: W) -> Result<(), ser::Error> {
|
|
|
|
let dir_path = Path::new("corpus").join(target);
|
|
|
|
if !dir_path.is_dir() {
|
2018-08-09 12:37:11 +03:00
|
|
|
fs::create_dir_all(&dir_path).map_err(|e| {
|
|
|
|
println!("fail: {}", e);
|
|
|
|
ser::Error::IOErr("can't create corpus directory".to_owned(), e.kind())
|
|
|
|
})?;
|
2018-03-22 19:53:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let pattern_path = dir_path.join("pattern");
|
|
|
|
if !pattern_path.exists() {
|
2018-08-09 12:37:11 +03:00
|
|
|
let mut file = File::create(&pattern_path)
|
|
|
|
.map_err(|e| ser::Error::IOErr("can't create a pattern file".to_owned(), e.kind()))?;
|
2018-03-22 19:53:47 +03:00
|
|
|
ser::serialize(&mut file, &obj)
|
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|