cycles-quartz/utils/cw-prover/src/main.rs

84 lines
2.2 KiB
Rust
Raw Normal View History

2023-12-14 11:18:19 +00:00
#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(
clippy::checked_conversions,
clippy::panic,
clippy::panic_in_result_fn,
clippy::unwrap_used,
missing_docs,
trivial_casts,
trivial_numeric_casts,
rust_2018_idioms,
unused_lifetimes,
unused_import_braces,
unused_qualifications
)]
use std::error::Error;
use clap::{Parser, Subcommand};
use cosmrs::AccountId;
2023-12-19 09:11:07 +00:00
use tendermint_rpc::{client::HttpClient as TmRpcClient, Client, HttpClientUrl};
2023-12-14 11:18:19 +00:00
#[derive(Debug, Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
/// Main command
#[command(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
/// Retrieve a merkle-proof for CosmWasm state
CwQueryProofs {
#[clap(long, default_value = "http://127.0.0.1:26657")]
rpc_url: HttpClientUrl,
/// Address of the CosmWasm contract
#[clap(long)]
contract_address: AccountId,
/// Storage key of the state item for which proofs must be retrieved
#[clap(long)]
storage_key: String,
},
}
2023-12-19 09:11:07 +00:00
const WASM_STORE_KEY: &str = "/store/wasm/key";
const CONTRACT_STORE_PREFIX: u8 = 0x03;
2023-12-14 11:18:19 +00:00
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::parse();
match args.command {
Command::CwQueryProofs {
rpc_url,
contract_address,
storage_key,
} => {
2023-12-19 09:11:07 +00:00
let path = WASM_STORE_KEY.to_owned();
let data = {
let mut data = vec![CONTRACT_STORE_PREFIX];
data.append(&mut contract_address.to_bytes());
data.append(&mut storage_key.into_bytes());
data
2023-12-14 11:18:19 +00:00
};
let client = TmRpcClient::builder(rpc_url).build()?;
let latest_height = client.status().await?.sync_info.latest_block_height;
2023-12-19 09:11:07 +00:00
let result = client
.abci_query(Some(path), data, Some(latest_height), true)
.await?;
2023-12-14 11:18:19 +00:00
println!(
"{}",
serde_json::to_string(&result).expect("infallible serializer")
);
}
};
Ok(())
}