Skip to content

Commit c7a9fc2

Browse files
committed
Make the RPCHelpMan aware of JSONRPCRequest and add Check() helper
1 parent 5c5e32b commit c7a9fc2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/rpc/util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ class RPCHelpMan
243243
std::string ToString() const;
244244
/** If the supplied number of args is neither too small nor too high */
245245
bool IsValidNumArgs(size_t num_args) const;
246+
/**
247+
* Check if the given request is valid according to this command or if
248+
* the user is asking for help information, and throw help when appropriate.
249+
*/
250+
inline void Check(const JSONRPCRequest& request) const {
251+
if (request.fHelp || !IsValidNumArgs(request.params.size())) {
252+
throw std::runtime_error(ToString());
253+
}
254+
}
246255

247256
private:
248257
const std::string m_name;

0 commit comments

Comments
 (0)