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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Queries active validators on the network.
//!
//! Returns details and the state of validation on the blockchain.
//!
//! ## Examples
//!
//! - Get the validators for a specified epoch.
//!
//!   ```
//!   use unc_jsonrpc_client::{methods, JsonRpcClient};
//!   use unc_primitives::types::{EpochReference, EpochId, BlockReference, Finality};
//!
//!   # #[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::validators::RpcValidatorRequest {
//!       epoch_reference: EpochReference::EpochId(
//!           "9xrjdZmgjoVkjVE3ui7tY37x9Mkw5wH385qNXE6cho7T".parse()?,
//!       )
//!   };
//!
//!   let response = client.call(request).await?;
//!
//!   assert!(matches!(
//!       response,
//!       methods::validators::RpcValidatorResponse { .. }
//!   ));
//!   # Ok(())
//!   # }
//!   ```
//!
//! - Get the validators for the latest block.
//!
//!   ```
//!   use unc_jsonrpc_client::{methods, JsonRpcClient};
//!   use unc_primitives::types::{EpochReference, EpochId, BlockId};
//!
//!   # #[tokio::main]
//!   # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!   let client = JsonRpcClient::connect("https://archival-rpc.mainnet.unc.org");
//!
//!   let request = methods::validators::RpcValidatorRequest {
//!       epoch_reference: EpochReference::Latest
//!   };
//!
//!   let response = client.call(request).await?;
//!
//!   assert!(matches!(
//!       response,
//!       methods::validators::RpcValidatorResponse { .. }
//!   ));
//!   # Ok(())
//!   # }
//!   ```
use super::*;

pub use unc_jsonrpc_primitives::types::validator::{RpcValidatorError, RpcValidatorRequest};

pub type RpcValidatorResponse = unc_primitives::views::EpochValidatorInfo;

impl RpcHandlerResponse for RpcValidatorResponse {}

impl RpcMethod for RpcValidatorRequest {
    type Response = RpcValidatorResponse;
    type Error = RpcValidatorError;

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

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

impl private::Sealed for RpcValidatorRequest {}