Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ucs01): batch sub-messages (closes #840) #841

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion cosmwasm/ucs01-relay/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ pub fn execute(
Err(ContractError::Unauthorized)
} else {
let normalized_hash = hash.0.try_into().expect("impossible");
FOREIGN_DENOM_TO_HASH.save(deps.storage, denom.clone().into(), &normalized_hash)?;
FOREIGN_DENOM_TO_HASH.save(deps.storage, denom.clone(), &normalized_hash)?;
HASH_TO_FOREIGN_DENOM.save(deps.storage, normalized_hash, &denom.to_string())?;
Ok(Response::default())
}
}
ExecuteMsg::BatchExecute { msgs } => {
if info.sender != env.contract.address {
Err(ContractError::Unauthorized)
} else {
Ok(Response::default().add_messages(msgs))
}
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion cosmwasm/ucs01-relay/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Binary, IbcChannel, Uint512};
use cosmwasm_std::{Binary, CosmosMsg, IbcChannel, Uint512};
use token_factory_api::TokenFactoryMsg;

use crate::state::ChannelInfo;

Expand All @@ -24,6 +25,9 @@ pub enum ExecuteMsg {
RegisterDenom { denom: String, hash: Binary },
/// Change the admin (must be called by current admin)
UpdateAdmin { admin: String },
BatchExecute {
msgs: Vec<CosmosMsg<TokenFactoryMsg>>,
},
}

/// This is the message we accept via Receive
Expand Down
11 changes: 9 additions & 2 deletions cosmwasm/ucs01-relay/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl<'a> TransferProtocol for Ics20Protocol<'a> {
receiver: &str,
tokens: Vec<TransferToken>,
) -> Result<Vec<CosmosMsg<Self::CustomMsg>>, ContractError> {
StatefulOnReceive {
let msgs = StatefulOnReceive {
deps: self.common.deps.branch(),
}
.receive_phase1_transfer(
Expand All @@ -460,7 +460,14 @@ impl<'a> TransferProtocol for Ics20Protocol<'a> {
&self.common.channel.counterparty_endpoint,
receiver,
tokens,
)
)?;

Ok(vec![wasm_execute(
self.self_addr(),
&ExecuteMsg::BatchExecute { msgs },
vec![],
)?
.into()])
}

fn normalize_for_ibc_transfer(
Expand Down