From 1bedd8bcf498887ee18022c0f86bd2861299ed9c Mon Sep 17 00:00:00 2001 From: hu55a1n1 Date: Tue, 19 Dec 2023 01:11:07 -0800 Subject: [PATCH] Fix query data --- utils/cw-prover/Cargo.lock | 232 +----------------------------------- utils/cw-prover/Cargo.toml | 1 - utils/cw-prover/src/main.rs | 40 +++---- 3 files changed, 16 insertions(+), 257 deletions(-) diff --git a/utils/cw-prover/Cargo.lock b/utils/cw-prover/Cargo.lock index 17965ad..abf21eb 100644 --- a/utils/cw-prover/Cargo.lock +++ b/utils/cw-prover/Cargo.lock @@ -71,28 +71,6 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" -[[package]] -name = "async-stream" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" -dependencies = [ - "async-stream-impl", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.41", -] - [[package]] name = "async-trait" version = "0.1.74" @@ -110,51 +88,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "axum" -version = "0.6.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" -dependencies = [ - "async-trait", - "axum-core", - "bitflags", - "bytes", - "futures-util", - "http", - "http-body", - "hyper", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper", - "tower", - "tower-layer", - "tower-service", -] - -[[package]] -name = "axum-core" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "mime", - "rustversion", - "tower-layer", - "tower-service", -] - [[package]] name = "backtrace" version = "0.3.69" @@ -350,7 +283,6 @@ dependencies = [ "prost", "prost-types", "tendermint-proto", - "tonic", ] [[package]] @@ -422,7 +354,6 @@ name = "cw-prover" version = "0.1.0" dependencies = [ "clap", - "cosmos-sdk-proto", "cosmrs", "serde_json", "tendermint-rpc", @@ -705,19 +636,13 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 2.1.0", + "indexmap", "slab", "tokio", "tokio-util", "tracing", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.14.3" @@ -823,18 +748,6 @@ dependencies = [ "tokio-rustls", ] -[[package]] -name = "hyper-timeout" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" -dependencies = [ - "hyper", - "pin-project-lite", - "tokio", - "tokio-io-timeout", -] - [[package]] name = "idna" version = "0.5.0" @@ -851,16 +764,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - [[package]] name = "indexmap" version = "2.1.0" @@ -868,7 +771,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown", ] [[package]] @@ -935,12 +838,6 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -[[package]] -name = "matchit" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" - [[package]] name = "memchr" version = "2.6.4" @@ -1140,12 +1037,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - [[package]] name = "proc-macro2" version = "1.0.70" @@ -1196,27 +1087,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - [[package]] name = "rand_core" version = "0.6.4" @@ -1357,12 +1227,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - [[package]] name = "ryu" version = "1.0.16" @@ -1652,12 +1516,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - [[package]] name = "system-configuration" version = "0.5.1" @@ -1856,16 +1714,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-macros" version = "2.2.0" @@ -1887,17 +1735,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-stream" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-util" version = "0.7.10" @@ -1921,59 +1758,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tonic" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d560933a0de61cf715926b9cac824d4c883c2c43142f787595e48280c40a1d0e" -dependencies = [ - "async-stream", - "async-trait", - "axum", - "base64", - "bytes", - "h2", - "http", - "http-body", - "hyper", - "hyper-timeout", - "percent-encoding", - "pin-project", - "prost", - "tokio", - "tokio-stream", - "tower", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "indexmap 1.9.3", - "pin-project", - "pin-project-lite", - "rand", - "slab", - "tokio", - "tokio-util", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - [[package]] name = "tower-service" version = "0.3.2" @@ -1987,21 +1771,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.41", -] - [[package]] name = "tracing-core" version = "0.1.32" diff --git a/utils/cw-prover/Cargo.toml b/utils/cw-prover/Cargo.toml index c200324..525c330 100644 --- a/utils/cw-prover/Cargo.toml +++ b/utils/cw-prover/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [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"] } diff --git a/utils/cw-prover/src/main.rs b/utils/cw-prover/src/main.rs index f4a73dd..c78cc00 100644 --- a/utils/cw-prover/src/main.rs +++ b/utils/cw-prover/src/main.rs @@ -17,25 +17,8 @@ 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 for RawQueryRawContractStateRequest { - fn from(request: QueryRawContractStateRequest) -> Self { - Self { - address: request.contract_address.to_string(), - query_data: request.storage_key.into_bytes(), - } - } -} +use tendermint_rpc::{client::HttpClient as TmRpcClient, Client, HttpClientUrl}; #[derive(Debug, Parser)] #[command(author, version, about, long_about = None)] @@ -62,6 +45,9 @@ enum Command { }, } +const WASM_STORE_KEY: &str = "/store/wasm/key"; +const CONTRACT_STORE_PREFIX: u8 = 0x03; + #[tokio::main] async fn main() -> Result<(), Box> { let args = Cli::parse(); @@ -72,18 +58,20 @@ async fn main() -> Result<(), Box> { contract_address, storage_key, } => { - let path = "/store/wasm/key".to_owned(); - let request = QueryRawContractStateRequest { - 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 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?; + let result = client + .abci_query(Some(path), data, Some(latest_height), true) + .await?; + println!( "{}", serde_json::to_string(&result).expect("infallible serializer")