Skip to content

Commit d692d19

Browse files
author
MarcoFalke
committed
Merge #19849: Assert that RPCArg names are equal to CRPCCommand ones (blockchain,rawtransaction)
fa6bb0c Assert that RPCArg names are equal to CRPCCommand ones (rawtransaction) (MarcoFalke) fa80c81 Assert that RPCArg names are equal to CRPCCommand ones (blockchain) (MarcoFalke) Pull request description: This is split out from #18531 to just touch some RPC methods. Description from the main pr: ### Motivation RPCArg names in the rpc help are currently only used for documentation. However, in the future they could be used to teach the server the named arguments. Named arguments are currently registered by the `CRPCCommand`s and duplicate the RPCArg names from the documentation. This redundancy is fragile, and has lead to errors in the past (despite having linters to catch those kind of errors). See section "bugs found" for a list of bugs that have been found as a result of the changes here. ### Changes The changes here add an assert in the `CRPCCommand` constructor that the RPCArg names are identical to the ones in the `CRPCCommand`. ### Future work > Here or follow up, makes sense to also assert type of returned UniValue? Sure, but let's not get ahead of ourselves. I am going to submit any further works as follow-ups, including: * Removing the CRPCCommand arguments, now that they are asserted to be equal and thus redundant * Removing all python regex linters on the args, now that RPCMan can be used to generate any output, including the cli.cpp table * Auto-formatting and sanity checking the RPCExamples with RPCMan * Checking passed-in json in self-check. Removing redundant checks * Checking returned json against documentation to avoid regressions or false documentation * Compile the RPC documentation at compile-time to ensure it doesn't change at runtime and is completely static ### Bugs found * The assert identified issue #18607 * The changes itself fixed bug #19250 ACKs for top commit: fjahr: utACK fa6bb0c tryphe: utACK fa6bb0c. Reducing data duplication is nice. Code changes are minimal and concise. Tree-SHA512: deb0edc3f999baf055526eaa199b98c500635e12502dece7aa3cad5319db330eb5ee7459a5c8f040a83671a7f20c560c19a2026fb76c8416f138aa332727cbce
2 parents 7737603 + fa6bb0c commit d692d19

File tree

3 files changed

+295
-193
lines changed

3 files changed

+295
-193
lines changed

src/rest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static bool rest_block_notxdetails(const util::Ref& context, HTTPRequest* req, c
303303
}
304304

305305
// A bit of a hack - dependency on a function defined in rpc/blockchain.cpp
306-
UniValue getblockchaininfo(const JSONRPCRequest& request);
306+
RPCHelpMan getblockchaininfo();
307307

308308
static bool rest_chaininfo(const util::Ref& context, HTTPRequest* req, const std::string& strURIPart)
309309
{
@@ -316,7 +316,7 @@ static bool rest_chaininfo(const util::Ref& context, HTTPRequest* req, const std
316316
case RetFormat::JSON: {
317317
JSONRPCRequest jsonRequest(context);
318318
jsonRequest.params = UniValue(UniValue::VARR);
319-
UniValue chainInfoObject = getblockchaininfo(jsonRequest);
319+
UniValue chainInfoObject = getblockchaininfo().HandleRequest(jsonRequest);
320320
std::string strJSON = chainInfoObject.write() + "\n";
321321
req->WriteHeader("Content-Type", "application/json");
322322
req->WriteReply(HTTP_OK, strJSON);

0 commit comments

Comments
 (0)