tendermint/abci/response/query.rs
1use bytes::Bytes;
2
3/// XXX(hdevalence): hide merkle::proof and re-export its contents from merkle?
4use crate::merkle::proof as merkle;
5use crate::{abci::Code, block, prelude::*};
6
7#[doc = include_str!("../doc/response-query.md")]
8#[derive(Clone, PartialEq, Eq, Debug, Default)]
9pub struct Query {
10 /// The response code for the query.
11 pub code: Code,
12 /// The output of the application's logger.
13 ///
14 /// **May be non-deterministic**.
15 pub log: String,
16 /// Additional information.
17 ///
18 /// **May be non-deterministic**.
19 pub info: String,
20 /// The index of the key in the tree.
21 pub index: i64,
22 /// The key of the matching data.
23 pub key: Bytes,
24 /// The value of the matching data.
25 pub value: Bytes,
26 /// Serialized proof for the value data, if requested, to be verified against
27 /// the app hash for the given `height`.
28 pub proof: Option<merkle::ProofOps>,
29 /// The block height from which data was derived.
30 ///
31 /// Note that this is the height of the block containing the application's
32 /// Merkle root hash, which represents the state as it was after committing
33 /// the block at `height - 1`.
34 pub height: block::Height,
35 /// The namespace for the `code`.
36 pub codespace: String,
37}
38
39// =============================================================================
40// Protobuf conversions
41// =============================================================================
42
43tendermint_pb_modules! {
44 use super::Query;
45
46 impl From<Query> for pb::abci::ResponseQuery {
47 fn from(query: Query) -> Self {
48 Self {
49 code: query.code.into(),
50 log: query.log,
51 info: query.info,
52 index: query.index,
53 key: query.key,
54 value: query.value,
55 proof_ops: query.proof.map(Into::into),
56 height: query.height.into(),
57 codespace: query.codespace,
58 }
59 }
60 }
61
62 impl TryFrom<pb::abci::ResponseQuery> for Query {
63 type Error = crate::Error;
64
65 fn try_from(query: pb::abci::ResponseQuery) -> Result<Self, Self::Error> {
66 Ok(Self {
67 code: query.code.into(),
68 log: query.log,
69 info: query.info,
70 index: query.index,
71 key: query.key,
72 value: query.value,
73 proof: query.proof_ops.map(TryInto::try_into).transpose()?,
74 height: query.height.try_into()?,
75 codespace: query.codespace,
76 })
77 }
78 }
79
80 impl Protobuf<pb::abci::ResponseQuery> for Query {}
81}