From eaa45ca32f1c9ed35c7c4a0910ab382c387771af Mon Sep 17 00:00:00 2001 From: hu55a1n1 Date: Fri, 22 Dec 2023 05:54:14 -0800 Subject: [PATCH] Write proof to file --- utils/cw-prover/src/main.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/utils/cw-prover/src/main.rs b/utils/cw-prover/src/main.rs index 1233276..0851e50 100644 --- a/utils/cw-prover/src/main.rs +++ b/utils/cw-prover/src/main.rs @@ -15,6 +15,9 @@ )] use std::error::Error; +use std::fs::File; +use std::io::{BufWriter, Write}; +use std::path::PathBuf; use clap::{Parser, Subcommand}; use cosmrs::AccountId; @@ -56,6 +59,10 @@ enum Command { /// (only makes sense when dealing with maps) #[clap(long)] storage_namespace: Option, + + /// Output file to store merkle proof + #[clap(long)] + proof_file: Option, }, } @@ -72,6 +79,7 @@ async fn main() -> Result<(), Box> { contract_address, storage_key, storage_namespace, + proof_file, } => { let client = TmRpcClient::builder(rpc_url).build()?; let status = client.status().await?; @@ -83,8 +91,12 @@ async fn main() -> Result<(), Box> { .abci_query(Some(path), data, Some(proof_height), true) .await?; - let value = verify_proof(latest_app_hash, result)?; + let value = verify_proof(latest_app_hash, result.clone())?; println!("{}", String::from_utf8(value)?); + + if let Some(proof_file) = proof_file { + write_proof_to_file(proof_file, result)?; + } } }; @@ -144,3 +156,11 @@ fn verify_proof(latest_app_hash: AppHash, result: AbciQuery) -> Result, Ok(result.value) } + +fn write_proof_to_file(proof_file: PathBuf, output: AbciQuery) -> Result<(), Box> { + let file = File::create(proof_file)?; + let mut writer = BufWriter::new(file); + serde_json::to_writer(&mut writer, &output)?; + writer.flush()?; + Ok(()) +}