layer_climb_core/
prelude.rs1pub(crate) use crate::network::apply_grpc_height;
4pub(crate) use anyhow::{anyhow, bail, Context, Result};
5use cosmwasm_std::Uint256;
6pub(crate) use layer_climb_address::Address;
7pub(crate) use layer_climb_config::*;
8pub(crate) use layer_climb_proto::{proto_into_any, proto_into_bytes, Message};
9
10pub use crate::{
12 cache::ClimbCache,
13 contract_helpers::contract_str_to_msg,
14 events::CosmosTxEvents,
15 querier::{Connection, ConnectionMode, QueryClient, QueryRequest},
16 signing::SigningClient,
17 transaction::TxBuilder,
18};
19
20#[cfg(not(target_arch = "wasm32"))]
21pub use crate::pool::*;
22
23pub fn new_coin(amount: impl ToString, denom: impl ToString) -> layer_climb_proto::Coin {
29 layer_climb_proto::Coin {
30 denom: denom.to_string(),
31 amount: amount.to_string(),
32 }
33}
34
35pub fn new_coins(
47 coins: impl IntoIterator<Item = (impl ToString, impl ToString)>,
48) -> Vec<layer_climb_proto::Coin> {
49 coins
50 .into_iter()
51 .map(|(amount, denom)| new_coin(amount, denom))
52 .collect()
53}
54
55pub trait ProtoCoinExt {
56 fn try_to_cosmwasm_coin(&self) -> Result<cosmwasm_std::Coin>;
57}
58
59impl ProtoCoinExt for layer_climb_proto::Coin {
60 fn try_to_cosmwasm_coin(&self) -> Result<cosmwasm_std::Coin> {
61 Ok(cosmwasm_std::Coin {
62 denom: self.denom.clone(),
63 amount: self
64 .amount
65 .parse::<Uint256>()
66 .map_err(|e| anyhow!("{e:?}"))?,
67 })
68 }
69}
70
71pub trait CosmwasmCoinExt {
72 fn to_proto_coin(&self) -> layer_climb_proto::Coin;
73}
74
75impl CosmwasmCoinExt for cosmwasm_std::Coin {
76 fn to_proto_coin(&self) -> layer_climb_proto::Coin {
77 layer_climb_proto::Coin {
78 denom: self.denom.clone(),
79 amount: self.amount.to_string(),
80 }
81 }
82}
83
84pub enum AnyClient {
87 Signing(SigningClient),
88 Query(QueryClient),
89}
90
91impl AnyClient {
92 pub fn as_signing(&self) -> &SigningClient {
95 match self {
96 Self::Signing(client) => client,
97 Self::Query(_) => panic!("Expected SigningClient, got QueryClient"),
98 }
99 }
100
101 pub fn as_querier(&self) -> &QueryClient {
103 match self {
104 Self::Query(client) => client,
105 Self::Signing(client) => &client.querier,
106 }
107 }
108}
109
110impl From<SigningClient> for AnyClient {
111 fn from(client: SigningClient) -> Self {
112 Self::Signing(client)
113 }
114}
115
116impl From<QueryClient> for AnyClient {
117 fn from(client: QueryClient) -> Self {
118 Self::Query(client)
119 }
120}
121
122impl TryFrom<AnyClient> for SigningClient {
123 type Error = anyhow::Error;
124
125 fn try_from(value: AnyClient) -> Result<Self> {
126 match value {
127 AnyClient::Signing(client) => Ok(client),
128 AnyClient::Query(_) => Err(anyhow!("Expected SigningClient, got QueryClient")),
129 }
130 }
131}
132
133impl From<AnyClient> for QueryClient {
134 fn from(client: AnyClient) -> Self {
135 match client {
136 AnyClient::Query(client) => client,
137 AnyClient::Signing(client) => client.querier,
138 }
139 }
140}