1
- // Copyright (c) 2017-2018 The Bitcoin Core developers
1
+ // Copyright (c) 2017-2019 The Bitcoin Core developers
2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
@@ -315,6 +315,17 @@ std::string RPCExamples::ToDescriptionString() const
315
315
return m_examples.empty () ? m_examples : " \n Examples:\n " + m_examples;
316
316
}
317
317
318
+ bool RPCHelpMan::IsValidNumArgs (size_t num_args) const
319
+ {
320
+ size_t num_required_args = 0 ;
321
+ for (size_t n = m_args.size (); n > 0 ; --n) {
322
+ if (!m_args.at (n - 1 ).IsOptional ()) {
323
+ num_required_args = n;
324
+ break ;
325
+ }
326
+ }
327
+ return num_required_args <= num_args && num_args <= m_args.size ();
328
+ }
318
329
std::string RPCHelpMan::ToString () const
319
330
{
320
331
std::string ret;
@@ -323,12 +334,7 @@ std::string RPCHelpMan::ToString() const
323
334
ret += m_name;
324
335
bool was_optional{false };
325
336
for (const auto & arg : m_args) {
326
- bool optional;
327
- if (arg.m_fallback .which () == 1 ) {
328
- optional = true ;
329
- } else {
330
- optional = RPCArg::Optional::NO != boost::get<RPCArg::Optional>(arg.m_fallback );
331
- }
337
+ const bool optional = arg.IsOptional ();
332
338
ret += " " ;
333
339
if (optional) {
334
340
if (!was_optional) ret += " ( " ;
@@ -370,6 +376,15 @@ std::string RPCHelpMan::ToString() const
370
376
return ret;
371
377
}
372
378
379
+ bool RPCArg::IsOptional () const
380
+ {
381
+ if (m_fallback.which () == 1 ) {
382
+ return true ;
383
+ } else {
384
+ return RPCArg::Optional::NO != boost::get<RPCArg::Optional>(m_fallback);
385
+ }
386
+ }
387
+
373
388
std::string RPCArg::ToDescriptionString () const
374
389
{
375
390
std::string ret;
0 commit comments