celestia_types/state/
abci.rs1use celestia_proto::cosmos::base::tendermint::v1beta1::{
2 AbciQueryResponse as RawAbciQueryResponse, ProofOps,
3};
4use serde::{Deserialize, Serialize};
5#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
6use wasm_bindgen::prelude::*;
7
8use crate::state::ErrorCode;
9use crate::{Error, Height, validation_error};
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
14#[cfg_attr(
15 all(target_arch = "wasm32", feature = "wasm-bindgen"),
16 wasm_bindgen(getter_with_clone)
17)]
18pub struct AbciQueryResponse {
19 #[cfg_attr(
24 all(target_arch = "wasm32", feature = "wasm-bindgen"),
25 wasm_bindgen(skip)
26 )]
27 pub height: Height,
28
29 pub code: ErrorCode,
31
32 pub codespace: String,
34
35 pub index: u64,
37
38 pub key: Vec<u8>,
40
41 pub value: Vec<u8>,
43
44 pub proof_ops: Option<ProofOps>,
49
50 pub log: String,
53
54 pub info: String,
56}
57
58#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
59#[wasm_bindgen]
60impl AbciQueryResponse {
61 #[wasm_bindgen(getter)]
66 pub fn height(&self) -> u64 {
67 self.height.value()
68 }
69}
70
71impl TryFrom<RawAbciQueryResponse> for AbciQueryResponse {
72 type Error = Error;
73
74 fn try_from(response: RawAbciQueryResponse) -> Result<AbciQueryResponse, Self::Error> {
75 Ok(AbciQueryResponse {
76 height: response.height.try_into()?,
77 code: response.code.try_into()?,
78 codespace: response.codespace,
79 index: response
80 .index
81 .try_into()
82 .map_err(|_| validation_error!("Negative index"))?,
83 key: response.key,
84 value: response.value,
85 proof_ops: response.proof_ops,
86 log: response.log,
87 info: response.info,
88 })
89 }
90}