From fc3c9f2f1100c3e08730ff13f0b239f02f6909f2 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 11 Sep 2024 12:54:23 +0000 Subject: [PATCH 1/9] Added upload wasm function to sender --- cw-orch-daemon/src/senders/cosmos.rs | 30 ++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/cw-orch-daemon/src/senders/cosmos.rs b/cw-orch-daemon/src/senders/cosmos.rs index e9d371cc4..1e3646b4e 100644 --- a/cw-orch-daemon/src/senders/cosmos.rs +++ b/cw-orch-daemon/src/senders/cosmos.rs @@ -32,13 +32,15 @@ use cosmrs::{ }; use cosmwasm_std::{coin, Addr, Coin}; use cw_orch_core::{ - environment::{ChainInfoOwned, ChainKind}, + contract::WasmPath, + environment::{ChainInfoOwned, ChainKind, IndexResponse}, CoreEnvVars, CwEnvError, }; +use flate2::{write, Compression}; use crate::env::{LOCAL_MNEMONIC_ENV_NAME, MAIN_MNEMONIC_ENV_NAME, TEST_MNEMONIC_ENV_NAME}; use bitcoin::secp256k1::{All, Secp256k1, Signing}; -use std::{str::FromStr, sync::Arc}; +use std::{io::Write, str::FromStr, sync::Arc}; use cosmos_modules::vesting::PeriodicVestingAccount; use tonic::transport::Channel; @@ -415,6 +417,30 @@ impl Wallet { } } +// Helpers to facilitate some rare operations +impl Wallet { + /// Uploads the `WasmPath` path specifier on chain and returns the resulting code_id + pub async fn upload_wasm( + &self, + wasm_path: WasmPath, + ) -> Result<(u64, CosmTxResponse), DaemonError> { + let file_contents = std::fs::read(wasm_path.path())?; + let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); + e.write_all(&file_contents)?; + let wasm_byte_code = e.finish()?; + let store_msg = cosmrs::cosmwasm::MsgStoreCode { + sender: self.account_id(), + wasm_byte_code, + instantiate_permission: None, + }; + + let result = self.commit_tx(vec![store_msg], None).await?; + let code_id = result.uploaded_code_id().unwrap(); + + Ok((code_id, result)) + } +} + impl QuerySender for Wallet { type Error = DaemonError; type Options = CosmosOptions; From 9085e1ff29b1a1c3e30005c3c6c60ea066c4c67a Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 11 Sep 2024 12:57:09 +0000 Subject: [PATCH 2/9] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 267d88259..e550f444f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add methods to set the private key and mnemonic of an existing sender - Deprecate `authz_granter` and `fee_granter` on `Daemon` struct + - Adds an `upload_wasm` function to CosmosSender to upload wasm code associated to no Contract structure ### Breaking From 245cd882eaf1c92e1fa520fa26bc5994d5a1525c Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 11 Sep 2024 13:00:31 +0000 Subject: [PATCH 3/9] Nits and better api --- cw-orch-daemon/src/senders/cosmos.rs | 15 +++++---------- cw-orch-daemon/src/senders/query_only.rs | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/cw-orch-daemon/src/senders/cosmos.rs b/cw-orch-daemon/src/senders/cosmos.rs index 1e3646b4e..9f1cb5c09 100644 --- a/cw-orch-daemon/src/senders/cosmos.rs +++ b/cw-orch-daemon/src/senders/cosmos.rs @@ -33,7 +33,7 @@ use cosmrs::{ use cosmwasm_std::{coin, Addr, Coin}; use cw_orch_core::{ contract::WasmPath, - environment::{ChainInfoOwned, ChainKind, IndexResponse}, + environment::{ChainInfoOwned, ChainKind}, CoreEnvVars, CwEnvError, }; use flate2::{write, Compression}; @@ -419,11 +419,9 @@ impl Wallet { // Helpers to facilitate some rare operations impl Wallet { - /// Uploads the `WasmPath` path specifier on chain and returns the resulting code_id - pub async fn upload_wasm( - &self, - wasm_path: WasmPath, - ) -> Result<(u64, CosmTxResponse), DaemonError> { + /// Uploads the `WasmPath` path specifier on chain. + /// The resulting code_id can be extracted from the Transaction result using [cw_orch_core::environment::IndexResponse::uploaded_code_id] and returns the resulting code_id + pub async fn upload_wasm(&self, wasm_path: WasmPath) -> Result { let file_contents = std::fs::read(wasm_path.path())?; let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); e.write_all(&file_contents)?; @@ -434,10 +432,7 @@ impl Wallet { instantiate_permission: None, }; - let result = self.commit_tx(vec![store_msg], None).await?; - let code_id = result.uploaded_code_id().unwrap(); - - Ok((code_id, result)) + self.commit_tx(vec![store_msg], None).await } } diff --git a/cw-orch-daemon/src/senders/query_only.rs b/cw-orch-daemon/src/senders/query_only.rs index c2437547b..7238e1e1e 100644 --- a/cw-orch-daemon/src/senders/query_only.rs +++ b/cw-orch-daemon/src/senders/query_only.rs @@ -46,7 +46,7 @@ impl QuerySender for QueryOnlySender { #[cfg(test)] mod tests { - use cw_orch_networks::networks::{ARCHWAY_1, JUNO_1, VOTA_ASH}; + use cw_orch_networks::networks::{ARCHWAY_1, JUNO_1}; use super::QueryOnlyDaemon; use crate::DaemonBuilder; From 6b0742ce0aa5860dda9cb8a40a7e47f466cdceb6 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 11 Sep 2024 14:10:21 +0000 Subject: [PATCH 4/9] Remove clone dedupe --- cw-orch-daemon/src/core.rs | 24 ++++----------------- cw-orch-daemon/src/senders/cosmos.rs | 23 +-------------------- cw-orch-daemon/src/senders/tx.rs | 31 ++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 44 deletions(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index 8e1b882bc..f3cf1fabe 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -20,13 +20,11 @@ use cw_orch_core::{ environment::{AsyncWasmQuerier, ChainInfoOwned, ChainState, IndexResponse, Querier}, log::transaction_target, }; -use flate2::{write, Compression}; use prost::Message; use serde::{de::DeserializeOwned, Serialize}; use serde_json::from_str; use std::{ fmt::Debug, - io::Write, ops::Deref, str::{from_utf8, FromStr}, time::Duration, @@ -349,32 +347,18 @@ impl DaemonAsyncBase { log::debug!(target: &transaction_target(), "Uploading file at {:?}", wasm_path); - let file_contents = std::fs::read(wasm_path.path())?; - let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); - e.write_all(&file_contents)?; - let wasm_byte_code = e.finish()?; - let store_msg = cosmrs::cosmwasm::MsgStoreCode { - sender: self.sender().account_id(), - wasm_byte_code, - instantiate_permission: None, - }; - - let result = self - .sender() - .commit_tx(vec![store_msg], None) - .await - .map_err(Into::into)?; + let upload_result = self.sender.upload_wasm(wasm_path).await?; - log::info!(target: &transaction_target(), "Uploading done: {:?}", result.txhash); + log::info!(target: &transaction_target(), "Uploading done: {:?}", upload_result.txhash); - let code_id = result.uploaded_code_id().unwrap(); + let code_id = upload_result.uploaded_code_id().unwrap(); // wait for the node to return the contract information for this upload let wasm = CosmWasm::new_async(self.channel()); while wasm._code(code_id).await.is_err() { self.next_block().await?; } - Ok(result) + Ok(upload_result) } } diff --git a/cw-orch-daemon/src/senders/cosmos.rs b/cw-orch-daemon/src/senders/cosmos.rs index 9f1cb5c09..e9d371cc4 100644 --- a/cw-orch-daemon/src/senders/cosmos.rs +++ b/cw-orch-daemon/src/senders/cosmos.rs @@ -32,15 +32,13 @@ use cosmrs::{ }; use cosmwasm_std::{coin, Addr, Coin}; use cw_orch_core::{ - contract::WasmPath, environment::{ChainInfoOwned, ChainKind}, CoreEnvVars, CwEnvError, }; -use flate2::{write, Compression}; use crate::env::{LOCAL_MNEMONIC_ENV_NAME, MAIN_MNEMONIC_ENV_NAME, TEST_MNEMONIC_ENV_NAME}; use bitcoin::secp256k1::{All, Secp256k1, Signing}; -use std::{io::Write, str::FromStr, sync::Arc}; +use std::{str::FromStr, sync::Arc}; use cosmos_modules::vesting::PeriodicVestingAccount; use tonic::transport::Channel; @@ -417,25 +415,6 @@ impl Wallet { } } -// Helpers to facilitate some rare operations -impl Wallet { - /// Uploads the `WasmPath` path specifier on chain. - /// The resulting code_id can be extracted from the Transaction result using [cw_orch_core::environment::IndexResponse::uploaded_code_id] and returns the resulting code_id - pub async fn upload_wasm(&self, wasm_path: WasmPath) -> Result { - let file_contents = std::fs::read(wasm_path.path())?; - let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); - e.write_all(&file_contents)?; - let wasm_byte_code = e.finish()?; - let store_msg = cosmrs::cosmwasm::MsgStoreCode { - sender: self.account_id(), - wasm_byte_code, - instantiate_permission: None, - }; - - self.commit_tx(vec![store_msg], None).await - } -} - impl QuerySender for Wallet { type Error = DaemonError; type Options = CosmosOptions; diff --git a/cw-orch-daemon/src/senders/tx.rs b/cw-orch-daemon/src/senders/tx.rs index 619d78ff9..2e8b48653 100644 --- a/cw-orch-daemon/src/senders/tx.rs +++ b/cw-orch-daemon/src/senders/tx.rs @@ -1,11 +1,15 @@ +use std::io::Write; + use cosmrs::{tx::Msg, AccountId, Any}; use cosmwasm_std::Addr; +use cw_orch_core::contract::WasmPath; +use flate2::{write, Compression}; -use crate::CosmTxResponse; +use crate::{CosmTxResponse, DaemonError}; use super::query::QuerySender; -pub trait TxSender: QuerySender { +pub trait TxSender: QuerySender + Sync { /// Returns the `AccountId` of the sender that commits the transaction. fn account_id(&self) -> AccountId; @@ -35,4 +39,27 @@ pub trait TxSender: QuerySender { self.commit_tx_any(msgs, memo) } + + /// Uploads the `WasmPath` path specifier on chain. + /// The resulting code_id can be extracted from the Transaction result using [cw_orch_core::environment::IndexResponse::uploaded_code_id] and returns the resulting code_id + fn upload_wasm( + &self, + wasm_path: WasmPath, + ) -> impl std::future::Future> + Send { + async move { + let file_contents = std::fs::read(wasm_path.path())?; + let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); + e.write_all(&file_contents)?; + let wasm_byte_code = e.finish()?; + let store_msg = cosmrs::cosmwasm::MsgStoreCode { + sender: self.account_id(), + wasm_byte_code, + instantiate_permission: None, + }; + + self.commit_tx(vec![store_msg], None) + .await + .map_err(Into::into) + } + } } From aa04ede91a1d52a434b88b94c703d5e09282f1f3 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Thu, 12 Sep 2024 07:42:22 +0000 Subject: [PATCH 5/9] Revert "Remove clone dedupe" This reverts commit 6b0742ce0aa5860dda9cb8a40a7e47f466cdceb6. --- cw-orch-daemon/src/core.rs | 24 +++++++++++++++++---- cw-orch-daemon/src/senders/cosmos.rs | 23 ++++++++++++++++++++- cw-orch-daemon/src/senders/tx.rs | 31 ++-------------------------- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index f3cf1fabe..8e1b882bc 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -20,11 +20,13 @@ use cw_orch_core::{ environment::{AsyncWasmQuerier, ChainInfoOwned, ChainState, IndexResponse, Querier}, log::transaction_target, }; +use flate2::{write, Compression}; use prost::Message; use serde::{de::DeserializeOwned, Serialize}; use serde_json::from_str; use std::{ fmt::Debug, + io::Write, ops::Deref, str::{from_utf8, FromStr}, time::Duration, @@ -347,18 +349,32 @@ impl DaemonAsyncBase { log::debug!(target: &transaction_target(), "Uploading file at {:?}", wasm_path); - let upload_result = self.sender.upload_wasm(wasm_path).await?; + let file_contents = std::fs::read(wasm_path.path())?; + let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); + e.write_all(&file_contents)?; + let wasm_byte_code = e.finish()?; + let store_msg = cosmrs::cosmwasm::MsgStoreCode { + sender: self.sender().account_id(), + wasm_byte_code, + instantiate_permission: None, + }; + + let result = self + .sender() + .commit_tx(vec![store_msg], None) + .await + .map_err(Into::into)?; - log::info!(target: &transaction_target(), "Uploading done: {:?}", upload_result.txhash); + log::info!(target: &transaction_target(), "Uploading done: {:?}", result.txhash); - let code_id = upload_result.uploaded_code_id().unwrap(); + let code_id = result.uploaded_code_id().unwrap(); // wait for the node to return the contract information for this upload let wasm = CosmWasm::new_async(self.channel()); while wasm._code(code_id).await.is_err() { self.next_block().await?; } - Ok(upload_result) + Ok(result) } } diff --git a/cw-orch-daemon/src/senders/cosmos.rs b/cw-orch-daemon/src/senders/cosmos.rs index e9d371cc4..9f1cb5c09 100644 --- a/cw-orch-daemon/src/senders/cosmos.rs +++ b/cw-orch-daemon/src/senders/cosmos.rs @@ -32,13 +32,15 @@ use cosmrs::{ }; use cosmwasm_std::{coin, Addr, Coin}; use cw_orch_core::{ + contract::WasmPath, environment::{ChainInfoOwned, ChainKind}, CoreEnvVars, CwEnvError, }; +use flate2::{write, Compression}; use crate::env::{LOCAL_MNEMONIC_ENV_NAME, MAIN_MNEMONIC_ENV_NAME, TEST_MNEMONIC_ENV_NAME}; use bitcoin::secp256k1::{All, Secp256k1, Signing}; -use std::{str::FromStr, sync::Arc}; +use std::{io::Write, str::FromStr, sync::Arc}; use cosmos_modules::vesting::PeriodicVestingAccount; use tonic::transport::Channel; @@ -415,6 +417,25 @@ impl Wallet { } } +// Helpers to facilitate some rare operations +impl Wallet { + /// Uploads the `WasmPath` path specifier on chain. + /// The resulting code_id can be extracted from the Transaction result using [cw_orch_core::environment::IndexResponse::uploaded_code_id] and returns the resulting code_id + pub async fn upload_wasm(&self, wasm_path: WasmPath) -> Result { + let file_contents = std::fs::read(wasm_path.path())?; + let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); + e.write_all(&file_contents)?; + let wasm_byte_code = e.finish()?; + let store_msg = cosmrs::cosmwasm::MsgStoreCode { + sender: self.account_id(), + wasm_byte_code, + instantiate_permission: None, + }; + + self.commit_tx(vec![store_msg], None).await + } +} + impl QuerySender for Wallet { type Error = DaemonError; type Options = CosmosOptions; diff --git a/cw-orch-daemon/src/senders/tx.rs b/cw-orch-daemon/src/senders/tx.rs index 2e8b48653..619d78ff9 100644 --- a/cw-orch-daemon/src/senders/tx.rs +++ b/cw-orch-daemon/src/senders/tx.rs @@ -1,15 +1,11 @@ -use std::io::Write; - use cosmrs::{tx::Msg, AccountId, Any}; use cosmwasm_std::Addr; -use cw_orch_core::contract::WasmPath; -use flate2::{write, Compression}; -use crate::{CosmTxResponse, DaemonError}; +use crate::CosmTxResponse; use super::query::QuerySender; -pub trait TxSender: QuerySender + Sync { +pub trait TxSender: QuerySender { /// Returns the `AccountId` of the sender that commits the transaction. fn account_id(&self) -> AccountId; @@ -39,27 +35,4 @@ pub trait TxSender: QuerySender + Sync { self.commit_tx_any(msgs, memo) } - - /// Uploads the `WasmPath` path specifier on chain. - /// The resulting code_id can be extracted from the Transaction result using [cw_orch_core::environment::IndexResponse::uploaded_code_id] and returns the resulting code_id - fn upload_wasm( - &self, - wasm_path: WasmPath, - ) -> impl std::future::Future> + Send { - async move { - let file_contents = std::fs::read(wasm_path.path())?; - let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); - e.write_all(&file_contents)?; - let wasm_byte_code = e.finish()?; - let store_msg = cosmrs::cosmwasm::MsgStoreCode { - sender: self.account_id(), - wasm_byte_code, - instantiate_permission: None, - }; - - self.commit_tx(vec![store_msg], None) - .await - .map_err(Into::into) - } - } } From 4c1128fe2e8ca9b67f2e7843ebce5d412fa2b9fb Mon Sep 17 00:00:00 2001 From: Kayanski Date: Thu, 12 Sep 2024 07:49:12 +0000 Subject: [PATCH 6/9] Removed code duplication --- cw-orch-daemon/src/core.rs | 20 ++--------------- cw-orch-daemon/src/senders/cosmos.rs | 32 ++++++++++++++++++---------- cw-orch-daemon/src/senders/mod.rs | 1 + 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index 8e1b882bc..c5cb07a9f 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -1,6 +1,6 @@ use crate::{ queriers::CosmWasm, - senders::{builder::SenderBuilder, query::QuerySender}, + senders::{builder::SenderBuilder, query::QuerySender, upload_wasm}, DaemonAsyncBuilder, DaemonState, }; @@ -20,13 +20,11 @@ use cw_orch_core::{ environment::{AsyncWasmQuerier, ChainInfoOwned, ChainState, IndexResponse, Querier}, log::transaction_target, }; -use flate2::{write, Compression}; use prost::Message; use serde::{de::DeserializeOwned, Serialize}; use serde_json::from_str; use std::{ fmt::Debug, - io::Write, ops::Deref, str::{from_utf8, FromStr}, time::Duration, @@ -349,21 +347,7 @@ impl DaemonAsyncBase { log::debug!(target: &transaction_target(), "Uploading file at {:?}", wasm_path); - let file_contents = std::fs::read(wasm_path.path())?; - let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); - e.write_all(&file_contents)?; - let wasm_byte_code = e.finish()?; - let store_msg = cosmrs::cosmwasm::MsgStoreCode { - sender: self.sender().account_id(), - wasm_byte_code, - instantiate_permission: None, - }; - - let result = self - .sender() - .commit_tx(vec![store_msg], None) - .await - .map_err(Into::into)?; + let result = upload_wasm(self.sender(), wasm_path).await?; log::info!(target: &transaction_target(), "Uploading done: {:?}", result.txhash); diff --git a/cw-orch-daemon/src/senders/cosmos.rs b/cw-orch-daemon/src/senders/cosmos.rs index 9f1cb5c09..b2ca6116d 100644 --- a/cw-orch-daemon/src/senders/cosmos.rs +++ b/cw-orch-daemon/src/senders/cosmos.rs @@ -422,20 +422,30 @@ impl Wallet { /// Uploads the `WasmPath` path specifier on chain. /// The resulting code_id can be extracted from the Transaction result using [cw_orch_core::environment::IndexResponse::uploaded_code_id] and returns the resulting code_id pub async fn upload_wasm(&self, wasm_path: WasmPath) -> Result { - let file_contents = std::fs::read(wasm_path.path())?; - let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); - e.write_all(&file_contents)?; - let wasm_byte_code = e.finish()?; - let store_msg = cosmrs::cosmwasm::MsgStoreCode { - sender: self.account_id(), - wasm_byte_code, - instantiate_permission: None, - }; - - self.commit_tx(vec![store_msg], None).await + upload_wasm(self, wasm_path).await } } +pub async fn upload_wasm( + sender: &T, + wasm_path: WasmPath, +) -> Result { + let file_contents = std::fs::read(wasm_path.path())?; + let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); + e.write_all(&file_contents)?; + let wasm_byte_code = e.finish()?; + let store_msg = cosmrs::cosmwasm::MsgStoreCode { + sender: sender.account_id(), + wasm_byte_code, + instantiate_permission: None, + }; + + sender + .commit_tx(vec![store_msg], None) + .await + .map_err(Into::into) +} + impl QuerySender for Wallet { type Error = DaemonError; type Options = CosmosOptions; diff --git a/cw-orch-daemon/src/senders/mod.rs b/cw-orch-daemon/src/senders/mod.rs index e637e4470..067e4d2a5 100644 --- a/cw-orch-daemon/src/senders/mod.rs +++ b/cw-orch-daemon/src/senders/mod.rs @@ -9,6 +9,7 @@ mod cosmos_batch; mod cosmos_options; mod query_only; +pub(crate) use cosmos::upload_wasm; pub use { cosmos::{CosmosSender, Wallet}, cosmos_batch::{options::CosmosBatchOptions, BatchDaemon, CosmosBatchSender}, From 55487e5bcf8d1f4d507fcfc3e8c0a9dcada4304f Mon Sep 17 00:00:00 2001 From: Kayanski Date: Thu, 12 Sep 2024 07:57:22 +0000 Subject: [PATCH 7/9] formatting --- cw-orch-daemon/src/senders/cosmos.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cw-orch-daemon/src/senders/cosmos.rs b/cw-orch-daemon/src/senders/cosmos.rs index 044b8727d..01776b412 100644 --- a/cw-orch-daemon/src/senders/cosmos.rs +++ b/cw-orch-daemon/src/senders/cosmos.rs @@ -1,8 +1,13 @@ use crate::{ - access_config_to_cosmrs, env::DaemonEnvVars, proto::injective::ETHEREUM_COIN_TYPE, queriers::Bank, tx_broadcaster::{ + access_config_to_cosmrs, + env::DaemonEnvVars, + proto::injective::ETHEREUM_COIN_TYPE, + queriers::Bank, + tx_broadcaster::{ account_sequence_strategy, assert_broadcast_code_cosm_response, insufficient_fee_strategy, TxBroadcaster, - }, CosmosOptions, GrpcChannel + }, + CosmosOptions, GrpcChannel, }; use crate::proto::injective::InjectiveEthAccount; From 754cf7dc5218ef5fb54a2450bd52f73e12363c64 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 16 Sep 2024 07:56:53 +0000 Subject: [PATCH 8/9] Moved upload_wasm --- cw-orch-daemon/src/core.rs | 42 ++++++++++++------- cw-orch-daemon/src/senders/cosmos.rs | 60 +++++++--------------------- cw-orch-daemon/src/senders/mod.rs | 1 - 3 files changed, 42 insertions(+), 61 deletions(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index dcd8e08df..2f9afa7d3 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -1,13 +1,11 @@ +use super::{ + cosmos_modules, error::DaemonError, queriers::Node, senders::Wallet, tx_resp::CosmTxResponse, +}; use crate::{ queriers::CosmWasm, - senders::{builder::SenderBuilder, query::QuerySender, upload_wasm}, + senders::{builder::SenderBuilder, query::QuerySender, tx::TxSender}, DaemonAsyncBuilder, DaemonState, }; - -use super::{ - cosmos_modules, error::DaemonError, queriers::Node, senders::Wallet, tx_resp::CosmTxResponse, -}; - use cosmrs::{ cosmwasm::{MsgExecuteContract, MsgInstantiateContract, MsgMigrateContract}, proto::cosmwasm::wasm::v1::MsgInstantiateContract2, @@ -16,26 +14,21 @@ use cosmrs::{ }; use cosmwasm_std::{Addr, Binary, Coin}; use cw_orch_core::{ - contract::interface_traits::Uploadable, + contract::{interface_traits::Uploadable, WasmPath}, environment::{ AccessConfig, AsyncWasmQuerier, ChainInfoOwned, ChainState, IndexResponse, Querier, }, log::transaction_target, }; +use flate2::{write, Compression}; use prost::Message; use serde::{de::DeserializeOwned, Serialize}; use serde_json::from_str; use std::{ - fmt::Debug, - ops::Deref, - str::{from_utf8, FromStr}, - time::Duration, + fmt::Debug, io::Write, ops::Deref, str::{from_utf8, FromStr}, time::Duration }; - use tonic::transport::Channel; -use crate::senders::tx::TxSender; - pub const INSTANTIATE_2_TYPE_URL: &str = "/cosmwasm.wasm.v1.MsgInstantiateContract2"; #[derive(Clone)] @@ -373,6 +366,27 @@ impl DaemonAsyncBase { } } +pub async fn upload_wasm( + sender: &T, + wasm_path: WasmPath, + access: Option, +) -> Result { + let file_contents = std::fs::read(wasm_path.path())?; + let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); + e.write_all(&file_contents)?; + let wasm_byte_code = e.finish()?; + let store_msg = cosmrs::cosmwasm::MsgStoreCode { + sender: sender.account_id(), + wasm_byte_code, + instantiate_permission: access.map(access_config_to_cosmrs).transpose()?, + }; + + sender + .commit_tx(vec![store_msg], None) + .await + .map_err(Into::into) +} + pub(crate) fn access_config_to_cosmrs( access_config: AccessConfig, ) -> Result { diff --git a/cw-orch-daemon/src/senders/cosmos.rs b/cw-orch-daemon/src/senders/cosmos.rs index 01776b412..952253f6f 100644 --- a/cw-orch-daemon/src/senders/cosmos.rs +++ b/cw-orch-daemon/src/senders/cosmos.rs @@ -1,28 +1,22 @@ +use super::{cosmos_options::CosmosWalletKey, query::QuerySender, tx::TxSender}; use crate::{ - access_config_to_cosmrs, - env::DaemonEnvVars, - proto::injective::ETHEREUM_COIN_TYPE, - queriers::Bank, + core::parse_cw_coins, + cosmos_modules::{self, auth::BaseAccount}, + env::{DaemonEnvVars, LOCAL_MNEMONIC_ENV_NAME, MAIN_MNEMONIC_ENV_NAME, TEST_MNEMONIC_ENV_NAME}, + error::DaemonError, + keys::private::PrivateKey, + proto::injective::{InjectiveEthAccount, ETHEREUM_COIN_TYPE}, + queriers::{Bank, Node}, tx_broadcaster::{ account_sequence_strategy, assert_broadcast_code_cosm_response, insufficient_fee_strategy, TxBroadcaster, }, - CosmosOptions, GrpcChannel, -}; - -use crate::proto::injective::InjectiveEthAccount; -use crate::{ - cosmos_modules::{self, auth::BaseAccount}, - error::DaemonError, - queriers::Node, tx_builder::TxBuilder, tx_resp::CosmTxResponse, + upload_wasm, CosmosOptions, GrpcChannel, }; - -#[cfg(feature = "eth")] -use crate::proto::injective::InjectiveSigner; - -use crate::{core::parse_cw_coins, keys::private::PrivateKey}; +use bitcoin::secp256k1::{All, Secp256k1, Signing}; +use cosmos_modules::vesting::PeriodicVestingAccount; use cosmrs::{ bank::MsgSend, crypto::secp256k1::SigningKey, @@ -37,16 +31,11 @@ use cw_orch_core::{ environment::{AccessConfig, ChainInfoOwned, ChainKind}, CoreEnvVars, CwEnvError, }; -use flate2::{write, Compression}; - -use crate::env::{LOCAL_MNEMONIC_ENV_NAME, MAIN_MNEMONIC_ENV_NAME, TEST_MNEMONIC_ENV_NAME}; -use bitcoin::secp256k1::{All, Secp256k1, Signing}; -use std::{io::Write, str::FromStr, sync::Arc}; - -use cosmos_modules::vesting::PeriodicVestingAccount; +use std::{str::FromStr, sync::Arc}; use tonic::transport::Channel; -use super::{cosmos_options::CosmosWalletKey, query::QuerySender, tx::TxSender}; +#[cfg(feature = "eth")] +use crate::proto::injective::InjectiveSigner; const GAS_BUFFER: f64 = 1.3; const BUFFER_THRESHOLD: u64 = 200_000; @@ -435,27 +424,6 @@ impl Wallet { } } -pub async fn upload_wasm( - sender: &T, - wasm_path: WasmPath, - access: Option, -) -> Result { - let file_contents = std::fs::read(wasm_path.path())?; - let mut e = write::GzEncoder::new(Vec::new(), Compression::default()); - e.write_all(&file_contents)?; - let wasm_byte_code = e.finish()?; - let store_msg = cosmrs::cosmwasm::MsgStoreCode { - sender: sender.account_id(), - wasm_byte_code, - instantiate_permission: access.map(access_config_to_cosmrs).transpose()?, - }; - - sender - .commit_tx(vec![store_msg], None) - .await - .map_err(Into::into) -} - impl QuerySender for Wallet { type Error = DaemonError; type Options = CosmosOptions; diff --git a/cw-orch-daemon/src/senders/mod.rs b/cw-orch-daemon/src/senders/mod.rs index 067e4d2a5..e637e4470 100644 --- a/cw-orch-daemon/src/senders/mod.rs +++ b/cw-orch-daemon/src/senders/mod.rs @@ -9,7 +9,6 @@ mod cosmos_batch; mod cosmos_options; mod query_only; -pub(crate) use cosmos::upload_wasm; pub use { cosmos::{CosmosSender, Wallet}, cosmos_batch::{options::CosmosBatchOptions, BatchDaemon, CosmosBatchSender}, From 18f28563d8cec0d07cf89e874290f38912df4615 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 16 Sep 2024 07:57:15 +0000 Subject: [PATCH 9/9] formatting --- cw-orch-daemon/src/core.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index 2f9afa7d3..05273cd6a 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -25,7 +25,11 @@ use prost::Message; use serde::{de::DeserializeOwned, Serialize}; use serde_json::from_str; use std::{ - fmt::Debug, io::Write, ops::Deref, str::{from_utf8, FromStr}, time::Duration + fmt::Debug, + io::Write, + ops::Deref, + str::{from_utf8, FromStr}, + time::Duration, }; use tonic::transport::Channel;