HomePhabricator

rpc: Add MaybeArg() and Arg() default helper

Description

rpc: Add MaybeArg() and Arg() default helper

Summary:
Currently the RPC method implementations have many issues:

  • Default RPC argument values (and their optionality state) are duplicated in the documentation and the C++ code, with no checks to prevent them from going out of sync.
  • Getting an optional RPC argument is verbose, using a ternary operator, or worse, a multi-line if.

Fix all issues by adding default helper that can be called via self.Arg<int>(0). The helper needs a few lines of code in the src/rpc/util.h header file. Everything else will be implemented in the cpp file once and if an RPC method needs it.

There is also an self.MaybeArg<int>(0) helper that works on any arg to return the argument, the default, or a falsy value

This is a backport of core#28230
Depends on D17943

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D17944

Details

Provenance
MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>Authored on Aug 7 2023, 12:53
PiRKCommitted on Thu, Apr 17, 11:07
PiRKPushed on Thu, Apr 17, 11:07
Reviewer
Restricted Project
Differential Revision
D17944: rpc: Add MaybeArg() and Arg() default helper
Parents
rABC92b26b9a5582: rpc: use RPCArg::Optional::OMITTED over OMITTED_NAMED_ARG
Branches
Unknown
Tags
Unknown