use cometbft::{abci, block, tx, Hash};
use serde::{Deserialize, Serialize};
use crate::dialect::{self, Dialect};
use crate::{prelude::*, request::RequestMessage, serializers, Method};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
#[serde(with = "serializers::tx_hash_base64")]
pub hash: Hash,
pub prove: bool,
}
impl Request {
pub fn new(hash: Hash, prove: bool) -> Self {
Self { hash, prove }
}
}
impl RequestMessage for Request {
fn method(&self) -> Method {
Method::Tx
}
}
impl crate::Request<dialect::v0_34::Dialect> for Request {
type Response = self::v0_34::DialectResponse;
}
impl crate::Request<dialect::v1::Dialect> for Request {
type Response = Response;
}
impl<S: Dialect> crate::SimpleRequest<S> for Request
where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = Response;
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Response {
pub hash: Hash,
pub height: block::Height,
pub index: u32,
pub tx_result: abci::types::ExecTxResult,
#[serde(with = "serializers::bytes::base64string")]
pub tx: Vec<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
pub proof: Option<tx::Proof>,
}
impl crate::Response for Response {}
pub mod v0_34 {
use super::Response;
use crate::dialect::v0_34::Event;
use crate::prelude::*;
use crate::{dialect, serializers};
use cometbft::{block, tx, Hash};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct DialectResponse {
pub hash: Hash,
pub height: block::Height,
pub index: u32,
pub tx_result: dialect::DeliverTx<Event>,
#[serde(with = "serializers::bytes::base64string")]
pub tx: Vec<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
pub proof: Option<tx::Proof>,
}
impl crate::Response for DialectResponse {}
impl From<DialectResponse> for Response {
fn from(msg: DialectResponse) -> Self {
Self {
hash: msg.hash,
height: msg.height,
index: msg.index,
tx_result: msg.tx_result.into(),
tx: msg.tx,
proof: msg.proof,
}
}
}
}