near_jsonrpc_client/methods/experimental/
protocol_config.rs

1//! Queries the protocol config of the blockchain at a given block.
2//!
3//! The `RpcProtocolConfigRequest` takes in a [`BlockReference`](https://docs.rs/near-primitives/0.12.0/near_primitives/types/enum.BlockReference.html) enum which has multiple variants.
4//!
5//! ## Example
6//!
7//! Returns the protocol config of the blockchain at a given block.
8//!
9//! ```no_run
10//! use near_jsonrpc_client::{methods, JsonRpcClient};
11//! use near_primitives::types::{BlockReference, BlockId};
12//!
13//! # #[tokio::main]
14//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
15//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.fastnear.com");
16//!
17//! let request = methods::EXPERIMENTAL_protocol_config::RpcProtocolConfigRequest {
18//!     block_reference: BlockReference::BlockId(BlockId::Height(100_000_000))
19//! };
20//!
21//! let response = client.call(request).await?;
22//!
23//! assert!(matches!(
24//!     response,
25//!     methods::EXPERIMENTAL_protocol_config::RpcProtocolConfigResponse { .. }
26//! ));
27//! # Ok(())
28//! # }
29//! ```
30use super::*;
31
32pub use near_jsonrpc_primitives::types::config::{
33    RpcProtocolConfigError, RpcProtocolConfigRequest,
34};
35
36pub type RpcProtocolConfigResponse = near_chain_configs::ProtocolConfigView;
37
38impl RpcHandlerResponse for RpcProtocolConfigResponse {}
39
40impl RpcHandlerError for RpcProtocolConfigError {
41    fn parse(value: serde_json::Value) -> Result<Self, serde_json::Error> {
42        common::parse_unknown_block!(value => Self)
43    }
44}
45
46impl RpcMethod for RpcProtocolConfigRequest {
47    type Response = RpcProtocolConfigResponse;
48    type Error = RpcProtocolConfigError;
49
50    fn method_name(&self) -> &str {
51        "EXPERIMENTAL_protocol_config"
52    }
53
54    fn params(&self) -> Result<serde_json::Value, io::Error> {
55        Ok(json!(self))
56    }
57}
58
59impl private::Sealed for RpcProtocolConfigRequest {}