From 39b195f86e24c2e3f1971aac67b7485346073f5f Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 19 Jun 2023 09:49:08 +1000 Subject: [PATCH] Make RPC testnet flag forward-compatible with additional testnets --- zebra-chain/src/parameters/network.rs | 7 ++++++- .../get_block_template_rpcs/types/get_mining_info.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/zebra-chain/src/parameters/network.rs b/zebra-chain/src/parameters/network.rs index 6ec34384e10..05f0a587738 100644 --- a/zebra-chain/src/parameters/network.rs +++ b/zebra-chain/src/parameters/network.rs @@ -59,7 +59,7 @@ pub enum Network { #[default] Mainnet, - /// The testnet. + /// The oldest public test network. Testnet, } @@ -124,6 +124,11 @@ impl Network { pub fn lowercase_name(&self) -> String { self.to_string().to_ascii_lowercase() } + + /// Returns `true` if this network is a testing network. + pub fn is_a_test_network(&self) -> bool { + *self != Network::Mainnet + } } impl FromStr for Network { diff --git a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs index 3ac548596cb..3da55de3fa7 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs @@ -25,7 +25,7 @@ impl Response { networksolps, networkhashps: networksolps, chain: network.bip70_network_name(), - testnet: network == Network::Testnet, + testnet: network.is_a_test_network(), } } }