cosmwasm_std/query/
ibc.rs

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