included sample contract queries
This commit is contained in:
Generated
+11
@@ -8601,6 +8601,17 @@ dependencies = [
|
||||
"psl-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "query-tester"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"nym-network-defaults",
|
||||
"nym-validator-client",
|
||||
"serde",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "2.0.1"
|
||||
|
||||
+1
-1
@@ -166,7 +166,7 @@ members = [
|
||||
"wasm/node-tester",
|
||||
"wasm/zknym-lib",
|
||||
"nym-gateway-probe"
|
||||
]
|
||||
, "query-tester"]
|
||||
|
||||
default-members = [
|
||||
"clients/native",
|
||||
|
||||
@@ -140,7 +140,8 @@ clippy: sdk-wasm-lint
|
||||
|
||||
WASM_CONTRACT_DIR := contracts/target/wasm32-unknown-unknown/release
|
||||
# Find every direct contract folder that contains a Cargo.toml
|
||||
CONTRACT_DIRS := $(shell find contracts -type f -name Cargo.toml \( ! -path "contracts/Cargo.toml" \) | grep -v integration-tests | xargs -n1 dirname | sort -u)
|
||||
#CONTRACT_DIRS := $(shell find contracts -type f -name Cargo.toml \( ! -path "contracts/Cargo.toml" \) | grep -v integration-tests | xargs -n1 dirname | sort -u)
|
||||
CONTRACT_DIRS := contracts/example-contract
|
||||
|
||||
CONTRACTS_OUT_DIR = contracts/artifacts
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
wasm:
|
||||
RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown
|
||||
|
||||
generate-schema:
|
||||
cargo schema
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use cosmwasm_std::{
|
||||
entry_point, to_json_binary, Addr, Coin, Deps, DepsMut, Env, MessageInfo, QueryResponse,
|
||||
entry_point, to_json_binary, Addr, Coin, Deps, DepsMut, Env, Event, MessageInfo, QueryResponse,
|
||||
Response,
|
||||
};
|
||||
use cw_storage_plus::Item;
|
||||
@@ -69,7 +69,7 @@ pub fn execute(
|
||||
.map_err(|err| err.to_string())?;
|
||||
}
|
||||
}
|
||||
Ok(Response::default())
|
||||
Ok(Response::new().add_event(Event::new("my-amazing-event").add_attribute("key1", "value1")))
|
||||
}
|
||||
|
||||
#[entry_point]
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "query-tester"
|
||||
version = "0.1.0"
|
||||
authors.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
documentation.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
readme.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
anyhow = { workspace = true }
|
||||
nym-validator-client = { path = "../common/client-libs/validator-client" }
|
||||
nym-network-defaults = { path = "../common/network-defaults" }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,76 @@
|
||||
use nym_network_defaults::NymNetworkDetails;
|
||||
use nym_network_defaults::setup_env;
|
||||
use nym_validator_client::nyxd::CosmWasmClient;
|
||||
use nym_validator_client::nyxd::contract_traits::{DkgQueryClient, GroupSigningClient};
|
||||
use nym_validator_client::{Config, DirectSigningHttpRpcNyxdClient, QueryHttpRpcValidatorClient};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum QueryMsg {
|
||||
GetCounter {},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum ExecuteMsg {
|
||||
IncrementCounter {},
|
||||
DecrementCounter {},
|
||||
SetCounter { to: u32 },
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
/*
|
||||
theres map
|
||||
id1 => wasm code 1
|
||||
id2 => wasm code 2
|
||||
id3 => wasm code 3
|
||||
|
||||
//
|
||||
// n1foo => id3
|
||||
// n1bar => id2
|
||||
//
|
||||
|
||||
|
||||
*/
|
||||
|
||||
let contract_address = "n1vwttwvy8e5nqshc35rsn2u88ewfecjwdkmqdwpuqdsfmweans3xs2rjgjx";
|
||||
|
||||
let mnemonic = "cost truly december route shoulder ostrich upon test test deliver moment tent general clutch manual language antenna curious gate library remember cost kidney proud";
|
||||
|
||||
let network = "/Users/jedrzej/workspace/nym/envs/canary.env";
|
||||
setup_env(Some(network));
|
||||
|
||||
let nym_network_details = NymNetworkDetails::new_from_env();
|
||||
|
||||
let signing_client = DirectSigningHttpRpcNyxdClient::connect_with_mnemonic(
|
||||
nym_validator_client::nyxd::Config::try_from_nym_network_details(&nym_network_details)?,
|
||||
"https://rpc.canary-validator.performance.nymte.ch",
|
||||
mnemonic.parse()?,
|
||||
)?;
|
||||
|
||||
let result = signing_client
|
||||
.execute(
|
||||
&contract_address.parse().unwrap(),
|
||||
&ExecuteMsg::SetCounter { to: 200 },
|
||||
None,
|
||||
"executing example contract",
|
||||
vec![],
|
||||
)
|
||||
.await?;
|
||||
println!("transaction got executed at tx {}", result.transaction_hash);
|
||||
println!("with events: {:?}", result.events);
|
||||
|
||||
// queries:
|
||||
let client = QueryHttpRpcValidatorClient::new_query(Config::try_from_nym_network_details(
|
||||
&nym_network_details,
|
||||
)?)?;
|
||||
|
||||
let response: u32 = client
|
||||
.nyxd
|
||||
.query_contract_smart(&contract_address.parse().unwrap(), &QueryMsg::GetCounter {})
|
||||
.await?;
|
||||
|
||||
println!("current counter is at {response}");
|
||||
println!("Hello, world!");
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user