use bytes::Bytes;
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 {
pub code: Code,
pub log: String,
pub info: String,
pub index: i64,
pub key: Bytes,
pub value: Bytes,
pub proof: Option<merkle::ProofOps>,
pub height: block::Height,
pub codespace: String,
}
tendermint_pb_modules! {
use super::Query;
impl From<Query> for pb::abci::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::abci::ResponseQuery> for Query {
type Error = crate::Error;
fn try_from(query: pb::abci::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::abci::ResponseQuery> for Query {}
}