diff options
author | Ava Chow <github@achow101.com> | 2024-08-14 12:01:55 -0400 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-08-14 12:01:55 -0400 |
commit | 0e42c1b6c5888d33b6fbefefd2aabd84929df384 (patch) | |
tree | 8cda4126f0791bb090b8de3b087b010409cd1e3f | |
parent | 9264d62bd9e3d9bde0eea973393633d8b75e51a0 (diff) | |
parent | 9b297555207b4ea54bc0051f09c7084797aa9def (diff) |
Merge bitcoin/bitcoin#30648: doc: Deduplicate list of possible chain strings in RPC help texts
9b297555207b4ea54bc0051f09c7084797aa9def Deduplicate list of chain strings in RPC help texts (Martin Saposnic)
Pull request description:
As mentioned in issue https://github.com/bitcoin/bitcoin/issues/30645:
Many command line parameter and RPC help texts currently contain the list of chain/network names hardcoded ("main, test, testnet4, signet, regtest"), which is error-prone as it can easily happen to miss an instance if the list ever changes again.
This PR deduplicates the list of possible chain/network strings in RPC/parameter help texts, and it creates a macro `LIST_CHAIN_NAMES` in src/chainparamsbase.h. In the future, there is only 1 place where that list of possible values lives, so maintainability is improved and errors are avoided.
All three places where this change impacts:
```
./bitcoin-cli --help
./bitcoin-cli help getblockchaininfo
./bitcoin-cli help getmininginfo
```
They all return the correct string `"main, test, testnet4, signet, regtest"`
See https://github.com/bitcoin/bitcoin/pull/30642#discussion_r1714711575
ACKs for top commit:
maflcko:
lgtm ACK 9b297555207b4ea54bc0051f09c7084797aa9def
achow101:
ACK 9b297555207b4ea54bc0051f09c7084797aa9def
MarnixCroes:
ACK 9b297555207b4ea54bc0051f09c7084797aa9def
theStack:
ACK 9b297555207b4ea54bc0051f09c7084797aa9def
danielabrozzoni:
ACK 9b297555207b4ea54bc0051f09c7084797aa9def
Tree-SHA512: 1e961bcbe40b0f17a87a2437eb4ba1bb89468fd1b5a39599d72a00ef75cb4009e7d2f05d0a621bb904fecf681c55b8a219fcfe4d44d5d27f27cdda20882b1323
-rw-r--r-- | src/chainparamsbase.cpp | 2 | ||||
-rw-r--r-- | src/chainparamsbase.h | 3 | ||||
-rw-r--r-- | src/rpc/blockchain.cpp | 3 | ||||
-rw-r--r-- | src/rpc/mining.cpp | 3 |
4 files changed, 8 insertions, 3 deletions
diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 26d877fd93..aadd04e509 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -13,7 +13,7 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman) { - argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, testnet4, signet, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); + argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: " LIST_CHAIN_NAMES, ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. " "This is intended for regression testing tools and app development. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-testactivationheight=name@height.", "Set the activation height of 'name' (segwit, bip34, dersig, cltv, csv). (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h index 72807501d9..c75a70cb96 100644 --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -53,4 +53,7 @@ const CBaseChainParams& BaseParams(); /** Sets the params returned by Params() to those for the given chain. */ void SelectBaseParams(const ChainType chain); +/** List of possible chain / network names */ +#define LIST_CHAIN_NAMES "main, test, testnet4, signet, regtest" + #endif // BITCOIN_CHAINPARAMSBASE_H diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index d7284ae018..b449444aff 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -8,6 +8,7 @@ #include <blockfilter.h> #include <chain.h> #include <chainparams.h> +#include <chainparamsbase.h> #include <clientversion.h> #include <coins.h> #include <common/args.h> @@ -1273,7 +1274,7 @@ RPCHelpMan getblockchaininfo() RPCResult{ RPCResult::Type::OBJ, "", "", { - {RPCResult::Type::STR, "chain", "current network name (main, test, testnet4, signet, regtest)"}, + {RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"}, {RPCResult::Type::NUM, "blocks", "the height of the most-work fully-validated chain. The genesis block has height 0"}, {RPCResult::Type::NUM, "headers", "the current number of headers we have validated"}, {RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"}, diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 37a22bcf10..3c41e136ec 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -7,6 +7,7 @@ #include <chain.h> #include <chainparams.h> +#include <chainparamsbase.h> #include <common/system.h> #include <consensus/amount.h> #include <consensus/consensus.h> @@ -422,7 +423,7 @@ static RPCHelpMan getmininginfo() {RPCResult::Type::NUM, "difficulty", "The current difficulty"}, {RPCResult::Type::NUM, "networkhashps", "The network hashes per second"}, {RPCResult::Type::NUM, "pooledtx", "The size of the mempool"}, - {RPCResult::Type::STR, "chain", "current network name (main, test, testnet4, signet, regtest)"}, + {RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"}, (IsDeprecatedRPCEnabled("warnings") ? RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} : RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)", |