use serde::{Deserialize, Serialize};
use cometbft::{abci, block, Hash};
use crate::dialect::{self, Dialect};
use crate::{prelude::*, request::RequestMessage, serializers};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
#[serde(with = "serializers::bytes::base64string")]
pub tx: Vec<u8>,
}
impl Request {
pub fn new(tx: impl Into<Vec<u8>>) -> Request {
Request { tx: tx.into() }
}
}
impl RequestMessage for Request {
fn method(&self) -> crate::Method {
crate::Method::BroadcastTxCommit
}
}
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 check_tx: abci::response::CheckTx,
#[serde(alias = "deliver_tx")]
pub tx_result: abci::types::ExecTxResult,
pub hash: Hash,
pub height: block::Height,
}
impl crate::Response for Response {}
pub mod v0_34 {
use super::Response;
use crate::dialect;
use crate::dialect::v0_34::Event;
use cometbft::{block, Hash};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct DialectResponse {
pub check_tx: dialect::CheckTx<Event>,
pub deliver_tx: dialect::DeliverTx<Event>,
pub hash: Hash,
pub height: block::Height,
}
impl crate::Response for DialectResponse {}
impl From<DialectResponse> for Response {
fn from(msg: DialectResponse) -> Self {
Self {
check_tx: msg.check_tx.into(),
tx_result: msg.deliver_tx.into(),
hash: msg.hash,
height: msg.height,
}
}
}
}