tendermint/abci/request/query.rs
1use bytes::Bytes;
2
3use crate::{block, prelude::*};
4
5#[doc = include_str!("../doc/request-query.md")]
6#[derive(Clone, PartialEq, Eq, Debug)]
7pub struct Query {
8 /// Raw query bytes.
9 ///
10 /// Can be used with or in lieu of `path`.
11 pub data: Bytes,
12 /// Path of the request, like an HTTP `GET` path.
13 ///
14 /// Can be used with or in lieu of `data`.
15 ///
16 /// Applications MUST interpret `/store` as a query by key on the underlying
17 /// store. The key SHOULD be specified in the Data field. Applications SHOULD
18 /// allow queries over specific types like `/accounts/...` or `/votes/...`.
19 pub path: String,
20 /// The block height for which the query should be executed.
21 ///
22 /// The default `0` returns data for the latest committed block. Note that
23 /// this is the height of the block containing the application's Merkle root
24 /// hash, which represents the state as it was after committing the block at
25 /// `height - 1`.
26 pub height: block::Height,
27 /// Whether to return a Merkle proof with the response, if possible.
28 pub prove: bool,
29}
30
31// =============================================================================
32// Protobuf conversions
33// =============================================================================
34
35tendermint_pb_modules! {
36 use super::Query;
37
38 impl From<Query> for pb::abci::RequestQuery {
39 fn from(query: Query) -> Self {
40 Self {
41 data: query.data,
42 path: query.path,
43 height: query.height.into(),
44 prove: query.prove,
45 }
46 }
47 }
48
49 impl TryFrom<pb::abci::RequestQuery> for Query {
50 type Error = crate::Error;
51
52 fn try_from(query: pb::abci::RequestQuery) -> Result<Self, Self::Error> {
53 Ok(Self {
54 data: query.data,
55 path: query.path,
56 height: query.height.try_into()?,
57 prove: query.prove,
58 })
59 }
60 }
61
62 impl Protobuf<pb::abci::RequestQuery> for Query {}
63}