use celestia_proto::cosmos::base::tendermint::v1beta1::{
AbciQueryResponse as RawAbciQueryResponse, ProofOps,
};
use serde::{Deserialize, Serialize};
#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
use wasm_bindgen::prelude::*;
use crate::state::ErrorCode;
use crate::{Error, Height, validation_error};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
#[cfg_attr(
all(target_arch = "wasm32", feature = "wasm-bindgen"),
wasm_bindgen(getter_with_clone)
)]
pub struct AbciQueryResponse {
#[cfg_attr(
all(target_arch = "wasm32", feature = "wasm-bindgen"),
wasm_bindgen(skip)
)]
pub height: Height,
pub code: ErrorCode,
pub codespace: String,
pub index: u64,
pub key: Vec<u8>,
pub value: Vec<u8>,
pub proof_ops: Option<ProofOps>,
pub log: String,
pub info: String,
}
#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
#[wasm_bindgen]
impl AbciQueryResponse {
#[wasm_bindgen(getter)]
pub fn height(&self) -> u64 {
self.height.value()
}
}
impl TryFrom<RawAbciQueryResponse> for AbciQueryResponse {
type Error = Error;
fn try_from(response: RawAbciQueryResponse) -> Result<AbciQueryResponse, Self::Error> {
Ok(AbciQueryResponse {
height: response.height.try_into()?,
code: response.code.try_into()?,
codespace: response.codespace,
index: response
.index
.try_into()
.map_err(|_| validation_error!("Negative index"))?,
key: response.key,
value: response.value,
proof_ops: response.proof_ops,
log: response.log,
info: response.info,
})
}
}