From 8f7f1f44f84c30e0e65da0c9d623f2de3ead0d9f Mon Sep 17 00:00:00 2001 From: poma Date: Wed, 15 Jan 2020 15:56:19 +0700 Subject: [PATCH] implement copy_json in rust --- phase2/src/bin/copy_json.rs | 30 ++++++++++++++++++++++++++++++ phase2/tools/copy_json.py | 23 ----------------------- 2 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 phase2/src/bin/copy_json.rs delete mode 100644 phase2/tools/copy_json.py diff --git a/phase2/src/bin/copy_json.rs b/phase2/src/bin/copy_json.rs new file mode 100644 index 0000000..71b11d0 --- /dev/null +++ b/phase2/src/bin/copy_json.rs @@ -0,0 +1,30 @@ +extern crate exitcode; +extern crate serde_json; + +use std::fs; +use serde_json::*; + +fn main() { + let args: Vec = std::env::args().collect(); + if args.len() != 4 { + println!("Usage: \n "); + std::process::exit(exitcode::USAGE); + } + let ref_file = &args[1]; + let in_file = &args[2]; + let out_file = &args[3]; + + let in_json: Map = serde_json::from_str(&fs::read_to_string(in_file).unwrap()).unwrap(); + let mut reference_json: Map = serde_json::from_str(&fs::read_to_string(ref_file).unwrap()).unwrap(); + + for (key, value) in &in_json { + reference_json[key] = value.clone(); + } + + if reference_json.contains_key("vk_alfabeta_12") { + reference_json.remove("vk_alfabeta_12").unwrap(); + } + + fs::write(out_file, serde_json::to_string(&reference_json).unwrap().as_bytes()).unwrap(); + println!("Done"); +} diff --git a/phase2/tools/copy_json.py b/phase2/tools/copy_json.py deleted file mode 100644 index 3c9055a..0000000 --- a/phase2/tools/copy_json.py +++ /dev/null @@ -1,23 +0,0 @@ -import json - -f = json.load(open('proving_key.json')) -f2 = json.load(open('pk.json')) - -for k in f2: - f[k] = f2[k] - -f3 = open('transformed_pk.json', 'w') -f3.write(json.dumps(f)) -f3.close() - -f = json.load(open('verification_key.json')) -f2 = json.load(open('vk.json')) - -for k in f2: - f[k] = f2[k] - -del f['vk_alfabeta_12'] - -f3 = open('transformed_vk.json', 'w') -f3.write(json.dumps(f)) -f3.close()