Skip to content

Commit

Permalink
Updates chain field of getmininginfo response
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Dec 8, 2022
1 parent 814ce64 commit a115632
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
use zebra_chain::parameters::Network;

/// `chain` field of [`Response`] as defined in BIP70
#[derive(Debug, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "lowercase")]
pub enum ChainNetworkResponse {
/// Corresponds to Mainnet
Main,

/// Corresponds to Testnet
Test,
}

impl From<Network> for ChainNetworkResponse {
fn from(network: Network) -> Self {
match network {
Network::Mainnet => Self::Main,
Network::Testnet => Self::Test,
}
}
}

/// Response to a `getmininginfo` RPC request.
#[derive(Debug, PartialEq, Eq, serde::Serialize)]
pub struct Response {
Expand All @@ -12,20 +32,20 @@ pub struct Response {
networkhashps: u128,

/// Current network name as defined in BIP70 (main, test, regtest)
chain: Network,
chain: ChainNetworkResponse,

/// If using testnet or not
testnet: bool,
}

impl Response {
/// Creates a new `getmininginfo` response
pub fn new(chain: Network, networksolps: u128) -> Self {
pub fn new(network: Network, networksolps: u128) -> Self {
Self {
networksolps,
networkhashps: networksolps,
chain,
testnet: chain == Network::Testnet,
chain: network.into(),
testnet: network == Network::Testnet,
}
}
}

0 comments on commit a115632

Please sign in to comment.