|
| 1 | +use crate::proto; |
| 2 | + |
| 3 | +/// PageRequest is to be embedded in gRPC request messages for efficient |
| 4 | +/// pagination. |
| 5 | +#[derive(Clone, Debug, Eq, PartialEq)] |
| 6 | +pub struct PageRequest { |
| 7 | + /// key is a value returned in PageResponse.next_key to begin |
| 8 | + /// querying the next page most efficiently. Only one of offset or key |
| 9 | + /// should be set. |
| 10 | + pub key: Vec<u8>, |
| 11 | + |
| 12 | + /// offset is a numeric offset that can be used when key is unavailable. |
| 13 | + /// It is less efficient than using key. Only one of offset or key should |
| 14 | + /// be set. |
| 15 | + pub offset: u64, |
| 16 | + /// limit is the total number of results to be returned in the result page. |
| 17 | + /// If left empty it will default to a value to be set by each app. |
| 18 | + pub limit: u64, |
| 19 | + /// count_total is set to true to indicate that the result set should include |
| 20 | + /// a count of the total number of items available for pagination in UIs. |
| 21 | + /// count_total is only respected when offset is used. It is ignored when key |
| 22 | + /// is set. |
| 23 | + pub count_total: bool, |
| 24 | + |
| 25 | + /// reverse is set to true if results are to be returned in the descending order. |
| 26 | + /// |
| 27 | + /// Since: cosmos-sdk 0.43 |
| 28 | + pub reverse: bool, |
| 29 | +} |
| 30 | + |
| 31 | +impl From<proto::cosmos::base::query::v1beta1::PageRequest> for PageRequest { |
| 32 | + fn from(proto: cosmos_sdk_proto::cosmos::base::query::v1beta1::PageRequest) -> Self { |
| 33 | + PageRequest { |
| 34 | + key: proto.key, |
| 35 | + offset: proto.offset, |
| 36 | + limit: proto.limit, |
| 37 | + count_total: proto.count_total, |
| 38 | + reverse: proto.reverse, |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +impl From<PageRequest> for proto::cosmos::base::query::v1beta1::PageRequest { |
| 44 | + fn from(page_request: PageRequest) -> Self { |
| 45 | + proto::cosmos::base::query::v1beta1::PageRequest { |
| 46 | + key: page_request.key, |
| 47 | + offset: page_request.offset, |
| 48 | + limit: page_request.limit, |
| 49 | + count_total: page_request.count_total, |
| 50 | + reverse: page_request.reverse, |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +/// PageResponse is to be embedded in gRPC response messages where the |
| 56 | +/// corresponding request message has used PageRequest. |
| 57 | +#[derive(Clone, Debug, Eq, PartialEq)] |
| 58 | +pub struct PageResponse { |
| 59 | + /// next_key is the key to be passed to PageRequest.key to |
| 60 | + /// query the next page most efficiently. It will be empty if |
| 61 | + /// there are no more results. |
| 62 | + pub next_key: Vec<u8>, |
| 63 | + |
| 64 | + /// total is total number of results available if PageRequest.count_total |
| 65 | + /// was set, its value is undefined otherwise |
| 66 | + pub total: u64, |
| 67 | +} |
| 68 | + |
| 69 | +impl From<proto::cosmos::base::query::v1beta1::PageResponse> for PageResponse { |
| 70 | + fn from(proto: cosmos_sdk_proto::cosmos::base::query::v1beta1::PageResponse) -> Self { |
| 71 | + PageResponse { |
| 72 | + next_key: proto.next_key, |
| 73 | + total: proto.total, |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +impl From<PageResponse> for proto::cosmos::base::query::v1beta1::PageResponse { |
| 79 | + fn from(page_response: PageResponse) -> Self { |
| 80 | + proto::cosmos::base::query::v1beta1::PageResponse { |
| 81 | + next_key: page_response.next_key, |
| 82 | + total: page_response.total, |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments