From df8901eaee27a61c1b3e11879fa9c1d638658e85 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 24 Sep 2024 16:20:47 +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 | 4 ++-- rpc/src/endpoint/block_by_hash.rs | 2 +- rpc/src/endpoint/block_search.rs | 2 +- 5 files changed, 66 insertions(+), 4 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..ba6909708 100644 --- a/rpc/src/endpoint/block.rs +++ b/rpc/src/endpoint/block.rs @@ -47,7 +47,7 @@ impl crate::SimpleRequest for Request { } impl crate::Request for Request { - type Response = Response; + type Response = self::v0_38::DialectResponse; } impl crate::SimpleRequest for Request { @@ -66,7 +66,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..d62f87a9d 100644 --- a/rpc/src/endpoint/block_by_hash.rs +++ b/rpc/src/endpoint/block_by_hash.rs @@ -77,7 +77,7 @@ impl crate::Response for Response {} pub mod v_038 { 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_search.rs b/rpc/src/endpoint/block_search.rs index 8f854ee03..dd8ffcedf 100644 --- a/rpc/src/endpoint/block_search.rs +++ b/rpc/src/endpoint/block_search.rs @@ -77,7 +77,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,