This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
terra_query.rs
61 lines (52 loc) · 1.93 KB
/
terra_query.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use dotenv::dotenv;
use clap::Arg;
use terra_rust_cli::cli_helpers;
/// VERSION number of package
pub const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
/// NAME of package
pub const NAME: Option<&'static str> = option_env!("CARGO_PKG_NAME");
async fn run() -> anyhow::Result<()> {
let cli = cli_helpers::gen_cli_read_only("terra query", "terra-query")
.arg(
Arg::new("contract")
.long("contract")
.value_name("contract")
.takes_value(true)
.env("TERRARUST_CONTRACT")
.help("the contract address"),
)
.arg(Arg::new("json").takes_value(true).value_name("json"))
.get_matches();
let terra = cli_helpers::lcd_no_tx_from_args(&cli)?;
let contract = cli_helpers::get_arg_value(&cli, "contract")?;
let json_str = cli_helpers::get_arg_value(&cli, "json")?;
let secp = secp256k1::Secp256k1::new();
let wallet = cli_helpers::wallet_opt_from_args(&cli);
let seed = cli_helpers::seed_from_args(&cli);
let json: serde_json::Value =
cli_helpers::get_json_block_expanded(json_str, None, &secp, wallet, seed, None, false)?;
// let json: serde_json::Value = serde_json::from_str(json_str)?;
let qry = terra
.wasm()
.query::<serde_json::Value>(contract, &json.to_string())
.await?;
println!("{}", qry);
Ok(())
}
#[tokio::main]
async fn main() {
dotenv().ok();
env_logger::init();
if let Err(ref err) = run().await {
log::error!("{}", err);
err.chain()
.skip(1)
.for_each(|cause| log::error!("because: {}", cause));
// The backtrace is not always generated. Try to run this example
// with `$env:RUST_BACKTRACE=1`.
// if let Some(backtrace) = e.backtrace() {
// log::debug!("backtrace: {:?}", backtrace);
// }
::std::process::exit(1);
}
}