Skip to content

Commit

Permalink
Add /genesis_chunked query
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 committed Jun 26, 2024
1 parent ed576f2 commit 9159cf2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ pub trait Client {
Ok(self.perform(genesis::Request::default()).await?.genesis)
}

/// `/genesis_chunked`: get genesis file in multiple chunks.
async fn genesis_chunked(
&self,
chunk: Option<String>,
) -> Result<genesis_chunked::Response, Error> {
self.perform(genesis_chunked::Request::new(chunk)).await
}

/// `/net_info`: obtain information about P2P and other network connections.
async fn net_info(&self) -> Result<net_info::Response, Error> {
self.perform(net_info::Request).await
Expand Down
1 change: 1 addition & 0 deletions rpc/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod consensus_params;
pub mod consensus_state;
pub mod evidence;
pub mod genesis;
pub mod genesis_chunked;
pub mod header;
pub mod header_by_hash;
pub mod health;
Expand Down
52 changes: 52 additions & 0 deletions rpc/src/endpoint/genesis_chunked.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//! `/genesis` endpoint JSON-RPC wrapper

use alloc::{string::String, vec::Vec};
use serde::{Deserialize, Serialize};
use tendermint_proto::serializers;

use crate::{dialect::Dialect, request::RequestMessage};

/// Get the genesis state in multiple chunks for the current chain
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
pub chunk: Option<String>,
}

impl Request {
pub fn new(chunk: Option<String>) -> Self {
Self { chunk }
}
}

impl RequestMessage for Request {
fn method(&self) -> crate::Method {
crate::Method::GenesisChunked
}
}

impl<S> crate::Request<S> for Request
where
S: Dialect,
{
type Response = Response;
}

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

/// Block responses
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
#[serde(with = "serializers::from_str")]
pub chunk: u64,
#[serde(with = "serializers::from_str")]
pub total: u64,
#[serde(with = "serializers::bytes::base64string")]
pub data: Vec<u8>,
}

impl crate::Response for Response {}
4 changes: 4 additions & 0 deletions rpc/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub enum Method {
/// Get genesis file
Genesis,

/// Get genesis in multiple chunks file
GenesisChunked,

/// Get block header
Header,

Expand Down Expand Up @@ -109,6 +112,7 @@ impl Method {
Method::ConsensusParams => "consensus_params",
Method::ConsensusState => "consensus_state",
Method::Genesis => "genesis",
Method::GenesisChunked => "genesis_chunked",
Method::Header => "header",
Method::HeaderByHash => "header_by_hash",
Method::Health => "health",
Expand Down

0 comments on commit 9159cf2

Please sign in to comment.