Skip to content

Commit

Permalink
Merge bitcoin#24339: rpc: Improve RPC help by explicitly mentioning o…
Browse files Browse the repository at this point in the history
…utput types

c821ab8 Use `GetAllOutputTypes` in `getblock` RPC function (Kiminuo)
d970a85 Move `GetAllOutputTypes` function from `rpc/rawtransaction.cpp` to `rpc/util.{h|cpp}` (Kiminuo)

Pull request description:

  This PR attempts to replicate https://github.com/bitcoin/bitcoin/blob/0ccf9b2e5594581deef2f60174c3651a57f93b64/src/rpc/rawtransaction.cpp#L547 to one other place (at the moment) so that users have better idea what RPC methods can actually return.

  I created this PR as a follow-up to the idea mentioned here bitcoin#23320 (comment) (resolved).

ACKs for top commit:
  kristapsk:
    re-ACK c821ab8

Tree-SHA512: 5ff66a41ad7c43ec769f4a99933d2d070feea7c617286d94b6f9bfa1a2547a42211915778210a89074ad4b14d99f34852cc6871efed5e6f1e2ffedd40d669386
  • Loading branch information
MarcoFalke authored and vijaydasmp committed Sep 8, 2024
1 parent 4cbbd8e commit 3c32e42
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,16 +867,6 @@ static RPCHelpMan decoderawtransaction()
};
}

static std::string GetAllOutputTypes()
{
std::vector<std::string> ret;
using U = std::underlying_type<TxoutType>::type;
for (U i = (U)TxoutType::NONSTANDARD; i <= (U)TxoutType::NULL_DATA; ++i) {
ret.emplace_back(GetTxnOutputType(static_cast<TxoutType>(i)));
}
return Join(ret, ", ");
}

static RPCHelpMan decodescript()
{
return RPCHelpMan{"decodescript",
Expand Down
10 changes: 10 additions & 0 deletions src/rpc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
const std::string EXAMPLE_ADDRESS[2] = {"XunLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPw0", "XwQQkwA4FYkq2XERzMY2CiAZhJTEDAbtc0"};

std::string GetAllOutputTypes()
{
std::vector<std::string> ret;
using U = std::underlying_type<TxoutType>::type;
for (U i = (U)TxoutType::NONSTANDARD; i <= (U)TxoutType::NULL_DATA; ++i) {
ret.emplace_back(GetTxnOutputType(static_cast<TxoutType>(i)));
}
return Join(ret, ", ");
}

void RPCTypeCheck(const UniValue& params,
const std::list<UniValueType>& typesExpected,
bool fAllowNull)
Expand Down
7 changes: 7 additions & 0 deletions src/rpc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class CPubKey;
class CScript;
struct Sections;

/**
* Gets all existing output types formatted for RPC help sections.
*
* @return Comma separated string representing output type names.
*/
std::string GetAllOutputTypes();

/** Wrapper for UniValue::VType, which includes typeAny:
* Used to denote don't care type. */
struct UniValueType {
Expand Down

0 comments on commit 3c32e42

Please sign in to comment.