1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Returns the next light client block.
//!
//! ## Example
//!
//! ```
//! use unc_jsonrpc_client::{methods, JsonRpcClient};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.unc.org");
//!
//! let request = methods::next_light_client_block::RpcLightClientNextBlockRequest {
//!     last_block_hash: "ANm3jm5wq1Z4rJv6tXWyiDtC3wYKpXVHY4iq6bE1te7B".parse()?,
//! };
//!
//! let response = client.call(request).await?;
//!
//! assert!(matches!(
//!     response,
//!     Some(methods::next_light_client_block::LightClientBlockView { .. })
//! ));
//! # Ok(())
//! # }
//! ```
use super::*;

pub use unc_jsonrpc_primitives::types::light_client::{
    RpcLightClientNextBlockError, RpcLightClientNextBlockRequest,
};
pub use unc_primitives::views::LightClientBlockView;

pub type RpcLightClientNextBlockResponse = Option<LightClientBlockView>;

impl RpcHandlerResponse for RpcLightClientNextBlockResponse {}

impl RpcHandlerError for RpcLightClientNextBlockError {
    fn parse(value: serde_json::Value) -> Result<Self, serde_json::Error> {
        common::parse_unknown_block!(value => Self)
    }
}

impl RpcMethod for RpcLightClientNextBlockRequest {
    type Response = RpcLightClientNextBlockResponse;
    type Error = RpcLightClientNextBlockError;

    fn method_name(&self) -> &str {
        "next_light_client_block"
    }

    fn params(&self) -> Result<serde_json::Value, io::Error> {
        Ok(json!(self))
    }
}

impl private::Sealed for RpcLightClientNextBlockRequest {}