Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
benluelo committed Nov 27, 2024
1 parent 1abe148 commit 67cb5a1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
14 changes: 10 additions & 4 deletions cosmwasm/union-ibc/core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,11 @@ fn delete_packet_commitment(
}

fn commit_packet(packet: &Packet) -> H256 {
commit(packet.abi_encode_params())
commit(packet.abi_encode())
}

fn commit_packets(packets: &[Packet]) -> H256 {
commit(packets.abi_encode_params())
commit(packets.abi_encode())
}

fn register_client(
Expand Down Expand Up @@ -1395,7 +1395,10 @@ fn write_acknowledgement(
// make sure the caller owns the channel
let port_id = CHANNEL_OWNER.load(deps.storage, channel_id)?;
if port_id != sender {
return Err(ContractError::Unauthorized);
return Err(ContractError::Unauthorized {
owner: port_id,
caller: sender,
});
}

let commitment_key =
Expand Down Expand Up @@ -1445,7 +1448,10 @@ fn send_packet(

let port_id = CHANNEL_OWNER.load(deps.storage, source_channel)?;
if port_id != sender {
return Err(ContractError::Unauthorized);
return Err(ContractError::Unauthorized {
owner: port_id,
caller: sender,
});
}

let channel = ensure_channel_state(deps.as_ref(), source_channel)?;
Expand Down
6 changes: 3 additions & 3 deletions cosmwasm/union-ibc/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod contract;
pub mod state;

use cosmwasm_std::StdError;
use cosmwasm_std::{Addr, StdError};
use ibc_solidity::ibc::{ChannelState, ConnectionState};
use thiserror::Error;

Expand Down Expand Up @@ -38,8 +38,8 @@ pub enum ContractError {
timeout_timestamp: u64,
current_timestamp: u64,
},
#[error("Caller is not the owner of the channel")]
Unauthorized,
#[error("Caller ({caller}) is not the owner ({owner}) of the channel")]
Unauthorized { owner: Addr, caller: Addr },
#[error("Packet not received")]
PacketNotReceived,
#[error("Packet is already acknowledged")]
Expand Down
10 changes: 5 additions & 5 deletions lib/ibc-solidity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,13 +776,13 @@ mod tests {
fn packet_hash() {
dbg!(keccak256(
Packet {
source_channel: 2,
destination_channel: 6,
data: bytes!("0000000000000000000000000000000000000000000000000000000000000000"),
source_channel: 1,
destination_channel: 5,
data: bytes!("0000000000000000000000000000000000000000000000000000000000000001"),
timeout_height: 0,
timeout_timestamp: 1733628077574130799
timeout_timestamp: 10000000
}
.abi_encode_params()
.abi_encode()
));
}
}
2 changes: 1 addition & 1 deletion voyager/plugins/transaction-batch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ async fn do_make_msg_union(
QueryHeight::Specific(origin_chain_proof_height),
unionlabs::ics24::ethabi::BatchPacketsPath {
channel_id: event.packet.source_channel.channel_id,
batch_hash: keccak256(packet.abi_encode_params()),
batch_hash: keccak256(packet.abi_encode()),
},
)
.await?;
Expand Down
23 changes: 22 additions & 1 deletion voyager/plugins/transaction/cosmos-sdk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,28 @@ fn process_msgs(
}
ibc_union::IbcMsg::ChannelCloseInit(_msg_channel_close_init) => todo!(),
ibc_union::IbcMsg::ChannelCloseConfirm(_msg_channel_close_confirm) => todo!(),
ibc_union::IbcMsg::PacketRecv(_msg_packet_recv) => todo!(),
ibc_union::IbcMsg::PacketRecv(msg_packet_recv) => {
dbg!(&msg_packet_recv);

let packet_recv = union_ibc_msg::msg::ExecuteMsg::PacketRecv(
union_ibc_msg::msg::MsgPacketRecv {
packets: msg_packet_recv.packets,
relayer_msgs: msg_packet_recv.relayer_msgs,
proof: msg_packet_recv.proof,
proof_height: msg_packet_recv.proof_height,
relayer: signer.to_string(),
},
);

dbg!(&packet_recv);

mk_any(&protos::cosmwasm::wasm::v1::MsgExecuteContract {
sender: signer.to_string(),
contract: ibc_union_contract_address.to_string(),
msg: serde_json::to_vec(&packet_recv).unwrap(),
funds: vec![],
})
}
ibc_union::IbcMsg::PacketAcknowledgement(_msg_packet_acknowledgement) => {
todo!()
}
Expand Down

0 comments on commit 67cb5a1

Please sign in to comment.