levana_perpswap_cosmos/
ibc.rs1use cosmwasm_schema::cw_serde;
3use cosmwasm_std::{to_json_binary, Binary};
4
5pub const TIMEOUT_SECONDS: u64 = 60 * 10; #[cw_serde]
11enum Ack {
12 Result(Binary),
13 Error(String),
14}
15
16pub fn ack_success() -> Binary {
18 to_json_binary(&Ack::Result(b"1".into())).unwrap()
19}
20
21pub fn ack_fail(err: anyhow::Error) -> Binary {
23 to_json_binary(&Ack::Error(err.to_string())).unwrap()
24}
25
26pub mod event {
28 use cosmwasm_std::{Event, IbcChannel};
29
30 #[derive(Debug)]
32 pub struct IbcChannelConnectEvent<'a> {
33 pub channel: &'a IbcChannel,
35 }
36
37 impl<'a> From<IbcChannelConnectEvent<'a>> for Event {
38 fn from(src: IbcChannelConnectEvent) -> Self {
39 mixin_ibc_channel(Event::new("ibc-channel-connect"), src.channel)
40 }
41 }
42
43 #[derive(Debug)]
45 pub struct IbcChannelCloseEvent<'a> {
46 pub channel: &'a IbcChannel,
48 }
49
50 impl<'a> From<IbcChannelCloseEvent<'a>> for Event {
51 fn from(src: IbcChannelCloseEvent) -> Self {
52 mixin_ibc_channel(Event::new("ibc-channel-close"), src.channel)
53 }
54 }
55
56 fn mixin_ibc_channel(event: Event, channel: &IbcChannel) -> Event {
57 event
58 .add_attribute("endpoint-id", &channel.endpoint.channel_id)
59 .add_attribute("endpoint-port-id", &channel.endpoint.port_id)
60 .add_attribute(
61 "counterparty-endpoint-id",
62 &channel.counterparty_endpoint.channel_id,
63 )
64 .add_attribute(
65 "counterparty-endpoint-port-id",
66 &channel.counterparty_endpoint.port_id,
67 )
68 .add_attribute("order", format!("{:?}", channel.order))
69 .add_attribute("version", &channel.version)
70 .add_attribute("connection-id", &channel.connection_id)
71 }
72}