Page MenuHomePhabricator

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

Authored by PiRK on Thu, Apr 17, 08:09.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC5112370f0353: 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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable