From f81ae5878f5f01b050ff9e66b8f5facb26453f60 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 24 Sep 2024 16:27:28 +0200 Subject: [PATCH] Fix block-related queries to use compat mode --- rpc/src/client/transport/http.rs | 31 +++++++++++++++++++++++++++ rpc/src/client/transport/websocket.rs | 31 +++++++++++++++++++++++++++ rpc/src/endpoint/block.rs | 22 ++++++++----------- rpc/src/endpoint/block_by_hash.rs | 24 +++++++++------------ rpc/src/endpoint/block_results.rs | 2 +- rpc/src/endpoint/block_search.rs | 21 ++++++++---------- rpc/src/endpoint/header.rs | 14 ++++++------ rpc/src/endpoint/header_by_hash.rs | 14 ++++++------ rpc/src/endpoint/tx.rs | 2 +- rpc/src/endpoint/tx_search.rs | 2 +- 10 files changed, 107 insertions(+), 56 deletions(-) diff --git a/rpc/src/client/transport/http.rs b/rpc/src/client/transport/http.rs index 5778b31ea..2885d63b9 100644 --- a/rpc/src/client/transport/http.rs +++ b/rpc/src/client/transport/http.rs @@ -257,6 +257,24 @@ impl Client for HttpClient { self.perform_with_dialect(request, LatestDialect).await } + async fn block(&self, height: H) -> Result + where + H: Into + Send, + { + perform_with_compat!(self, endpoint::block::Request::new(height.into())) + } + + async fn block_by_hash( + &self, + hash: tendermint::Hash, + ) -> Result { + perform_with_compat!(self, endpoint::block_by_hash::Request::new(hash)) + } + + async fn latest_block(&self) -> Result { + perform_with_compat!(self, endpoint::block::Request::default()) + } + async fn block_results(&self, height: H) -> Result where H: Into + Send, @@ -268,6 +286,19 @@ impl Client for HttpClient { perform_with_compat!(self, endpoint::block_results::Request::default()) } + async fn block_search( + &self, + query: Query, + page: u32, + per_page: u8, + order: Order, + ) -> Result { + perform_with_compat!( + self, + endpoint::block_search::Request::new(query, page, per_page, order) + ) + } + async fn header(&self, height: H) -> Result where H: Into + Send, diff --git a/rpc/src/client/transport/websocket.rs b/rpc/src/client/transport/websocket.rs index 240d9e79f..a52312391 100644 --- a/rpc/src/client/transport/websocket.rs +++ b/rpc/src/client/transport/websocket.rs @@ -234,6 +234,24 @@ impl Client for WebSocketClient { self.perform_with_dialect(request, LatestDialect).await } + async fn block(&self, height: H) -> Result + where + H: Into + Send, + { + perform_with_compat!(self, endpoint::block::Request::new(height.into())) + } + + async fn block_by_hash( + &self, + hash: tendermint::Hash, + ) -> Result { + perform_with_compat!(self, endpoint::block_by_hash::Request::new(hash)) + } + + async fn latest_block(&self) -> Result { + perform_with_compat!(self, endpoint::block::Request::default()) + } + async fn block_results(&self, height: H) -> Result where H: Into + Send, @@ -245,6 +263,19 @@ impl Client for WebSocketClient { perform_with_compat!(self, endpoint::block_results::Request::default()) } + async fn block_search( + &self, + query: Query, + page: u32, + per_page: u8, + order: Order, + ) -> Result { + perform_with_compat!( + self, + endpoint::block_search::Request::new(query, page, per_page, order) + ) + } + async fn header(&self, height: H) -> Result where H: Into + Send, diff --git a/rpc/src/endpoint/block.rs b/rpc/src/endpoint/block.rs index adc4777a0..3a6addbb8 100644 --- a/rpc/src/endpoint/block.rs +++ b/rpc/src/endpoint/block.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use tendermint::block::{self, Block}; -use crate::dialect; +use crate::dialect::{self, Dialect}; use crate::request::RequestMessage; /// Get information about a specific block @@ -34,24 +34,20 @@ impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; -} - impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; -} - impl crate::Request for Request { - type Response = Response; + type Response = self::v0_38::DialectResponse; } -impl crate::SimpleRequest for Request { - type Output = Response; +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ + type Output = >::Response; } /// Block responses @@ -66,7 +62,7 @@ pub struct Response { impl crate::Response for Response {} -pub mod v_038 { +pub mod v0_38 { use std::vec::Vec; use block::{Commit, Header}; diff --git a/rpc/src/endpoint/block_by_hash.rs b/rpc/src/endpoint/block_by_hash.rs index 7a7baf312..067d69efb 100644 --- a/rpc/src/endpoint/block_by_hash.rs +++ b/rpc/src/endpoint/block_by_hash.rs @@ -6,7 +6,7 @@ use tendermint::{ Hash, }; -use crate::dialect; +use crate::dialect::{self, Dialect}; use crate::request::RequestMessage; /// Get information about a specific block by its hash @@ -43,24 +43,20 @@ impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; -} - impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; -} - impl crate::Request for Request { - type Response = Response; + type Response = self::v0_38::DialectResponse; } -impl crate::SimpleRequest for Request { - type Output = Response; +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ + type Output = >::Response; } /// Block responses @@ -75,9 +71,9 @@ pub struct Response { impl crate::Response for Response {} -pub mod v_038 { +pub mod v0_38 { use super::*; - use crate::endpoint::block::v_038::DialectBlock; + use crate::endpoint::block::v0_38::DialectBlock; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct DialectResponse { diff --git a/rpc/src/endpoint/block_results.rs b/rpc/src/endpoint/block_results.rs index 9f40509ad..3ab93abb3 100644 --- a/rpc/src/endpoint/block_results.rs +++ b/rpc/src/endpoint/block_results.rs @@ -49,7 +49,7 @@ where Self: crate::Request, Response: From, { - type Output = Response; + type Output = >::Response; } /// ABCI result response. diff --git a/rpc/src/endpoint/block_search.rs b/rpc/src/endpoint/block_search.rs index 8f854ee03..820e509e5 100644 --- a/rpc/src/endpoint/block_search.rs +++ b/rpc/src/endpoint/block_search.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::dialect; +use crate::dialect::Dialect; use crate::prelude::*; use crate::request::RequestMessage; use crate::serializers; @@ -43,24 +44,20 @@ impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; -} - impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; -} - impl crate::Request for Request { - type Response = Response; + type Response = self::v0_38::DialectResponse; } -impl crate::SimpleRequest for Request { - type Output = Response; +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ + type Output = >::Response; } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -77,7 +74,7 @@ pub mod v0_38 { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct DialectResponse { - pub blocks: Vec, + pub blocks: Vec, #[serde(with = "serializers::from_str")] pub total_count: u32, diff --git a/rpc/src/endpoint/header.rs b/rpc/src/endpoint/header.rs index 730f534f0..8ff3e88dd 100644 --- a/rpc/src/endpoint/header.rs +++ b/rpc/src/endpoint/header.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use tendermint::block::{self, Header}; -use crate::dialect::{v0_37, v0_38}; +use crate::dialect::{v0_37, v0_38, Dialect}; use crate::request::RequestMessage; /// Get information about a specific block @@ -34,16 +34,16 @@ impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; -} - impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ + type Output = >::Response; } /// Header response diff --git a/rpc/src/endpoint/header_by_hash.rs b/rpc/src/endpoint/header_by_hash.rs index 0bdf050fe..6c862175a 100644 --- a/rpc/src/endpoint/header_by_hash.rs +++ b/rpc/src/endpoint/header_by_hash.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use tendermint::{block::Header, Hash}; -use crate::dialect::{v0_37, v0_38}; +use crate::dialect::{v0_37, v0_38, Dialect}; use crate::request::RequestMessage; /// Get information about a specific block by its hash @@ -40,16 +40,16 @@ impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; -} - impl crate::Request for Request { type Response = Response; } -impl crate::SimpleRequest for Request { - type Output = Response; +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ + type Output = >::Response; } /// Header response diff --git a/rpc/src/endpoint/tx.rs b/rpc/src/endpoint/tx.rs index c69bf80d4..081e91e58 100644 --- a/rpc/src/endpoint/tx.rs +++ b/rpc/src/endpoint/tx.rs @@ -50,7 +50,7 @@ where Self: crate::Request, Response: From, { - type Output = Response; + type Output = >::Response; } #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/rpc/src/endpoint/tx_search.rs b/rpc/src/endpoint/tx_search.rs index 6a100528a..eecb89934 100644 --- a/rpc/src/endpoint/tx_search.rs +++ b/rpc/src/endpoint/tx_search.rs @@ -65,7 +65,7 @@ where Self: crate::Request, Response: From, { - type Output = Response; + type Output = >::Response; } #[derive(Clone, Debug, Serialize, Deserialize)]