cw_client/
lib.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
pub use cli::CliClient;
use cosmrs::tendermint::chain::Id;
pub use grpc::GrpcClient;
use hex::ToHex;
use serde::de::DeserializeOwned;

pub mod cli;

pub mod grpc;

#[async_trait::async_trait]
pub trait CwClient {
    type Address: AsRef<str>;
    type Query: ToString;
    type RawQuery: ToHex;
    type ChainId: AsRef<str>;
    type Error;

    async fn query_smart<R: DeserializeOwned + Send>(
        &self,
        contract: &Self::Address,
        query: Self::Query,
    ) -> Result<R, Self::Error>;

    fn query_raw<R: DeserializeOwned + Default>(
        &self,
        contract: &Self::Address,
        query: Self::RawQuery,
    ) -> Result<R, Self::Error>;

    fn query_tx<R: DeserializeOwned + Default>(&self, txhash: &str) -> Result<R, Self::Error>;

    async fn tx_execute<M: ToString + Send>(
        &self,
        contract: &Self::Address,
        chain_id: &Id,
        gas: u64,
        sender: &str,
        msg: M,
        fees: &str,
    ) -> Result<String, Self::Error>;

    fn deploy<M: ToString>(
        &self,
        chain_id: &Id,
        sender: &str, // what should this type be
        wasm_path: M,
    ) -> Result<String, Self::Error>;

    fn init<M: ToString>(
        &self,
        chain_id: &Id,
        sender: &str,
        code_id: u64,
        init_msg: M,
        label: &str,
    ) -> Result<String, Self::Error>;

    fn trusted_height_hash(&self) -> Result<(u64, String), Self::Error>;
}