use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_json_binary, Binary};
pub const TIMEOUT_SECONDS: u64 = 60 * 10; #[cw_serde]
enum Ack {
Result(Binary),
Error(String),
}
pub fn ack_success() -> Binary {
to_json_binary(&Ack::Result(b"1".into())).unwrap()
}
pub fn ack_fail(err: anyhow::Error) -> Binary {
to_json_binary(&Ack::Error(err.to_string())).unwrap()
}
pub mod event {
use cosmwasm_std::{Event, IbcChannel};
#[derive(Debug)]
pub struct IbcChannelConnectEvent<'a> {
pub channel: &'a IbcChannel,
}
impl<'a> From<IbcChannelConnectEvent<'a>> for Event {
fn from(src: IbcChannelConnectEvent) -> Self {
mixin_ibc_channel(Event::new("ibc-channel-connect"), src.channel)
}
}
#[derive(Debug)]
pub struct IbcChannelCloseEvent<'a> {
pub channel: &'a IbcChannel,
}
impl<'a> From<IbcChannelCloseEvent<'a>> for Event {
fn from(src: IbcChannelCloseEvent) -> Self {
mixin_ibc_channel(Event::new("ibc-channel-close"), src.channel)
}
}
fn mixin_ibc_channel(event: Event, channel: &IbcChannel) -> Event {
event
.add_attribute("endpoint-id", &channel.endpoint.channel_id)
.add_attribute("endpoint-port-id", &channel.endpoint.port_id)
.add_attribute(
"counterparty-endpoint-id",
&channel.counterparty_endpoint.channel_id,
)
.add_attribute(
"counterparty-endpoint-port-id",
&channel.counterparty_endpoint.port_id,
)
.add_attribute("order", format!("{:?}", channel.order))
.add_attribute("version", &channel.version)
.add_attribute("connection-id", &channel.connection_id)
}
}