near_jsonrpc_client/methods/
next_light_client_block.rs

1//! Returns the next light client block.
2//!
3//! ## Example
4//!
5//! ```
6//! use near_jsonrpc_client::{methods, JsonRpcClient};
7//!
8//! # #[tokio::main]
9//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
10//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.fastnear.com");
11//!
12//! let request = methods::next_light_client_block::RpcLightClientNextBlockRequest {
13//!     last_block_hash: "ANm3jm5wq1Z4rJv6tXWyiDtC3wYKpXVHY4iq6bE1te7B".parse()?,
14//! };
15//!
16//! let response = client.call(request).await?;
17//!
18//! assert!(matches!(
19//!     response,
20//!     Some(methods::next_light_client_block::LightClientBlockView { .. })
21//! ));
22//! # Ok(())
23//! # }
24//! ```
25use super::*;
26
27pub use near_jsonrpc_primitives::types::light_client::{
28    RpcLightClientNextBlockError, RpcLightClientNextBlockRequest,
29};
30pub use near_primitives::views::LightClientBlockView;
31
32pub type RpcLightClientNextBlockResponse = Option<LightClientBlockView>;
33
34impl RpcHandlerResponse for RpcLightClientNextBlockResponse {}
35
36impl RpcHandlerError for RpcLightClientNextBlockError {
37    fn parse(value: serde_json::Value) -> Result<Self, serde_json::Error> {
38        common::parse_unknown_block!(value => Self)
39    }
40}
41
42impl RpcMethod for RpcLightClientNextBlockRequest {
43    type Response = RpcLightClientNextBlockResponse;
44    type Error = RpcLightClientNextBlockError;
45
46    fn method_name(&self) -> &str {
47        "next_light_client_block"
48    }
49
50    fn params(&self) -> Result<serde_json::Value, io::Error> {
51        Ok(json!(self))
52    }
53}
54
55impl private::Sealed for RpcLightClientNextBlockRequest {}