tendermint_rpc/endpoint/
tx_search.rs

1//! `/tx_search` endpoint JSON-RPC wrapper
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6    dialect::{self, Dialect},
7    prelude::*,
8    request::RequestMessage,
9    serializers, Method, Order,
10};
11
12pub use super::tx;
13
14/// Request for searching for transactions with their results.
15#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
16pub struct Request {
17    pub query: String,
18    pub prove: bool,
19    #[serde(with = "serializers::from_str")]
20    pub page: u32,
21    #[serde(with = "serializers::from_str")]
22    pub per_page: u8,
23    pub order_by: Order,
24}
25
26impl Request {
27    /// Constructor.
28    pub fn new(
29        query: impl ToString,
30        prove: bool,
31        page: u32,
32        per_page: u8,
33        order_by: Order,
34    ) -> Self {
35        Self {
36            query: query.to_string(),
37            prove,
38            page,
39            per_page,
40            order_by,
41        }
42    }
43}
44
45impl RequestMessage for Request {
46    fn method(&self) -> Method {
47        Method::TxSearch
48    }
49}
50
51impl crate::Request<dialect::v0_34::Dialect> for Request {
52    type Response = self::v0_34::DialectResponse;
53}
54
55impl crate::Request<dialect::v0_37::Dialect> for Request {
56    type Response = Response;
57}
58
59impl crate::Request<dialect::v0_38::Dialect> for Request {
60    type Response = Response;
61}
62
63impl<S: Dialect> crate::SimpleRequest<S> for Request
64where
65    Self: crate::Request<S>,
66    Response: From<Self::Response>,
67{
68    type Output = Response;
69}
70
71#[derive(Clone, Debug, Serialize, Deserialize)]
72pub struct Response {
73    pub txs: Vec<tx::Response>,
74    #[serde(with = "serializers::from_str")]
75    pub total_count: u32,
76}
77
78impl crate::Response for Response {}
79
80/// Serialization for /tx_search endpoint format in Tendermint 0.34
81pub mod v0_34 {
82    use super::{tx, Response};
83    use crate::prelude::*;
84    use crate::serializers;
85    use serde::{Deserialize, Serialize};
86
87    /// RPC dialect helper for serialization of the response.
88    #[derive(Debug, Deserialize, Serialize)]
89    pub struct DialectResponse {
90        pub txs: Vec<tx::v0_34::DialectResponse>,
91        #[serde(with = "serializers::from_str")]
92        pub total_count: u32,
93    }
94
95    impl crate::Response for DialectResponse {}
96
97    impl From<DialectResponse> for Response {
98        fn from(msg: DialectResponse) -> Self {
99            Self {
100                txs: msg.txs.into_iter().map(Into::into).collect(),
101                total_count: msg.total_count,
102            }
103        }
104    }
105}