Skip to content

Commit

Permalink
Merge branch 'main' into buckram/fix-upload-with-access-unimplemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Buckram123 authored Sep 30, 2024
2 parents 8167855 + aad7559 commit 6e351c8
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 19 deletions.
8 changes: 4 additions & 4 deletions cw-orch-daemon/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl<Sender: TxSender> DaemonAsyncBase<Sender> {
contract_address: &Addr,
) -> Result<CosmTxResponse, DaemonError> {
let exec_msg: MsgExecuteContract = MsgExecuteContract {
sender: self.sender().account_id(),
sender: self.sender().msg_sender().map_err(Into::into)?,
contract: AccountId::from_str(contract_address.as_str())?,
msg: serde_json::to_vec(&exec_msg)?,
funds: parse_cw_coins(coins)?,
Expand Down Expand Up @@ -262,7 +262,7 @@ impl<Sender: TxSender> DaemonAsyncBase<Sender> {
code_id,
label: Some(label.unwrap_or("instantiate_contract").to_string()),
admin: admin.map(|a| FromStr::from_str(a.as_str()).unwrap()),
sender: self.sender().account_id(),
sender: self.sender().msg_sender().map_err(Into::into)?,
msg: serde_json::to_vec(&init_msg)?,
funds: parse_cw_coins(coins)?,
};
Expand Down Expand Up @@ -324,7 +324,7 @@ impl<Sender: TxSender> DaemonAsyncBase<Sender> {
contract_address: &Addr,
) -> Result<CosmTxResponse, DaemonError> {
let exec_msg: MsgMigrateContract = MsgMigrateContract {
sender: self.sender().account_id(),
sender: self.sender().msg_sender().map_err(Into::into)?,
contract: AccountId::from_str(contract_address.as_str())?,
msg: serde_json::to_vec(&migrate_msg)?,
code_id: new_code_id,
Expand Down Expand Up @@ -380,7 +380,7 @@ pub async fn upload_wasm<T: TxSender>(
e.write_all(&file_contents)?;
let wasm_byte_code = e.finish()?;
let store_msg = cosmrs::cosmwasm::MsgStoreCode {
sender: sender.account_id(),
sender: sender.msg_sender().map_err(Into::into)?,
wasm_byte_code,
instantiate_permission: access.map(access_config_to_cosmrs).transpose()?,
};
Expand Down
16 changes: 11 additions & 5 deletions cw-orch-daemon/src/senders/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,7 @@ impl Wallet {
recipient: &Addr,
coins: Vec<cosmwasm_std::Coin>,
) -> Result<CosmTxResponse, DaemonError> {
let acc_id = if let Some(granter) = self.options.authz_granter.as_ref() {
AccountId::from_str(granter.as_str()).unwrap()
} else {
self.account_id()
};
let acc_id = self.msg_sender()?;

let msg_send = MsgSend {
from_address: acc_id,
Expand Down Expand Up @@ -488,6 +484,16 @@ impl TxSender for Wallet {
// unwrap as address is validated on construction
.unwrap()
}

/// Actual sender of the messages.
/// This is different when using authz capabilites
fn msg_sender(&self) -> Result<AccountId, DaemonError> {
if let Some(sender) = &self.options.authz_granter {
Ok(sender.as_str().parse()?)
} else {
Ok(self.account_id())
}
}
}

fn get_mnemonic_env(chain_kind: &ChainKind) -> Result<String, CwEnvError> {
Expand Down
7 changes: 7 additions & 0 deletions cw-orch-daemon/src/senders/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pub trait TxSender: QuerySender {
Addr::unchecked(self.account_id().to_string())
}

/// Actual sender of the messages.
///
/// For example, this can be different when using authz capabilites
fn msg_sender(&self) -> Result<AccountId, Self::Error> {
Ok(self.account_id())
}

/// Commit a transaction to the chain using this sender.
fn commit_tx<T: Msg>(
&self,
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-core"
version = "2.1.0"
version = "2.1.1"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-mock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-mock"
version = "0.24.1"
version = "0.24.2"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-networks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-networks"
version = "0.24.1"
version = "0.24.2"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-traits"
version = "0.24.0"
version = "0.24.1"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/interchain/interchain-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cw-orch-daemon = { workspace = true, optional = true }
futures = "0.3.30"
ibc-relayer-types = { workspace = true }
log = { workspace = true }
polytone = "1.0.0"
# TODO: polytone = "2.0.0"
prost = "0.13.1"
serde_json = { workspace = true }
thiserror = { workspace = true }
Expand Down
58 changes: 57 additions & 1 deletion packages/interchain/interchain-core/src/ack_parser.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{from_json, Binary};
use cw_orch_core::environment::CwEnv;
use polytone::ack::Callback;
use prost::Message;
// TODO: when polytone updates to cosmwasm v2 use polytone::ack::Callback;
use polytone_callback::Callback;

use crate::{
env::decode_ack_error,
Expand Down Expand Up @@ -147,3 +148,58 @@ pub mod acknowledgement {
}
}
}

mod polytone_callback {
use super::*;

use cosmwasm_std::{SubMsgResponse, Uint64};

#[cw_serde]
pub struct ExecutionResponse {
/// The address on the remote chain that executed the messages.
pub executed_by: String,
/// Index `i` corresponds to the result of executing the `i`th
/// message.
pub result: Vec<SubMsgResponse>,
}

#[cw_serde]
pub struct ErrorResponse {
/// The index of the first message who's execution failed.
pub message_index: Uint64,
/// The error that occured executing the message.
pub error: String,
}

/// Copy of the [polytone::ack::Callback](https://docs.rs/polytone/1.0.0/polytone/ack/index.html#reexport.Callback)
/// But without cosmwasm v1 dependencies
#[cw_serde]
pub enum Callback {
/// Result of executing the requested query, or an error.
///
/// result[i] corresponds to the i'th query and contains the
/// base64 encoded query response.
Query(Result<Vec<Binary>, ErrorResponse>),

/// Result of executing the requested messages, or an error.
///
/// 14/04/23: if a submessage errors the reply handler can see
/// `codespace: wasm, code: 5`, but not the actual error. as a
/// result, we can't return good errors for Execution and this
/// error string will only tell you the error's codespace. for
/// example, an out-of-gas error is code 11 and looks like
/// `codespace: sdk, code: 11`.
Execute(Result<ExecutionResponse, String>),

/// An error occured that could not be recovered from. The only
/// known way that this can occur is message handling running out
/// of gas, in which case the error will be `codespace: sdk, code:
/// 11`.
///
/// This error is not named becuase it could also occur due to a
/// panic or unhandled error during message processing. We don't
/// expect this to happen and have carefully written the code to
/// avoid it.
FatalError(String),
}
}
2 changes: 1 addition & 1 deletion packages/interchain/interchain-core/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub trait InterchainEnv<Chain: IbcQueryHandler>: Clone {
/// use counter_contract::CounterContract;
/// let interchain = MockBech32InterchainEnv::new(vec![("osmosis-1","osmo"),("archway-1","arch")]);
///
/// let all_chains: Vec<&MockBeck32> = interchain.chains().collect();
/// let all_chains: Vec<&MockBech32> = interchain.chains().collect();
///
/// ```
fn chains<'a>(&'a self) -> impl Iterator<Item = &'a Chain>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<C: ChannelCreator> DaemonInterchain<C> {
/// let src_chain = OSMOSIS_1;
///
/// let interchain = DaemonInterchain::new(
/// vec![(src_chain.clone(), None), (dst_chain, None)],
/// vec![src_chain.clone(), dst_chain],
/// &ChannelCreationValidator,
/// ).unwrap();
///
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/cw-orch-contract-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-contract-derive"
version = "0.21.0"
version = "0.21.1"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/cw-orch-fns-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-fns-derive"
version = "0.23.0"
version = "0.23.1"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down

0 comments on commit 6e351c8

Please sign in to comment.