Skip to content

Commit 1337b93

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24339: rpc: Improve RPC help by explicitly mentioning output 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/bitcoin#23320 (comment) (resolved). ACKs for top commit: kristapsk: re-ACK c821ab8 Tree-SHA512: 5ff66a41ad7c43ec769f4a99933d2d070feea7c617286d94b6f9bfa1a2547a42211915778210a89074ad4b14d99f34852cc6871efed5e6f1e2ffedd40d669386
2 parents 85ae549 + c821ab8 commit 1337b93

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ static RPCHelpMan getblock()
10371037
{RPCResult::Type::STR, "asm", "The asm"},
10381038
{RPCResult::Type::STR, "hex", "The hex"},
10391039
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
1040-
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
1040+
{RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"},
10411041
}},
10421042
}},
10431043
}},

src/rpc/rawtransaction.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,6 @@ static RPCHelpMan decoderawtransaction()
542542
};
543543
}
544544

545-
static std::string GetAllOutputTypes()
546-
{
547-
std::vector<std::string> ret;
548-
using U = std::underlying_type<TxoutType>::type;
549-
for (U i = (U)TxoutType::NONSTANDARD; i <= (U)TxoutType::WITNESS_UNKNOWN; ++i) {
550-
ret.emplace_back(GetTxnOutputType(static_cast<TxoutType>(i)));
551-
}
552-
return Join(ret, ", ");
553-
}
554-
555545
static RPCHelpMan decodescript()
556546
{
557547
return RPCHelpMan{

src/rpc/util.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
2222
const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"};
2323

24+
std::string GetAllOutputTypes()
25+
{
26+
std::vector<std::string> ret;
27+
using U = std::underlying_type<TxoutType>::type;
28+
for (U i = (U)TxoutType::NONSTANDARD; i <= (U)TxoutType::WITNESS_UNKNOWN; ++i) {
29+
ret.emplace_back(GetTxnOutputType(static_cast<TxoutType>(i)));
30+
}
31+
return Join(ret, ", ");
32+
}
33+
2434
void RPCTypeCheck(const UniValue& params,
2535
const std::list<UniValueType>& typesExpected,
2636
bool fAllowNull)

src/rpc/util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ class CPubKey;
3939
class CScript;
4040
struct Sections;
4141

42+
/**
43+
* Gets all existing output types formatted for RPC help sections.
44+
*
45+
* @return Comma separated string representing output type names.
46+
*/
47+
std::string GetAllOutputTypes();
48+
4249
/** Wrapper for UniValue::VType, which includes typeAny:
4350
* Used to denote don't care type. */
4451
struct UniValueType {

0 commit comments

Comments
 (0)