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