zebra_rpc/methods/types/
get_mining_info.rs

1//! Response type for the `getmininginfo` RPC.
2
3use derive_getters::Getters;
4use derive_new::new;
5use zebra_chain::parameters::Network;
6
7/// Response to a `getmininginfo` RPC request.
8#[derive(
9    Debug, Default, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, Getters, new,
10)]
11pub struct GetMiningInfoResponse {
12    /// The current tip height.
13    #[serde(rename = "blocks")]
14    tip_height: u32,
15
16    /// The size of the last mined block if any.
17    #[serde(rename = "currentblocksize", skip_serializing_if = "Option::is_none")]
18    #[getter(copy)]
19    current_block_size: Option<usize>,
20
21    /// The number of transactions in the last mined block if any.
22    #[serde(rename = "currentblocktx", skip_serializing_if = "Option::is_none")]
23    #[getter(copy)]
24    current_block_tx: Option<usize>,
25
26    /// The estimated network solution rate in Sol/s.
27    networksolps: u64,
28
29    /// The estimated network solution rate in Sol/s.
30    networkhashps: u64,
31
32    /// Current network name as defined in BIP70 (main, test, regtest)
33    chain: String,
34
35    /// If using testnet or not
36    testnet: bool,
37}
38
39impl GetMiningInfoResponse {
40    /// Creates a new `getmininginfo` response
41    pub(crate) fn new_internal(
42        tip_height: u32,
43        current_block_size: Option<usize>,
44        current_block_tx: Option<usize>,
45        network: Network,
46        networksolps: u64,
47    ) -> Self {
48        Self {
49            tip_height,
50            current_block_size,
51            current_block_tx,
52            networksolps,
53            networkhashps: networksolps,
54            chain: network.bip70_network_name(),
55            testnet: network.is_a_test_network(),
56        }
57    }
58}