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.
9/// Most of these will return errors if the contract is not "ibc enabled".
10#[non_exhaustive]
11#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
12#[serde(rename_all = "snake_case")]
13pub enum IbcQuery {
14    /// Gets the Port ID the current contract is bound to.
15    ///
16    /// Returns a `PortIdResponse`.
17    PortId {},
18    /// Lists all channels that are bound to a given port.
19    /// If `port_id` is omitted, this list all channels bound to the contract's port.
20    ///
21    /// Returns a `ListChannelsResponse`.
22    #[deprecated = "Returns a potentially unbound number of results. If you think you have a valid usecase, please open an issue."]
23    ListChannels { port_id: Option<String> },
24    /// Lists all information for a (portID, channelID) pair.
25    /// If port_id is omitted, it will default to the contract's own channel.
26    /// (To save a PortId{} call)
27    ///
28    /// Returns a `ChannelResponse`.
29    Channel {
30        channel_id: String,
31        port_id: Option<String>,
32    },
33    /// Queries whether the given channel supports IBC fees.
34    /// If port_id is omitted, it will default to the contract's own channel.
35    /// (To save a PortId{} call)
36    ///
37    /// Returns a `FeeEnabledChannelResponse`.
38    #[cfg(feature = "cosmwasm_2_2")]
39    FeeEnabledChannel {
40        port_id: Option<String>,
41        channel_id: String,
42    },
43}
44
45#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
46#[non_exhaustive]
47pub struct PortIdResponse {
48    pub port_id: String,
49}
50
51impl_response_constructor!(PortIdResponse, port_id: String);
52
53#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
54#[non_exhaustive]
55pub struct ListChannelsResponse {
56    pub channels: Vec<IbcChannel>,
57}
58
59impl_response_constructor!(ListChannelsResponse, channels: Vec<IbcChannel>);
60
61#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
62#[non_exhaustive]
63pub struct ChannelResponse {
64    pub channel: Option<IbcChannel>,
65}
66
67impl_response_constructor!(ChannelResponse, channel: Option<IbcChannel>);
68
69#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
70#[non_exhaustive]
71pub struct FeeEnabledChannelResponse {
72    pub fee_enabled: bool,
73}
74
75impl_response_constructor!(FeeEnabledChannelResponse, fee_enabled: bool);