cometbft_rpc/endpoint/broadcast/
tx_async.rs

1//! `/broadcast_tx_async`: broadcast a transaction and return immediately.
2
3use bytes::Bytes;
4use cometbft::{abci::Code, Hash};
5use serde::{Deserialize, Serialize};
6
7use crate::{dialect::Dialect, prelude::*, request::RequestMessage, serializers};
8
9/// `/broadcast_tx_async`: broadcast a transaction and return immediately.
10#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
11pub struct Request {
12    /// Transaction to broadcast
13    #[serde(with = "serializers::bytes::base64string")]
14    pub tx: Vec<u8>,
15}
16
17impl Request {
18    /// Create a new async transaction broadcast RPC request
19    pub fn new(tx: impl Into<Vec<u8>>) -> Request {
20        Request { tx: tx.into() }
21    }
22}
23
24impl RequestMessage for Request {
25    fn method(&self) -> crate::Method {
26        crate::Method::BroadcastTxAsync
27    }
28}
29
30impl<S: Dialect> crate::Request<S> for Request {
31    type Response = Response;
32}
33
34impl<S: Dialect> crate::SimpleRequest<S> for Request {
35    type Output = Response;
36}
37
38/// Response from either an async or sync transaction broadcast request.
39#[derive(Clone, Debug, Deserialize, Serialize)]
40pub struct Response {
41    /// Code
42    pub code: Code,
43
44    /// Data
45    #[serde(with = "serializers::bytes::base64string")]
46    pub data: Bytes,
47
48    /// Log
49    pub log: String,
50
51    /// Transaction hash
52    pub hash: Hash,
53}
54
55impl crate::Response for Response {}