Skip to content

Commit 357488f

Browse files
author
MarcoFalke
committed
Merge #16240: JSONRPCRequest-aware RPCHelpMan
b6fb617 rpc: switch to using RPCHelpMan.Check() (Karl-Johan Alm) c7a9fc2 Make the RPCHelpMan aware of JSONRPCRequest and add Check() helper (Karl-Johan Alm) 5c5e32b rpc: migrate JSONRPCRequest functionality into request.cpp (Karl-Johan Alm) 0ab8ba1 rpc: fix RPC help requirements for getblocktemplate (Karl-Johan Alm) Pull request description: Every single RPC call has a helper-section at the start, which throws a help string if the user asks for help or if the user provided too few/many arguments. ```C++ const RPCHelpMan help{...}; if (request.fHelp || !help.IsValidNumArgs(request.params.size())) { throw std::runtime_error(help.ToString()); } ``` or (older version) ```C++ if (request.fHelp || request.params.size() < min || request.params.size() > max) throw std::runtime_error( RPCHelpMan{...}.ToString() ); ``` It seems like an obvious improvement, and less copy-pasting, to make `RPCHelpMan` aware of `JSONRPCRequest`, and to let it handle the checks instead. Both of the above become ```C++ RPCHelpMan{...}.Check(request); ``` which means we save roughly 3 lines per RPC command, and the `RPCHelpMan` instance is never referenced afterwards, so the approach is a tiny fraction cleaner. This is a complete update, sans a few special case locations that had special rules. 623 lines turn into 284 (which includes the addition to `RPCHelpMan`). ACKs for top commit: laanwj: code rview and lightly tested ACK b6fb617 MarcoFalke: ACK b6fb617, looked at the diff, verified move-only where applicable Tree-SHA512: eb73f47f812512905b852e313281d1c8df803db40a6188aa39d5a7586631664db6764491152a8a96769946c796dc56d38c6e3a66ddd06ba3fb9d20050e6274e1
2 parents 8046a3e + b6fb617 commit 357488f

18 files changed

+253
-578
lines changed

src/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ BITCOIN_CORE_H = \
175175
rpc/blockchain.h \
176176
rpc/client.h \
177177
rpc/protocol.h \
178-
rpc/server.h \
179178
rpc/rawtransaction_util.h \
180179
rpc/register.h \
180+
rpc/request.h \
181+
rpc/server.h \
181182
rpc/util.h \
182183
scheduler.h \
183184
script/descriptor.h \
@@ -481,7 +482,7 @@ libbitcoin_util_a_SOURCES = \
481482
interfaces/handler.cpp \
482483
logging.cpp \
483484
random.cpp \
484-
rpc/protocol.cpp \
485+
rpc/request.cpp \
485486
support/cleanse.cpp \
486487
sync.cpp \
487488
threadinterrupt.cpp \

src/bitcoin-cli.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <fs.h>
1313
#include <rpc/client.h>
1414
#include <rpc/protocol.h>
15+
#include <rpc/request.h>
1516
#include <util/system.h>
1617
#include <util/strencodings.h>
1718

src/rest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <primitives/block.h>
1313
#include <primitives/transaction.h>
1414
#include <rpc/blockchain.h>
15+
#include <rpc/protocol.h>
1516
#include <rpc/server.h>
1617
#include <streams.h>
1718
#include <sync.h>

0 commit comments

Comments
 (0)