From ccc53d4bc0e0a975754771f8e62fc299a2aa59f2 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 24 Sep 2024 16:30:02 +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 | 20 +++++++---------- rpc/src/endpoint/block_by_hash.rs | 22 ++++++++----------- rpc/src/endpoint/block_search.rs | 19 +++++++--------- rpc/src/endpoint/header.rs | 12 +++++------ rpc/src/endpoint/header_by_hash.rs | 12 +++++------ 7 files changed, 99 insertions(+), 48 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..f20221380 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,23 +34,19 @@ 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 { +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ type Output = Response; } @@ -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..05786c760 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,23 +43,19 @@ 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 { +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ type Output = Response; } @@ -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_search.rs b/rpc/src/endpoint/block_search.rs index 8f854ee03..6d15117fe 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,23 +44,19 @@ 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 { +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ type Output = Response; } @@ -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..372b3a31e 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,15 +34,15 @@ 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 { +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ type Output = Response; } diff --git a/rpc/src/endpoint/header_by_hash.rs b/rpc/src/endpoint/header_by_hash.rs index 0bdf050fe..21a2bf361 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,15 +40,15 @@ 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 { +impl crate::SimpleRequest for Request +where + Self: crate::Request, + Response: From, +{ type Output = Response; }