Skip to content

Commit eac1378

Browse files
authored
Update RPC Tendermint to 38 (#273)
* Add local wasm network * Update support of tendermint rpc to 0.38 * Remove unused tendermint-rpc dep * Minor bug fixes * Return proper rpc error * Update wasmd network names * Format
1 parent a320473 commit eac1378

File tree

28 files changed

+296
-215
lines changed

28 files changed

+296
-215
lines changed

cw-orch-daemon/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ rpc = ["cosmrs/rpc"]
2626
grpc = ["cosmrs/grpc", "dep:tonic"]
2727

2828

29-
3029
[dependencies]
3130
# Default deps
3231
cw-orch-contract-derive = { workspace = true }
@@ -46,7 +45,7 @@ thiserror = { workspace = true }
4645
# Daemon deps
4746
sha256 = { workspace = true }
4847
ibc-relayer-types = { workspace = true }
49-
prost = { version = "0.11" }
48+
prost = { version = "0.12" }
5049
bitcoin = { version = "0.30.0" }
5150
hex = { version = "0.4.3" }
5251
ripemd = { version = "0.1.3" }
@@ -60,7 +59,7 @@ hkd32 = { version = "0.7.0", features = ["bip39", "mnemonic", "bech32"] }
6059
rand_core = { version = "0.6.4", default-features = false }
6160
ed25519-dalek = { version = "2", features = ["serde"] }
6261
eyre = { version = "0.6" }
63-
cosmrs = { version = "0.14.0", features = ["dev", "cosmwasm"] }
62+
cosmrs = { version = "0.15.0", features = ["dev", "cosmwasm"] }
6463
chrono = { version = "0.4" }
6564
base16 = { version = "0.2.1" }
6665
derive_builder = { version = "0.12.0" }

cw-orch-daemon/src/core.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::DaemonState;
33
use super::{
44
builder::DaemonAsyncBuilder,
55
error::DaemonError,
6-
queriers::{DaemonQuerier, Node, CosmWasm},
6+
queriers::{CosmWasm, DaemonQuerier, Node},
77
sender::Wallet,
88
tx_resp::CosmTxResponse,
99
};
@@ -27,7 +27,6 @@ use std::{
2727
time::Duration,
2828
};
2929

30-
3130
#[derive(Clone)]
3231
/**
3332
Represents a blockchain node.
@@ -73,11 +72,11 @@ impl DaemonAsync {
7372
}
7473

7574
/// Get the channel configured for this DaemonAsync.
76-
#[cfg(feature="grpc")]
75+
#[cfg(feature = "grpc")]
7776
pub fn channel(&self) -> tonic::transport::Channel {
7877
self.state.transport_channel.clone()
7978
}
80-
#[cfg(feature="rpc")]
79+
#[cfg(feature = "rpc")]
8180
pub fn channel(&self) -> cosmrs::rpc::HttpClient {
8281
self.state.transport_channel.clone()
8382
}
@@ -148,7 +147,9 @@ impl DaemonAsync {
148147
) -> Result<R, DaemonError> {
149148
let querier = CosmWasm::new(self.channel());
150149

151-
let resp: Vec<u8> = querier.contract_state(contract_address, serde_json::to_vec(&query_msg)?).await?;
150+
let resp: Vec<u8> = querier
151+
.contract_state(contract_address, serde_json::to_vec(&query_msg)?)
152+
.await?;
152153

153154
Ok(from_str(from_utf8(&resp).unwrap())?)
154155
}

cw-orch-daemon/src/error.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ pub enum DaemonError {
1919
VarError(#[from] ::std::env::VarError),
2020
#[error(transparent)]
2121
AnyError(#[from] ::anyhow::Error),
22-
23-
#[cfg(feature="grpc")]
22+
23+
#[cfg(feature = "grpc")]
2424
#[error(transparent)]
2525
Status(#[from] ::tonic::Status),
2626

27-
#[cfg(feature="grpc")]
27+
#[cfg(feature = "grpc")]
2828
#[error(transparent)]
2929
TransportError(#[from] ::tonic::transport::Error),
3030

@@ -104,6 +104,8 @@ pub enum DaemonError {
104104
NewNetwork(String),
105105
#[error("Can not connect to any grpc endpoint that was provided.")]
106106
CannotConnectGRPC,
107+
#[error("Can not connect to any rpc endpoint that was provided.")]
108+
CannotConnectRPC,
107109
#[error("tx failed: {reason} with code {code}")]
108110
TxFailed { code: usize, reason: String },
109111
#[error("The list of grpc endpoints is empty")]

cw-orch-daemon/src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
21
//! `Daemon` and `DaemonAsync` execution environments.
32
//!
43
//! The `Daemon` type is a synchronous wrapper around the `DaemonAsync` type and can be used as a contract execution environment.
5-
//!
4+
//!
65
#[cfg(all(feature = "rpc", feature = "grpc"))]
76
compile_error!("feature \"rpc\" and feature \"grpc\" cannot be enabled at the same time");
87

@@ -25,23 +24,20 @@ pub mod live_mock;
2524

2625
pub mod queriers;
2726

28-
#[cfg(feature="rpc")]
27+
#[cfg(feature = "rpc")]
2928
pub mod rpc_channel;
30-
#[cfg(feature="rpc")]
29+
#[cfg(feature = "rpc")]
3130
pub use self::rpc_channel::*;
3231

33-
#[cfg(feature="grpc")]
32+
#[cfg(feature = "grpc")]
3433
pub mod grpc_channel;
35-
#[cfg(feature="grpc")]
34+
#[cfg(feature = "grpc")]
3635
pub use self::grpc_channel::*;
3736

38-
3937
mod traits;
4038
pub mod tx_builder;
4139

42-
pub use self::{
43-
builder::*, core::*, error::*, state::*, sync::*, traits::*, tx_resp::*,
44-
};
40+
pub use self::{builder::*, core::*, error::*, state::*, sync::*, traits::*, tx_resp::*};
4541
pub use cw_orch_networks::chain_info::*;
4642
pub use cw_orch_networks::networks;
4743
pub use sender::Wallet;

cw-orch-daemon/src/live_mock.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! It can be used to do chain-backed unit-testing. It can't be used for state-changing operations.
33
44
use crate::create_transport_channel;
5-
use crate::queriers::{DaemonQuerier, Staking, Bank, CosmWasm};
5+
use crate::queriers::{Bank, CosmWasm, DaemonQuerier, Staking};
66
use cosmwasm_std::Addr;
77
use cosmwasm_std::AllBalanceResponse;
88
use cosmwasm_std::BalanceResponse;
@@ -52,9 +52,9 @@ pub fn mock_dependencies(
5252

5353
/// Querier struct that fetches queries on-chain directly
5454
pub struct WasmMockQuerier {
55-
#[cfg(feature="grpc")]
55+
#[cfg(feature = "grpc")]
5656
channel: tonic::transport::Channel,
57-
#[cfg(feature="rpc")]
57+
#[cfg(feature = "rpc")]
5858
channel: cosmrs::rpc::HttpClient,
5959
runtime: Runtime,
6060
}
@@ -205,9 +205,7 @@ impl WasmMockQuerier {
205205
pub fn new(chain: ChainData) -> Self {
206206
let rt = Runtime::new().unwrap();
207207

208-
let channel = rt
209-
.block_on(create_transport_channel(&chain))
210-
.unwrap();
208+
let channel = rt.block_on(create_transport_channel(&chain)).unwrap();
211209

212210
WasmMockQuerier {
213211
channel,

cw-orch-daemon/src/proto/injective.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
use crate::DaemonError;
44
use cosmrs::tx::SignDoc;
5-
use cosmrs::{proto::traits::TypeUrl, tx::Raw};
5+
use cosmrs::{
6+
proto::traits::{Message, Name},
7+
tx::Raw,
8+
};
69

710
#[cfg(feature = "eth")]
811
use crate::keys::private::PrivateKey;
@@ -26,8 +29,9 @@ pub struct InjectivePubKey {
2629
pub key: Vec<u8>,
2730
}
2831

29-
impl TypeUrl for InjectivePubKey {
30-
const TYPE_URL: &'static str = "/injective.crypto.v1beta1.ethsecp256k1.PubKey";
32+
impl Name for InjectivePubKey {
33+
const NAME: &'static str = "PubKey";
34+
const PACKAGE: &'static str = "/injective.crypto.v1beta1.ethsecp256k1";
3135
}
3236

3337
pub trait InjectiveSigner {

cw-orch-daemon/src/queriers.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
2-
31
pub const MAX_TX_QUERY_RETRIES: usize = 50;
42

5-
#[cfg(feature="rpc")]
3+
#[cfg(feature = "rpc")]
64
pub mod rpc;
7-
#[cfg(feature="rpc")]
5+
#[cfg(feature = "rpc")]
86
pub use rpc::*;
9-
#[cfg(feature="grpc")]
7+
#[cfg(feature = "grpc")]
108
pub mod grpc;
11-
#[cfg(feature="grpc")]
9+
#[cfg(feature = "grpc")]
1210
pub use grpc::*;
1311

14-
15-
1612
/// Constructor for a querier over a given channel
1713
pub trait DaemonQuerier {
1814
/// Construct an new querier over a given channel
19-
#[cfg(feature="rpc")]
15+
#[cfg(feature = "rpc")]
2016
fn new(client: cosmrs::rpc::HttpClient) -> Self;
21-
#[cfg(feature="grpc")]
17+
#[cfg(feature = "grpc")]
2218
fn new(channel: tonic::transport::Channel) -> Self;
23-
}
19+
}
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Only a simple implementation to not overload the tx builder
22
use tonic::transport::Channel;
33

4-
use crate::{queriers::DaemonQuerier, cosmos_query, DaemonError};
4+
use crate::{cosmos_query, queriers::DaemonQuerier, DaemonError};
55

66
/// Queries for Cosmos Bank Module
77
pub struct Auth {
@@ -14,20 +14,17 @@ impl DaemonQuerier for Auth {
1414
}
1515
}
1616

17-
18-
impl Auth{
19-
17+
impl Auth {
2018
/// Query spendable balance for address
21-
pub async fn account(
22-
&self,
23-
address: impl Into<String>,
24-
) -> Result<Vec<u8>, DaemonError> {
19+
pub async fn account(&self, address: impl Into<String>) -> Result<Vec<u8>, DaemonError> {
2520
let resp = cosmos_query!(
2621
self,
2722
auth,
2823
account,
29-
QueryAccountRequest { address: address.into() }
24+
QueryAccountRequest {
25+
address: address.into()
26+
}
3027
);
3128
Ok(resp.account.unwrap().value)
3229
}
33-
}
30+
}

cw-orch-daemon/src/queriers/grpc/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,24 @@ macro_rules! cosmos_query {
4444
};
4545
}
4646

47+
mod auth;
4748
mod bank;
4849
mod cosmwasm;
4950
mod feegrant;
5051
mod gov;
5152
mod ibc;
5253
mod node;
5354
mod staking;
54-
mod auth;
5555
mod tx;
5656

57+
pub use auth::Auth;
5758
pub use bank::Bank;
5859
pub use cosmwasm::CosmWasm;
5960
pub use feegrant::Feegrant;
6061
pub use ibc::Ibc;
6162
pub use node::Node;
62-
pub use auth::Auth;
6363
pub use tx::Tx;
6464

6565
// this two containt structs that are helpers for the queries
6666
pub use gov::*;
6767
pub use staking::*;
68-

cw-orch-daemon/src/queriers/grpc/node.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::{cmp::min, time::Duration};
22

3-
use crate::{cosmos_modules, error::DaemonError, tx_resp::CosmTxResponse, queriers::MAX_TX_QUERY_RETRIES};
3+
use crate::{
4+
cosmos_modules, error::DaemonError, queriers::MAX_TX_QUERY_RETRIES, tx_resp::CosmTxResponse,
5+
};
46

57
use cosmrs::{
68
proto::cosmos::{base::query::v1beta1::PageRequest, tx::v1beta1::SimulateResponse},

0 commit comments

Comments
 (0)