Skip to content

Commit

Permalink
Fix block-related queries to use compat mode
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Sep 24, 2024
1 parent c190d2a commit f81ae58
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 56 deletions.
31 changes: 31 additions & 0 deletions rpc/src/client/transport/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,24 @@ impl Client for HttpClient {
self.perform_with_dialect(request, LatestDialect).await
}

async fn block<H>(&self, height: H) -> Result<endpoint::block::Response, Error>
where
H: Into<Height> + Send,
{
perform_with_compat!(self, endpoint::block::Request::new(height.into()))
}

async fn block_by_hash(
&self,
hash: tendermint::Hash,
) -> Result<endpoint::block_by_hash::Response, Error> {
perform_with_compat!(self, endpoint::block_by_hash::Request::new(hash))
}

async fn latest_block(&self) -> Result<endpoint::block::Response, Error> {
perform_with_compat!(self, endpoint::block::Request::default())
}

async fn block_results<H>(&self, height: H) -> Result<endpoint::block_results::Response, Error>
where
H: Into<Height> + Send,
Expand All @@ -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<endpoint::block_search::Response, Error> {
perform_with_compat!(
self,
endpoint::block_search::Request::new(query, page, per_page, order)
)
}

async fn header<H>(&self, height: H) -> Result<endpoint::header::Response, Error>
where
H: Into<Height> + Send,
Expand Down
31 changes: 31 additions & 0 deletions rpc/src/client/transport/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,24 @@ impl Client for WebSocketClient {
self.perform_with_dialect(request, LatestDialect).await
}

async fn block<H>(&self, height: H) -> Result<endpoint::block::Response, Error>
where
H: Into<Height> + Send,
{
perform_with_compat!(self, endpoint::block::Request::new(height.into()))
}

async fn block_by_hash(
&self,
hash: tendermint::Hash,
) -> Result<endpoint::block_by_hash::Response, Error> {
perform_with_compat!(self, endpoint::block_by_hash::Request::new(hash))
}

async fn latest_block(&self) -> Result<endpoint::block::Response, Error> {
perform_with_compat!(self, endpoint::block::Request::default())
}

async fn block_results<H>(&self, height: H) -> Result<endpoint::block_results::Response, Error>
where
H: Into<Height> + Send,
Expand All @@ -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<endpoint::block_search::Response, Error> {
perform_with_compat!(
self,
endpoint::block_search::Request::new(query, page, per_page, order)
)
}

async fn header<H>(&self, height: H) -> Result<endpoint::header::Response, Error>
where
H: Into<Height> + Send,
Expand Down
22 changes: 9 additions & 13 deletions rpc/src/endpoint/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,24 +34,20 @@ impl crate::Request<dialect::v0_34::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<dialect::v0_34::Dialect> for Request {
type Output = Response;
}

impl crate::Request<dialect::v0_37::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<dialect::v0_37::Dialect> for Request {
type Output = Response;
}

impl crate::Request<dialect::v0_38::Dialect> for Request {
type Response = Response;
type Response = self::v0_38::DialectResponse;
}

impl crate::SimpleRequest<dialect::v0_38::Dialect> for Request {
type Output = Response;
impl<S: Dialect> crate::SimpleRequest<S> for Request
where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = <Self as crate::Request<S>>::Response;
}

/// Block responses
Expand All @@ -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};
Expand Down
24 changes: 10 additions & 14 deletions rpc/src/endpoint/block_by_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,24 +43,20 @@ impl crate::Request<dialect::v0_34::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<dialect::v0_34::Dialect> for Request {
type Output = Response;
}

impl crate::Request<dialect::v0_37::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<dialect::v0_37::Dialect> for Request {
type Output = Response;
}

impl crate::Request<dialect::v0_38::Dialect> for Request {
type Response = Response;
type Response = self::v0_38::DialectResponse;
}

impl crate::SimpleRequest<dialect::v0_38::Dialect> for Request {
type Output = Response;
impl<S: Dialect> crate::SimpleRequest<S> for Request
where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = <Self as crate::Request<S>>::Response;
}

/// Block responses
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/endpoint/block_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = Response;
type Output = <Self as crate::Request<S>>::Response;
}

/// ABCI result response.
Expand Down
21 changes: 9 additions & 12 deletions rpc/src/endpoint/block_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,24 +44,20 @@ impl crate::Request<dialect::v0_34::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<dialect::v0_34::Dialect> for Request {
type Output = Response;
}

impl crate::Request<dialect::v0_37::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<dialect::v0_37::Dialect> for Request {
type Output = Response;
}

impl crate::Request<dialect::v0_38::Dialect> for Request {
type Response = Response;
type Response = self::v0_38::DialectResponse;
}

impl crate::SimpleRequest<dialect::v0_38::Dialect> for Request {
type Output = Response;
impl<S: Dialect> crate::SimpleRequest<S> for Request
where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = <Self as crate::Request<S>>::Response;
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand All @@ -77,7 +74,7 @@ pub mod v0_38 {

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DialectResponse {
pub blocks: Vec<block::v_038::DialectResponse>,
pub blocks: Vec<block::v0_38::DialectResponse>,

#[serde(with = "serializers::from_str")]
pub total_count: u32,
Expand Down
14 changes: 7 additions & 7 deletions rpc/src/endpoint/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,16 +34,16 @@ impl crate::Request<v0_37::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<v0_37::Dialect> for Request {
type Output = Response;
}

impl crate::Request<v0_38::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<v0_38::Dialect> for Request {
type Output = Response;
impl<S: Dialect> crate::SimpleRequest<S> for Request
where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = <Self as crate::Request<S>>::Response;
}

/// Header response
Expand Down
14 changes: 7 additions & 7 deletions rpc/src/endpoint/header_by_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,16 +40,16 @@ impl crate::Request<v0_37::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<v0_37::Dialect> for Request {
type Output = Response;
}

impl crate::Request<v0_38::Dialect> for Request {
type Response = Response;
}

impl crate::SimpleRequest<v0_38::Dialect> for Request {
type Output = Response;
impl<S: Dialect> crate::SimpleRequest<S> for Request
where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = <Self as crate::Request<S>>::Response;
}

/// Header response
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/endpoint/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = Response;
type Output = <Self as crate::Request<S>>::Response;
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/endpoint/tx_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = Response;
type Output = <Self as crate::Request<S>>::Response;
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down

0 comments on commit f81ae58

Please sign in to comment.