1pub use cli::CliClient;
2pub use cosmrs::abci::GasInfo;
3use cosmrs::tendermint::chain::Id;
4pub use grpc::GrpcClient;
5use hex::ToHex;
6use serde::de::DeserializeOwned;
7
8pub mod cli;
9
10pub mod grpc;
11
12#[async_trait::async_trait]
13pub trait CwClient {
14 type Address: AsRef<str>;
15 type Query: ToString;
16 type RawQuery: ToHex;
17 type ChainId: AsRef<str>;
18 type Error;
19
20 async fn query_smart<R: DeserializeOwned + Send>(
21 &self,
22 contract: &Self::Address,
23 query: Self::Query,
24 ) -> Result<R, Self::Error>;
25
26 async fn query_raw<R: DeserializeOwned + Default>(
27 &self,
28 contract: &Self::Address,
29 query: Self::RawQuery,
30 ) -> Result<R, Self::Error>;
31
32 fn query_tx<R: DeserializeOwned + Default>(&self, txhash: &str) -> Result<R, Self::Error>;
33
34 async fn tx_execute<M: ToString + Send + Sync>(
35 &self,
36 contract: &Self::Address,
37 chain_id: &Id,
38 gas: u64,
39 sender: &str,
40 msgs: impl Iterator<Item = M> + Send + Sync,
41 pay_amount: &str,
42 ) -> Result<String, Self::Error>;
43
44 async fn tx_simulate<M: ToString + Send + Sync>(
45 &self,
46 contract: &Self::Address,
47 chain_id: &Id,
48 gas: u64,
49 sender: &str,
50 msgs: impl Iterator<Item = M> + Send + Sync,
51 pay_amount: &str,
52 ) -> Result<GasInfo, Self::Error>;
53
54 fn deploy<M: ToString>(
55 &self,
56 chain_id: &Id,
57 sender: &str, wasm_path: M,
59 ) -> Result<String, Self::Error>;
60
61 fn init<M: ToString>(
62 &self,
63 chain_id: &Id,
64 sender: &str,
65 admin: Option<&str>,
66 code_id: u64,
67 init_msg: M,
68 label: &str,
69 ) -> Result<String, Self::Error>;
70
71 fn trusted_height_hash(&self) -> Result<(u64, String), Self::Error>;
72}