From d891d3c95cc539da62a7fd98d876cc9eb64820b6 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 21 Feb 2022 13:58:04 +0100 Subject: [PATCH] (partial) Merge bitcoin/bitcoin#24339: rpc: Improve RPC help by explicitly mentioning output types c821ab8be8dffb749853c05e05cb515c11e6328a Use `GetAllOutputTypes` in `getblock` RPC function (Kiminuo) d970a85d335202cc85f6604f794c43af6645673f 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 https://github.com/bitcoin/bitcoin/pull/23320#discussion_r732458112 (resolved). ACKs for top commit: kristapsk: re-ACK c821ab8be8dffb749853c05e05cb515c11e6328a Tree-SHA512: 5ff66a41ad7c43ec769f4a99933d2d070feea7c617286d94b6f9bfa1a2547a42211915778210a89074ad4b14d99f34852cc6871efed5e6f1e2ffedd40d669386 --- src/rpc/rawtransaction.cpp | 10 ---------- src/rpc/util.cpp | 10 ++++++++++ src/rpc/util.h | 7 +++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index d3c37f7345..6c1a433dc0 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -867,16 +867,6 @@ static RPCHelpMan decoderawtransaction() }; } -static std::string GetAllOutputTypes() -{ - std::vector ret; - using U = std::underlying_type::type; - for (U i = (U)TxoutType::NONSTANDARD; i <= (U)TxoutType::NULL_DATA; ++i) { - ret.emplace_back(GetTxnOutputType(static_cast(i))); - } - return Join(ret, ", "); -} - static RPCHelpMan decodescript() { return RPCHelpMan{"decodescript", diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 3b02da632f..29d48cac63 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -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 ret; + using U = std::underlying_type::type; + for (U i = (U)TxoutType::NONSTANDARD; i <= (U)TxoutType::NULL_DATA; ++i) { + ret.emplace_back(GetTxnOutputType(static_cast(i))); + } + return Join(ret, ", "); +} + void RPCTypeCheck(const UniValue& params, const std::list& typesExpected, bool fAllowNull) diff --git a/src/rpc/util.h b/src/rpc/util.h index 189551cd03..b373a044fb 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -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 {