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
//! Queries the protocol config of the blockchain at a given block.
//!
//! The `RpcProtocolConfigRequest` takes in a [`BlockReference`](https://docs.rs/unc-primitives/0.12.0/unc_primitives/types/enum.BlockReference.html) enum which has multiple variants.
//!
//! ## Example
//!
//! Returns the protocol config of the blockchain at a given block.
//!
//! ```no_run
//! use unc_jsonrpc_client::{methods, JsonRpcClient};
//! use unc_primitives::types::{BlockReference, 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::EXPERIMENTAL_protocol_config::RpcProtocolConfigRequest {
//! block_reference: BlockReference::BlockId(BlockId::Height(100_000_000))
//! };
//!
//! let response = client.call(request).await?;
//!
//! assert!(matches!(
//! response,
//! methods::EXPERIMENTAL_protocol_config::RpcProtocolConfigResponse { .. }
//! ));
//! # Ok(())
//! # }
//! ```
use super::*;
pub use unc_jsonrpc_primitives::types::config::{
RpcProtocolConfigError, RpcProtocolConfigRequest,
};
pub type RpcProtocolConfigResponse = unc_chain_configs::ProtocolConfigView;
impl RpcHandlerResponse for RpcProtocolConfigResponse {}
impl RpcHandlerError for RpcProtocolConfigError {
fn parse(value: serde_json::Value) -> Result<Self, serde_json::Error> {
common::parse_unknown_block!(value => Self)
}
}
impl RpcMethod for RpcProtocolConfigRequest {
type Response = RpcProtocolConfigResponse;
type Error = RpcProtocolConfigError;
fn method_name(&self) -> &str {
"EXPERIMENTAL_protocol_config"
}
fn params(&self) -> Result<serde_json::Value, io::Error> {
Ok(json!(self))
}
}
impl private::Sealed for RpcProtocolConfigRequest {}