zebra_rpc/methods/types/
get_mining_info.rs

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