Create crate cw-prover
This commit is contained in:
parent
b8b231d546
commit
d6a3c53cc2
4 changed files with 2484 additions and 0 deletions
2374
utils/cw-prover/Cargo.lock
generated
Normal file
2374
utils/cw-prover/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
14
utils/cw-prover/Cargo.toml
Normal file
14
utils/cw-prover/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[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"] }
|
||||
cosmos-sdk-proto = { version = "0.20.0", features = ["cosmwasm"] }
|
||||
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"
|
1
utils/cw-prover/README.md
Normal file
1
utils/cw-prover/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# CosmWasm prover
|
95
utils/cw-prover/src/main.rs
Normal file
95
utils/cw-prover/src/main.rs
Normal file
|
@ -0,0 +1,95 @@
|
|||
#![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 cosmos_sdk_proto::cosmwasm::wasm::v1::QueryRawContractStateRequest as RawQueryRawContractStateRequest;
|
||||
use cosmos_sdk_proto::traits::Message;
|
||||
use cosmrs::AccountId;
|
||||
use tendermint_rpc::client::HttpClient as TmRpcClient;
|
||||
use tendermint_rpc::{Client, HttpClientUrl};
|
||||
|
||||
struct QueryRawContractStateRequest {
|
||||
pub contract_address: AccountId,
|
||||
pub storage_key: String,
|
||||
}
|
||||
|
||||
impl From<QueryRawContractStateRequest> for RawQueryRawContractStateRequest {
|
||||
fn from(request: QueryRawContractStateRequest) -> Self {
|
||||
Self {
|
||||
address: request.contract_address.to_string(),
|
||||
query_data: request.storage_key.into_bytes(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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,
|
||||
},
|
||||
}
|
||||
|
||||
#[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 = "/store/wasm/key".to_owned();
|
||||
let request = QueryRawContractStateRequest {
|
||||
contract_address,
|
||||
storage_key,
|
||||
};
|
||||
let raw_request = RawQueryRawContractStateRequest::from(request);
|
||||
let data = raw_request.encode_to_vec();
|
||||
|
||||
let client = TmRpcClient::builder(rpc_url).build()?;
|
||||
let latest_height = client.status().await?.sync_info.latest_block_height;
|
||||
println!("{:?}", latest_height);
|
||||
let result = client.abci_query(Some(path), data, Some(latest_height), true).await?;
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string(&result).expect("infallible serializer")
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue