sonobe/cli/src/main.rs
cli/src/main.rsRaw
1use ::clap::Parser;
2use ark_serialize::Write;
3use settings::Cli;
4use std::path::Path;
5use std::{fs, io};
6
7mod settings;
8
9fn create_or_open_then_write<T: AsRef<[u8]>>(path: &Path, content: &T) -> Result<(), io::Error> {
10 let mut file = fs::OpenOptions::new().create(true).write(true).open(path)?;
11 file.write_all(content.as_ref())
12}
13
14fn main() {
15 let cli = Cli::parse();
16
17 // generate a subscriber with the desired log level
18 env_logger::builder()
19 .format_timestamp_secs()
20 .filter_level(cli.verbosity.log_level_filter())
21 .init();
22
23 let out_path = cli.out;
24
25 // Fetch the exact protocol for which we need to generate the Decider verifier contract.
26 let protocol = cli.protocol;
27 // Fetch the protocol data passed by the user from the file.
28 let protocol_vk = std::fs::read(cli.protocol_vk).unwrap();
29
30 // Generate the Solidity Verifier contract for the selected protocol with the given data.
31 create_or_open_then_write(
32 &out_path,
33 &protocol.render(&protocol_vk, cli.pragma).unwrap(),
34 )
35 .unwrap();
36}