Merge bitcoin/bitcoin#32432: wallet, rpc: Use OUTPUT_TYPES to describe the output types instead of hardcoding them

8cc9845b8ddf4f93a02c622e7df8d1095dc1a640 wallet, rpc: Use `OUTPUT_TYPES` to describe the output types instead of hardcoding them (w0xlt)

Pull request description:

  Follow-up to https://github.com/bitcoin/bitcoin/pull/32429, built on top of it.

  This PR addresses the https://github.com/bitcoin/bitcoin/pull/32429#discussion_r2076251627 that the RPC documentation does not use `OUTPUT_TYPES`, but rather hardcodes them, as is already the case for the `getnewaddress` command.
  So here the output types are changed from `std::string` to `std::string_view` so that the values are known at compile time or during the early stages of program startup, before main() execution.

  It also updates `wallet/rpc/addresses.cpp` to write the RPC docs according to `OUTPUT_TYPES` instead of using hardcoded version.

  It also updates the documentation in outputtypes.h, adding Doxygen comments,

ACKs for top commit:
  maflcko:
    lgtm ACK 8cc9845b8ddf4f93a02c622e7df8d1095dc1a640
  achow101:
    ACK 8cc9845b8ddf4f93a02c622e7df8d1095dc1a640

Tree-SHA512: e86d813d6d158dd2f6c62519a7ecaa878f2e4f686b5bae82028a106bd6671a13b10fb366f9bb7b94974777217e1852f38e8aa05bba00cd27f94f4412167a3562
This commit is contained in:
Ava Chow 2025-07-01 13:53:11 -07:00
commit f33154c464
No known key found for this signature in database
GPG Key ID: 17565732E08E5E41
3 changed files with 8 additions and 2 deletions

View File

@ -46,6 +46,11 @@ const std::string& FormatOutputType(OutputType type)
assert(false);
}
std::string FormatAllOutputTypes()
{
return util::Join(OUTPUT_TYPES, ", ", [](const auto& i) { return "\"" + FormatOutputType(i) + "\""; });
}
CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, const CScript& script, OutputType type)
{
// Add script to keystore

View File

@ -31,6 +31,7 @@ static constexpr auto OUTPUT_TYPES = std::array{
std::optional<OutputType> ParseOutputType(const std::string& str);
const std::string& FormatOutputType(OutputType type);
std::string FormatAllOutputTypes();
/**
* Get a destination of the requested type (if possible) to the specified script.

View File

@ -27,7 +27,7 @@ RPCHelpMan getnewaddress()
"so payments received with the address will be associated with 'label'.\n",
{
{"label", RPCArg::Type::STR, RPCArg::Default{""}, "The label name for the address to be linked to. It can also be set to the empty string \"\" to represent the default label. The label does not need to exist, it will be created if there is no label by the given name."},
{"address_type", RPCArg::Type::STR, RPCArg::DefaultHint{"set by -addresstype"}, "The address type to use. Options are \"legacy\", \"p2sh-segwit\", \"bech32\", and \"bech32m\"."},
{"address_type", RPCArg::Type::STR, RPCArg::DefaultHint{"set by -addresstype"}, "The address type to use. Options are " + FormatAllOutputTypes() + "."},
},
RPCResult{
RPCResult::Type::STR, "address", "The new bitcoin address"
@ -219,7 +219,7 @@ RPCHelpMan keypoolrefill()
{
return RPCHelpMan{"keypoolrefill",
"Refills each descriptor keypool in the wallet up to the specified number of new keys.\n"
"By default, descriptor wallets have 4 active ranged descriptors (\"legacy\", \"p2sh-segwit\", \"bech32\", and \"bech32m\"), each with " + util::ToString(DEFAULT_KEYPOOL_SIZE) + " entries.\n" +
"By default, descriptor wallets have 4 active ranged descriptors (" + FormatAllOutputTypes() + "), each with " + util::ToString(DEFAULT_KEYPOOL_SIZE) + " entries.\n" +
HELP_REQUIRING_PASSPHRASE,
{
{"newsize", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%u, or as set by -keypool", DEFAULT_KEYPOOL_SIZE)}, "The new keypool size"},