Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cw-orch-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ rpc = ["cosmrs/rpc"]
grpc = ["cosmrs/grpc", "dep:tonic"]



[dependencies]
# Default deps
cw-orch-contract-derive = { workspace = true }
Expand All @@ -46,7 +45,7 @@ thiserror = { workspace = true }
# Daemon deps
sha256 = { workspace = true }
ibc-relayer-types = { workspace = true }
prost = { version = "0.11" }
prost = { version = "0.12" }
bitcoin = { version = "0.30.0" }
hex = { version = "0.4.3" }
ripemd = { version = "0.1.3" }
Expand All @@ -60,7 +59,7 @@ hkd32 = { version = "0.7.0", features = ["bip39", "mnemonic", "bech32"] }
rand_core = { version = "0.6.4", default-features = false }
ed25519-dalek = { version = "2", features = ["serde"] }
eyre = { version = "0.6" }
cosmrs = { version = "0.14.0", features = ["dev", "cosmwasm"] }
cosmrs = { version = "0.15.0", features = ["dev", "cosmwasm"] }
chrono = { version = "0.4" }
base16 = { version = "0.2.1" }
derive_builder = { version = "0.12.0" }
Expand Down
11 changes: 6 additions & 5 deletions cw-orch-daemon/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::DaemonState;
use super::{
builder::DaemonAsyncBuilder,
error::DaemonError,
queriers::{DaemonQuerier, Node, CosmWasm},
queriers::{CosmWasm, DaemonQuerier, Node},
sender::Wallet,
tx_resp::CosmTxResponse,
};
Expand All @@ -27,7 +27,6 @@ use std::{
time::Duration,
};


#[derive(Clone)]
/**
Represents a blockchain node.
Expand Down Expand Up @@ -73,11 +72,11 @@ impl DaemonAsync {
}

/// Get the channel configured for this DaemonAsync.
#[cfg(feature="grpc")]
#[cfg(feature = "grpc")]
pub fn channel(&self) -> tonic::transport::Channel {
self.state.transport_channel.clone()
}
#[cfg(feature="rpc")]
#[cfg(feature = "rpc")]
pub fn channel(&self) -> cosmrs::rpc::HttpClient {
self.state.transport_channel.clone()
}
Expand Down Expand Up @@ -148,7 +147,9 @@ impl DaemonAsync {
) -> Result<R, DaemonError> {
let querier = CosmWasm::new(self.channel());

let resp: Vec<u8> = querier.contract_state(contract_address, serde_json::to_vec(&query_msg)?).await?;
let resp: Vec<u8> = querier
.contract_state(contract_address, serde_json::to_vec(&query_msg)?)
.await?;

Ok(from_str(from_utf8(&resp).unwrap())?)
}
Expand Down
8 changes: 5 additions & 3 deletions cw-orch-daemon/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ pub enum DaemonError {
VarError(#[from] ::std::env::VarError),
#[error(transparent)]
AnyError(#[from] ::anyhow::Error),
#[cfg(feature="grpc")]

#[cfg(feature = "grpc")]
#[error(transparent)]
Status(#[from] ::tonic::Status),

#[cfg(feature="grpc")]
#[cfg(feature = "grpc")]
#[error(transparent)]
TransportError(#[from] ::tonic::transport::Error),

Expand Down Expand Up @@ -104,6 +104,8 @@ pub enum DaemonError {
NewNetwork(String),
#[error("Can not connect to any grpc endpoint that was provided.")]
CannotConnectGRPC,
#[error("Can not connect to any rpc endpoint that was provided.")]
CannotConnectRPC,
#[error("tx failed: {reason} with code {code}")]
TxFailed { code: usize, reason: String },
#[error("The list of grpc endpoints is empty")]
Expand Down
16 changes: 6 additions & 10 deletions cw-orch-daemon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

//! `Daemon` and `DaemonAsync` execution environments.
//!
//! The `Daemon` type is a synchronous wrapper around the `DaemonAsync` type and can be used as a contract execution environment.
//!
//!
#[cfg(all(feature = "rpc", feature = "grpc"))]
compile_error!("feature \"rpc\" and feature \"grpc\" cannot be enabled at the same time");

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

pub mod queriers;

#[cfg(feature="rpc")]
#[cfg(feature = "rpc")]
pub mod rpc_channel;
#[cfg(feature="rpc")]
#[cfg(feature = "rpc")]
pub use self::rpc_channel::*;

#[cfg(feature="grpc")]
#[cfg(feature = "grpc")]
pub mod grpc_channel;
#[cfg(feature="grpc")]
#[cfg(feature = "grpc")]
pub use self::grpc_channel::*;


mod traits;
pub mod tx_builder;

pub use self::{
builder::*, core::*, error::*, state::*, sync::*, traits::*, tx_resp::*,
};
pub use self::{builder::*, core::*, error::*, state::*, sync::*, traits::*, tx_resp::*};
pub use cw_orch_networks::chain_info::*;
pub use cw_orch_networks::networks;
pub use sender::Wallet;
Expand Down
10 changes: 4 additions & 6 deletions cw-orch-daemon/src/live_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! It can be used to do chain-backed unit-testing. It can't be used for state-changing operations.

use crate::create_transport_channel;
use crate::queriers::{DaemonQuerier, Staking, Bank, CosmWasm};
use crate::queriers::{Bank, CosmWasm, DaemonQuerier, Staking};
use cosmwasm_std::Addr;
use cosmwasm_std::AllBalanceResponse;
use cosmwasm_std::BalanceResponse;
Expand Down Expand Up @@ -52,9 +52,9 @@ pub fn mock_dependencies(

/// Querier struct that fetches queries on-chain directly
pub struct WasmMockQuerier {
#[cfg(feature="grpc")]
#[cfg(feature = "grpc")]
channel: tonic::transport::Channel,
#[cfg(feature="rpc")]
#[cfg(feature = "rpc")]
channel: cosmrs::rpc::HttpClient,
runtime: Runtime,
}
Expand Down Expand Up @@ -205,9 +205,7 @@ impl WasmMockQuerier {
pub fn new(chain: ChainData) -> Self {
let rt = Runtime::new().unwrap();

let channel = rt
.block_on(create_transport_channel(&chain))
.unwrap();
let channel = rt.block_on(create_transport_channel(&chain)).unwrap();

WasmMockQuerier {
channel,
Expand Down
10 changes: 7 additions & 3 deletions cw-orch-daemon/src/proto/injective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

use crate::DaemonError;
use cosmrs::tx::SignDoc;
use cosmrs::{proto::traits::TypeUrl, tx::Raw};
use cosmrs::{
proto::traits::{Message, Name},
tx::Raw,
};

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

impl TypeUrl for InjectivePubKey {
const TYPE_URL: &'static str = "/injective.crypto.v1beta1.ethsecp256k1.PubKey";
impl Name for InjectivePubKey {
const NAME: &'static str = "PubKey";
const PACKAGE: &'static str = "/injective.crypto.v1beta1.ethsecp256k1";
}

pub trait InjectiveSigner {
Expand Down
18 changes: 7 additions & 11 deletions cw-orch-daemon/src/queriers.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@


pub const MAX_TX_QUERY_RETRIES: usize = 50;

#[cfg(feature="rpc")]
#[cfg(feature = "rpc")]
pub mod rpc;
#[cfg(feature="rpc")]
#[cfg(feature = "rpc")]
pub use rpc::*;
#[cfg(feature="grpc")]
#[cfg(feature = "grpc")]
pub mod grpc;
#[cfg(feature="grpc")]
#[cfg(feature = "grpc")]
pub use grpc::*;



/// Constructor for a querier over a given channel
pub trait DaemonQuerier {
/// Construct an new querier over a given channel
#[cfg(feature="rpc")]
#[cfg(feature = "rpc")]
fn new(client: cosmrs::rpc::HttpClient) -> Self;
#[cfg(feature="grpc")]
#[cfg(feature = "grpc")]
fn new(channel: tonic::transport::Channel) -> Self;
}
}
17 changes: 7 additions & 10 deletions cw-orch-daemon/src/queriers/grpc/auth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Only a simple implementation to not overload the tx builder
use tonic::transport::Channel;

use crate::{queriers::DaemonQuerier, cosmos_query, DaemonError};
use crate::{cosmos_query, queriers::DaemonQuerier, DaemonError};

/// Queries for Cosmos Bank Module
pub struct Auth {
Expand All @@ -14,20 +14,17 @@ impl DaemonQuerier for Auth {
}
}


impl Auth{

impl Auth {
/// Query spendable balance for address
pub async fn account(
&self,
address: impl Into<String>,
) -> Result<Vec<u8>, DaemonError> {
pub async fn account(&self, address: impl Into<String>) -> Result<Vec<u8>, DaemonError> {
let resp = cosmos_query!(
self,
auth,
account,
QueryAccountRequest { address: address.into() }
QueryAccountRequest {
address: address.into()
}
);
Ok(resp.account.unwrap().value)
}
}
}
5 changes: 2 additions & 3 deletions cw-orch-daemon/src/queriers/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,24 @@ macro_rules! cosmos_query {
};
}

mod auth;
mod bank;
mod cosmwasm;
mod feegrant;
mod gov;
mod ibc;
mod node;
mod staking;
mod auth;
mod tx;

pub use auth::Auth;
pub use bank::Bank;
pub use cosmwasm::CosmWasm;
pub use feegrant::Feegrant;
pub use ibc::Ibc;
pub use node::Node;
pub use auth::Auth;
pub use tx::Tx;

// this two containt structs that are helpers for the queries
pub use gov::*;
pub use staking::*;

4 changes: 3 additions & 1 deletion cw-orch-daemon/src/queriers/grpc/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{cmp::min, time::Duration};

use crate::{cosmos_modules, error::DaemonError, tx_resp::CosmTxResponse, queriers::MAX_TX_QUERY_RETRIES};
use crate::{
cosmos_modules, error::DaemonError, queriers::MAX_TX_QUERY_RETRIES, tx_resp::CosmTxResponse,
};

use cosmrs::{
proto::cosmos::{base::query::v1beta1::PageRequest, tx::v1beta1::SimulateResponse},
Expand Down
19 changes: 6 additions & 13 deletions cw-orch-daemon/src/queriers/grpc/tx.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Only a simple implementation to not overload the tx builder

use cosmrs::{tx::Raw, proto::cosmos::base::abci::v1beta1::TxResponse};
use cosmrs::{proto::cosmos::base::abci::v1beta1::TxResponse, tx::Raw};
use tonic::transport::Channel;

use crate::{queriers::DaemonQuerier, DaemonError, cosmos_modules};

use crate::{cosmos_modules, queriers::DaemonQuerier, DaemonError};

/// Queries for Cosmos Bank Module
pub struct Tx {
Expand All @@ -17,16 +16,11 @@ impl DaemonQuerier for Tx {
}
}

impl Tx{

impl Tx {
/// Query spendable balance for address
pub async fn broadcast(
&self,
tx: Raw,
) -> Result<TxResponse, DaemonError> {

pub async fn broadcast(&self, tx: Raw) -> Result<TxResponse, DaemonError> {
let mut client =
cosmos_modules::tx::service_client::ServiceClient::new(self.channel.clone());
cosmos_modules::tx::service_client::ServiceClient::new(self.channel.clone());

let resp = client
.broadcast_tx(cosmos_modules::tx::BroadcastTxRequest {
Expand All @@ -36,7 +30,6 @@ impl Tx{
.await?
.into_inner();


Ok(resp.tx_response.unwrap())
}
}
}
21 changes: 9 additions & 12 deletions cw-orch-daemon/src/queriers/rpc/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

use cosmrs::rpc::HttpClient;

use crate::{queriers::DaemonQuerier, cosmos_rpc_query, DaemonError};
use crate::{cosmos_rpc_query, queriers::DaemonQuerier, DaemonError};


/// Queries for Cosmos Bank Module
/// Queries for Cosmos Auth Module
pub struct Auth {
client: HttpClient,
}
Expand All @@ -16,20 +15,18 @@ impl DaemonQuerier for Auth {
}
}

impl Auth{

/// Query spendable balance for address
pub async fn account(
&self,
address: impl Into<String>,
) -> Result<Vec<u8>, DaemonError> {
impl Auth {
/// Query the account
pub async fn account(&self, address: impl Into<String>) -> Result<Vec<u8>, DaemonError> {
let resp = cosmos_rpc_query!(
self,
auth,
"/cosmos.auth.v1beta1.Query/Account",
QueryAccountRequest { address: address.into() },
QueryAccountRequest {
address: address.into()
},
QueryAccountResponse,
);
Ok(resp.account.unwrap().value)
}
}
}
Loading