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 78 79 80 81 82
//! Returns the gas price for a specific block height or block hash.
//!
//! ## Examples
//!
//! Returns the gas fees for this block:
//! <https://explorer.unc.org/blocks/6atGq4TUTZerVHU9qWoYfzXNBg3K4C4cca15TE6KfuBr>
//!
//! - `BlockId::Height`
//!
//! ```
//! # use unc_jsonrpc_client::{methods, JsonRpcClient};
//! use unc_primitives::types::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::gas_price::RpcGasPriceRequest {
//! block_id: Some(BlockId::Height(61512623)),
//! };
//!
//! let response = client.call(request).await?;
//!
//! assert!(matches!(
//! response,
//! methods::gas_price::RpcGasPriceResponse { .. }
//! ));
//! # Ok(())
//! # }
//! ```
//!
//! - `BlockId::Hash`
//!
//! ```
//! # use unc_jsonrpc_client::{methods, JsonRpcClient};
//! use unc_primitives::types::BlockId;
//!
//! # #[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::gas_price::RpcGasPriceRequest {
//! block_id: Some(BlockId::Hash("6atGq4TUTZerVHU9qWoYfzXNBg3K4C4cca15TE6KfuBr".parse()?)),
//! };
//!
//! let response = client.call(request).await?;
//!
//! assert!(matches!(
//! response,
//! methods::gas_price::RpcGasPriceResponse { .. }
//! ));
//! # Ok(())
//! # }
//! ```
use super::*;
pub use unc_jsonrpc_primitives::types::gas_price::{RpcGasPriceError, RpcGasPriceRequest};
pub type RpcGasPriceResponse = unc_primitives::views::GasPriceView;
impl RpcHandlerResponse for RpcGasPriceResponse {}
impl RpcHandlerError for RpcGasPriceError {
fn parse(value: serde_json::Value) -> Result<Self, serde_json::Error> {
common::parse_unknown_block!(value => Self)
}
}
impl RpcMethod for RpcGasPriceRequest {
type Response = RpcGasPriceResponse;
type Error = RpcGasPriceError;
fn method_name(&self) -> &str {
"gas_price"
}
fn params(&self) -> Result<serde_json::Value, io::Error> {
Ok(json!([self.block_id]))
}
}
impl private::Sealed for RpcGasPriceRequest {}