cometbft_rpc/endpoint/
blockchain.rs

1//! `/block` endpoint JSON-RPC wrapper
2
3use core::ops::Range;
4
5use cometbft::block;
6use serde::{Deserialize, Serialize};
7
8use crate::prelude::*;
9use crate::{dialect::Dialect, request::RequestMessage};
10
11/// Get information about a specific block
12#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
13pub struct Request {
14    /// First block in the sequence to request info about
15    #[serde(rename = "minHeight")]
16    pub min_height: block::Height,
17
18    /// Last block in the sequence to request info about
19    #[serde(rename = "maxHeight")]
20    pub max_height: block::Height,
21}
22
23impl Request {
24    /// Request information about a sequence of blocks
25    pub fn new(min_height: block::Height, max_height: block::Height) -> Self {
26        Self {
27            min_height,
28            max_height,
29        }
30    }
31}
32
33impl From<Range<block::Height>> for Request {
34    fn from(range: Range<block::Height>) -> Request {
35        Request::new(range.start, range.end)
36    }
37}
38
39impl RequestMessage for Request {
40    fn method(&self) -> crate::Method {
41        crate::Method::Blockchain
42    }
43}
44
45impl<S: Dialect> crate::Request<S> for Request {
46    type Response = Response;
47}
48
49impl<S: Dialect> crate::SimpleRequest<S> for Request {
50    type Output = Response;
51}
52
53/// Block responses
54#[derive(Clone, Debug, Deserialize, Serialize)]
55pub struct Response {
56    /// Last block height for this particular chain
57    pub last_height: block::Height,
58
59    /// Block metadata
60    pub block_metas: Vec<block::Meta>,
61}
62
63impl crate::Response for Response {}