Create crate cw-prover (#31)

This commit is contained in:
Shoaib Ahmed 2023-12-19 14:46:47 +05:30 committed by GitHub
commit 61ee993f81
4 changed files with 2243 additions and 0 deletions

2146
utils/cw-prover/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
[package]
name = "cw-prover"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4.1.8", features = ["derive"] }
cosmrs = "0.15.0"
tendermint-rpc = { version = "0.34.0", features = ["http-client"] }
tokio = { version = "1.26.0", features = ["full"] }
serde_json = "1.0.108"

View file

@ -0,0 +1 @@
# CosmWasm prover

View file

@ -0,0 +1,83 @@
#![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;
use tendermint_rpc::{client::HttpClient as TmRpcClient, Client, HttpClientUrl};
#[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,
},
}
const WASM_STORE_KEY: &str = "/store/wasm/key";
const CONTRACT_STORE_PREFIX: u8 = 0x03;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::parse();
match args.command {
Command::CwQueryProofs {
rpc_url,
contract_address,
storage_key,
} => {
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
};
let client = TmRpcClient::builder(rpc_url).build()?;
let latest_height = client.status().await?.sync_info.latest_block_height;
let result = client
.abci_query(Some(path), data, Some(latest_height), true)
.await?;
println!(
"{}",
serde_json::to_string(&result).expect("infallible serializer")
);
}
};
Ok(())
}