cosmwasm_std/query/
ibc.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::ibc::IbcChannel;
5
6/// These are queries to the various IBC modules to see the state of the contract's
7/// IBC connection. These will return errors if the contract is not "ibc enabled"
8#[non_exhaustive]
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum IbcQuery {
12    /// Gets the Port ID the current contract is bound to.
13    ///
14    /// Returns a `PortIdResponse`.
15    PortId {},
16    /// Lists all channels that are bound to a given port.
17    /// If `port_id` is omitted, this list all channels bound to the contract's port.
18    ///
19    /// Returns a `ListChannelsResponse`.
20    ListChannels { port_id: Option<String> },
21    /// Lists all information for a (portID, channelID) pair.
22    /// If port_id is omitted, it will default to the contract's own channel.
23    /// (To save a PortId{} call)
24    ///
25    /// Returns a `ChannelResponse`.
26    Channel {
27        channel_id: String,
28        port_id: Option<String>,
29    },
30    // TODO: Add more
31}
32
33#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
34pub struct PortIdResponse {
35    pub port_id: String,
36}
37
38impl_response_constructor!(PortIdResponse, port_id: String);
39
40#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
41pub struct ListChannelsResponse {
42    pub channels: Vec<IbcChannel>,
43}
44
45impl_response_constructor!(ListChannelsResponse, channels: Vec<IbcChannel>);
46
47#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
48pub struct ChannelResponse {
49    pub channel: Option<IbcChannel>,
50}
51
52impl_response_constructor!(ChannelResponse, channel: Option<IbcChannel>);