ibc_query/core/
context.rs

1//! Required traits for blanket implementations of [`gRPC query services`](crate::core).
2
3use ibc::core::channel::types::channel::IdentifiedChannelEnd;
4use ibc::core::channel::types::packet::PacketState;
5use ibc::core::client::types::Height;
6use ibc::core::connection::types::IdentifiedConnectionEnd;
7use ibc::core::host::types::error::HostError;
8use ibc::core::host::types::identifiers::{ClientId, ConnectionId, Sequence};
9use ibc::core::host::types::path::{ChannelEndPath, Path};
10use ibc::core::host::{ClientStateRef, ConsensusStateRef, ValidationContext};
11use ibc::core::primitives::prelude::*;
12
13/// Context to be implemented by the host to provide proofs in query responses
14pub trait ProvableContext {
15    /// Returns the proof for the given path at the given height.
16    /// As this is in the context of IBC, the path is expected to be an [`IbcPath`](Path).
17    fn get_proof(&self, height: Height, path: &Path) -> Option<Vec<u8>>;
18}
19
20/// Context to be implemented by the host that provides gRPC query services.
21pub trait QueryContext: ProvableContext + ValidationContext {
22    // Client queries
23
24    /// Returns the list of all clients.
25    fn client_states(&self) -> Result<Vec<(ClientId, ClientStateRef<Self>)>, HostError>;
26
27    /// Returns the list of all consensus states for the given client.
28    fn consensus_states(
29        &self,
30        client_id: &ClientId,
31    ) -> Result<Vec<(Height, ConsensusStateRef<Self>)>, HostError>;
32
33    /// Returns the list of all heights at which consensus states for the given client are.
34    fn consensus_state_heights(&self, client_id: &ClientId) -> Result<Vec<Height>, HostError>;
35
36    // Connection queries
37
38    /// Returns the list of all connection ends.
39    fn connection_ends(&self) -> Result<Vec<IdentifiedConnectionEnd>, HostError>;
40
41    /// Returns the list of all connection ids of the given client.
42    fn client_connection_ends(&self, client_id: &ClientId) -> Result<Vec<ConnectionId>, HostError>;
43
44    // Channel queries
45
46    /// Returns the list of all channel ends.
47    fn channel_ends(&self) -> Result<Vec<IdentifiedChannelEnd>, HostError>;
48
49    // Packet queries
50
51    /// Returns the list of all packet commitments for the given channel end.
52    fn packet_commitments(
53        &self,
54        channel_end_path: &ChannelEndPath,
55    ) -> Result<Vec<PacketState>, HostError>;
56
57    /// Filters the list of packet sequences for the given channel end that are acknowledged.
58    /// Returns all the packet acknowledgements if `sequences` is empty.
59    fn packet_acknowledgements(
60        &self,
61        channel_end_path: &ChannelEndPath,
62        sequences: impl ExactSizeIterator<Item = Sequence>,
63    ) -> Result<Vec<PacketState>, HostError>;
64
65    /// Filters the packet sequences for the given channel end that are not received.
66    fn unreceived_packets(
67        &self,
68        channel_end_path: &ChannelEndPath,
69        sequences: impl ExactSizeIterator<Item = Sequence>,
70    ) -> Result<Vec<Sequence>, HostError>;
71
72    /// Filters the list of packet sequences for the given channel end whose acknowledgement is not received.
73    /// Returns all the unreceived acknowledgements if `sequences` is empty.
74    fn unreceived_acks(
75        &self,
76        channel_end_path: &ChannelEndPath,
77        sequences: impl ExactSizeIterator<Item = Sequence>,
78    ) -> Result<Vec<Sequence>, HostError>;
79}