ibc_query/
types.rs

1use ibc::core::primitives::prelude::*;
2use ibc_proto::cosmos::base::query::v1beta1::{
3    PageRequest as RawPageRequest, PageResponse as RawPageResponse,
4};
5
6pub type Proof = Vec<u8>;
7
8#[derive(Clone, Debug, Default)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
11pub struct PageRequest {
12    /// key is a value returned in PageResponse.next_key to begin
13    /// querying the next page most efficiently. Only one of offset or key
14    /// should be set.
15    pub key: Vec<u8>,
16    /// offset is a numeric offset that can be used when the key is unavailable.
17    /// It is less efficient than using the key.
18    /// Only one of offset or key should be set.
19    pub offset: u64,
20    /// limit is the total number of results to be returned to the result page.
21    /// If left empty, it will default to a value to be set by each app.
22    pub limit: u64,
23    /// count_total is set to true  to indicate that the result set should include
24    /// a count of the total number of items available for pagination in UIs.
25    /// count_total is only respected when offset is used. It is ignored when key
26    /// is set.
27    pub count_total: bool,
28    /// reverse is set to true if results are to be returned in the descending order.
29    pub reverse: bool,
30}
31
32impl PageRequest {
33    pub fn all() -> Self {
34        Self {
35            limit: u64::MAX,
36            ..Default::default()
37        }
38    }
39}
40
41impl From<PageRequest> for RawPageRequest {
42    fn from(request: PageRequest) -> Self {
43        Self {
44            key: request.key,
45            offset: request.offset,
46            limit: request.limit,
47            count_total: request.count_total,
48            reverse: request.reverse,
49        }
50    }
51}
52
53impl From<RawPageRequest> for PageRequest {
54    fn from(request: RawPageRequest) -> Self {
55        Self {
56            key: request.key,
57            offset: request.offset,
58            limit: request.limit,
59            count_total: request.count_total,
60            reverse: request.reverse,
61        }
62    }
63}
64
65#[derive(Clone, Debug, Default)]
66#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
68pub struct PageResponse {
69    /// next_key is the key to be passed to PageRequest.key to
70    /// query the next page most efficiently. It will be empty if
71    /// there are no more results.
72    pub next_key: Vec<u8>,
73    /// total is the total number of results available if PageRequest.count_total
74    /// was set, its value is undefined otherwise
75    pub total: u64,
76}
77
78impl From<PageResponse> for RawPageResponse {
79    fn from(response: PageResponse) -> Self {
80        Self {
81            next_key: response.next_key,
82            total: response.total,
83        }
84    }
85}
86
87impl From<RawPageResponse> for PageResponse {
88    fn from(response: RawPageResponse) -> Self {
89        Self {
90            next_key: response.next_key,
91            total: response.total,
92        }
93    }
94}