27
27
28
28
#include < univalue.h>
29
29
30
- static UniValue validateaddress (const JSONRPCRequest& request )
30
+ static RPCHelpMan validateaddress ()
31
31
{
32
- RPCHelpMan{" validateaddress" ,
32
+ return RPCHelpMan{" validateaddress" ,
33
33
" \n Return information about the given bitcoin address.\n " ,
34
34
{
35
35
{" address" , RPCArg::Type::STR, RPCArg::Optional::NO, " The bitcoin address to validate" },
@@ -50,8 +50,8 @@ static UniValue validateaddress(const JSONRPCRequest& request)
50
50
HelpExampleCli (" validateaddress" , " \" " + EXAMPLE_ADDRESS[0 ] + " \" " ) +
51
51
HelpExampleRpc (" validateaddress" , " \" " + EXAMPLE_ADDRESS[0 ] + " \" " )
52
52
},
53
- }. Check ( request);
54
-
53
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
54
+ {
55
55
CTxDestination dest = DecodeDestination (request.params [0 ].get_str ());
56
56
bool isValid = IsValidDestination (dest);
57
57
@@ -69,11 +69,13 @@ static UniValue validateaddress(const JSONRPCRequest& request)
69
69
ret.pushKVs (detail);
70
70
}
71
71
return ret;
72
+ },
73
+ };
72
74
}
73
75
74
- static UniValue createmultisig (const JSONRPCRequest& request )
76
+ static RPCHelpMan createmultisig ()
75
77
{
76
- RPCHelpMan{" createmultisig" ,
78
+ return RPCHelpMan{" createmultisig" ,
77
79
" \n Creates a multi-signature address with n signature of m keys required.\n "
78
80
" It returns a json object with the address and redeemScript.\n " ,
79
81
{
@@ -98,8 +100,8 @@ static UniValue createmultisig(const JSONRPCRequest& request)
98
100
" \n As a JSON-RPC call\n "
99
101
+ HelpExampleRpc (" createmultisig" , " 2, \" [\\\" 03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\" ,\\\" 03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\" ]\" " )
100
102
},
101
- }. Check ( request);
102
-
103
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
104
+ {
103
105
int required = request.params [0 ].get_int ();
104
106
105
107
// Get the public keys
@@ -135,11 +137,13 @@ static UniValue createmultisig(const JSONRPCRequest& request)
135
137
result.pushKV (" descriptor" , descriptor->ToString ());
136
138
137
139
return result;
140
+ },
141
+ };
138
142
}
139
143
140
- UniValue getdescriptorinfo (const JSONRPCRequest& request )
144
+ static RPCHelpMan getdescriptorinfo ()
141
145
{
142
- RPCHelpMan{" getdescriptorinfo" ,
146
+ return RPCHelpMan{" getdescriptorinfo" ,
143
147
{" \n Analyses a descriptor.\n " },
144
148
{
145
149
{" descriptor" , RPCArg::Type::STR, RPCArg::Optional::NO, " The descriptor." },
@@ -157,8 +161,9 @@ UniValue getdescriptorinfo(const JSONRPCRequest& request)
157
161
RPCExamples{
158
162
" Analyse a descriptor\n " +
159
163
HelpExampleCli (" getdescriptorinfo" , " \" wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)\" " )
160
- }}.Check (request);
161
-
164
+ },
165
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
166
+ {
162
167
RPCTypeCheck (request.params , {UniValue::VSTR});
163
168
164
169
FlatSigningProvider provider;
@@ -175,11 +180,13 @@ UniValue getdescriptorinfo(const JSONRPCRequest& request)
175
180
result.pushKV (" issolvable" , desc->IsSolvable ());
176
181
result.pushKV (" hasprivatekeys" , provider.keys .size () > 0 );
177
182
return result;
183
+ },
184
+ };
178
185
}
179
186
180
- UniValue deriveaddresses (const JSONRPCRequest& request )
187
+ static RPCHelpMan deriveaddresses ()
181
188
{
182
- RPCHelpMan{" deriveaddresses" ,
189
+ return RPCHelpMan{" deriveaddresses" ,
183
190
{" \n Derives one or more addresses corresponding to an output descriptor.\n "
184
191
" Examples of output descriptors are:\n "
185
192
" pkh(<pubkey>) P2PKH outputs for the given pubkey\n "
@@ -202,8 +209,9 @@ UniValue deriveaddresses(const JSONRPCRequest& request)
202
209
RPCExamples{
203
210
" First three native segwit receive addresses\n " +
204
211
HelpExampleCli (" deriveaddresses" , " \" wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu\" \" [0,2]\" " )
205
- }}.Check (request);
206
-
212
+ },
213
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
214
+ {
207
215
RPCTypeCheck (request.params , {UniValue::VSTR, UniValueType ()}); // Range argument is checked later
208
216
const std::string desc_str = request.params [0 ].get_str ();
209
217
@@ -254,11 +262,13 @@ UniValue deriveaddresses(const JSONRPCRequest& request)
254
262
}
255
263
256
264
return addresses;
265
+ },
266
+ };
257
267
}
258
268
259
- static UniValue verifymessage (const JSONRPCRequest& request )
269
+ static RPCHelpMan verifymessage ()
260
270
{
261
- RPCHelpMan{" verifymessage" ,
271
+ return RPCHelpMan{" verifymessage" ,
262
272
" \n Verify a signed message\n " ,
263
273
{
264
274
{" address" , RPCArg::Type::STR, RPCArg::Optional::NO, " The bitcoin address to use for the signature." },
@@ -278,8 +288,8 @@ static UniValue verifymessage(const JSONRPCRequest& request)
278
288
" \n As a JSON-RPC call\n "
279
289
+ HelpExampleRpc (" verifymessage" , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" , \" signature\" , \" my message\" " )
280
290
},
281
- }. Check ( request);
282
-
291
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
292
+ {
283
293
LOCK (cs_main);
284
294
285
295
std::string strAddress = request.params [0 ].get_str ();
@@ -301,11 +311,13 @@ static UniValue verifymessage(const JSONRPCRequest& request)
301
311
}
302
312
303
313
return false ;
314
+ },
315
+ };
304
316
}
305
317
306
- static UniValue signmessagewithprivkey (const JSONRPCRequest& request )
318
+ static RPCHelpMan signmessagewithprivkey ()
307
319
{
308
- RPCHelpMan{" signmessagewithprivkey" ,
320
+ return RPCHelpMan{" signmessagewithprivkey" ,
309
321
" \n Sign a message with the private key of an address\n " ,
310
322
{
311
323
{" privkey" , RPCArg::Type::STR, RPCArg::Optional::NO, " The private key to sign the message with." },
@@ -322,8 +334,8 @@ static UniValue signmessagewithprivkey(const JSONRPCRequest& request)
322
334
" \n As a JSON-RPC call\n "
323
335
+ HelpExampleRpc (" signmessagewithprivkey" , " \" privkey\" , \" my message\" " )
324
336
},
325
- }. Check ( request);
326
-
337
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
338
+ {
327
339
std::string strPrivkey = request.params [0 ].get_str ();
328
340
std::string strMessage = request.params [1 ].get_str ();
329
341
@@ -339,20 +351,22 @@ static UniValue signmessagewithprivkey(const JSONRPCRequest& request)
339
351
}
340
352
341
353
return signature;
354
+ },
355
+ };
342
356
}
343
357
344
- static UniValue setmocktime (const JSONRPCRequest& request )
358
+ static RPCHelpMan setmocktime ()
345
359
{
346
- RPCHelpMan{" setmocktime" ,
360
+ return RPCHelpMan{" setmocktime" ,
347
361
" \n Set the local time to given timestamp (-regtest only)\n " ,
348
362
{
349
363
{" timestamp" , RPCArg::Type::NUM, RPCArg::Optional::NO, UNIX_EPOCH_TIME + " \n "
350
364
" Pass 0 to go back to using the system time." },
351
365
},
352
366
RPCResult{RPCResult::Type::NONE, " " , " " },
353
367
RPCExamples{" " },
354
- }. Check ( request);
355
-
368
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
369
+ {
356
370
if (!Params ().IsMockableChain ()) {
357
371
throw std::runtime_error (" setmocktime is for regression testing (-regtest mode) only" );
358
372
}
@@ -374,19 +388,21 @@ static UniValue setmocktime(const JSONRPCRequest& request)
374
388
}
375
389
376
390
return NullUniValue;
391
+ },
392
+ };
377
393
}
378
394
379
- static UniValue mockscheduler (const JSONRPCRequest& request )
395
+ static RPCHelpMan mockscheduler ()
380
396
{
381
- RPCHelpMan{" mockscheduler" ,
397
+ return RPCHelpMan{" mockscheduler" ,
382
398
" \n Bump the scheduler into the future (-regtest only)\n " ,
383
399
{
384
400
{" delta_time" , RPCArg::Type::NUM, RPCArg::Optional::NO, " Number of seconds to forward the scheduler into the future." },
385
401
},
386
402
RPCResult{RPCResult::Type::NONE, " " , " " },
387
403
RPCExamples{" " },
388
- }. Check ( request);
389
-
404
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
405
+ {
390
406
if (!Params ().IsMockableChain ()) {
391
407
throw std::runtime_error (" mockscheduler is for regression testing (-regtest mode) only" );
392
408
}
@@ -405,6 +421,8 @@ static UniValue mockscheduler(const JSONRPCRequest& request)
405
421
node.scheduler ->MockForward (std::chrono::seconds (delta_seconds));
406
422
407
423
return NullUniValue;
424
+ },
425
+ };
408
426
}
409
427
410
428
static UniValue RPCLockedMemoryInfo ()
@@ -439,12 +457,12 @@ static std::string RPCMallocInfo()
439
457
}
440
458
#endif
441
459
442
- static UniValue getmemoryinfo (const JSONRPCRequest& request )
460
+ static RPCHelpMan getmemoryinfo ()
443
461
{
444
462
/* Please, avoid using the word "pool" here in the RPC interface or help,
445
463
* as users will undoubtedly confuse it with the other "memory pool"
446
464
*/
447
- RPCHelpMan{" getmemoryinfo" ,
465
+ return RPCHelpMan{" getmemoryinfo" ,
448
466
" Returns an object containing information about memory usage.\n " ,
449
467
{
450
468
{" mode" , RPCArg::Type::STR, /* default */ " \" stats\" " , " determines what kind of information is returned.\n "
@@ -474,8 +492,8 @@ static UniValue getmemoryinfo(const JSONRPCRequest& request)
474
492
HelpExampleCli (" getmemoryinfo" , " " )
475
493
+ HelpExampleRpc (" getmemoryinfo" , " " )
476
494
},
477
- }. Check ( request);
478
-
495
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
496
+ {
479
497
std::string mode = request.params [0 ].isNull () ? " stats" : request.params [0 ].get_str ();
480
498
if (mode == " stats" ) {
481
499
UniValue obj (UniValue::VOBJ);
@@ -490,6 +508,8 @@ static UniValue getmemoryinfo(const JSONRPCRequest& request)
490
508
} else {
491
509
throw JSONRPCError (RPC_INVALID_PARAMETER, " unknown mode " + mode);
492
510
}
511
+ },
512
+ };
493
513
}
494
514
495
515
static void EnableOrDisableLogCategories (UniValue cats, bool enable) {
@@ -510,9 +530,9 @@ static void EnableOrDisableLogCategories(UniValue cats, bool enable) {
510
530
}
511
531
}
512
532
513
- UniValue logging (const JSONRPCRequest& request )
533
+ static RPCHelpMan logging ()
514
534
{
515
- RPCHelpMan{" logging" ,
535
+ return RPCHelpMan{" logging" ,
516
536
" Gets and sets the logging configuration.\n "
517
537
" When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n "
518
538
" When called with arguments, adds or removes categories from debug logging and return the lists above.\n "
@@ -543,8 +563,8 @@ UniValue logging(const JSONRPCRequest& request)
543
563
HelpExampleCli (" logging" , " \" [\\\" all\\\" ]\" \" [\\\" http\\\" ]\" " )
544
564
+ HelpExampleRpc (" logging" , " [\" all\" ], [\" libevent\" ]" )
545
565
},
546
- }. Check ( request);
547
-
566
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
567
+ {
548
568
uint32_t original_log_categories = LogInstance ().GetCategoryMask ();
549
569
if (request.params [0 ].isArray ()) {
550
570
EnableOrDisableLogCategories (request.params [0 ], true );
@@ -575,28 +595,47 @@ UniValue logging(const JSONRPCRequest& request)
575
595
}
576
596
577
597
return result;
598
+ },
599
+ };
578
600
}
579
601
580
- static UniValue echo (const JSONRPCRequest& request )
602
+ static RPCHelpMan echo (const std::string& name )
581
603
{
582
- if (request.fHelp )
583
- throw std::runtime_error (
584
- RPCHelpMan{" echo|echojson ..." ,
604
+ return RPCHelpMan{name,
585
605
" \n Simply echo back the input arguments. This command is for testing.\n "
586
- " \n It will return an internal bug report when exactly 100 arguments are passed.\n "
606
+ " \n It will return an internal bug report when arg9='trigger_internal_bug' is passed.\n "
587
607
" \n The difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in "
588
608
" bitcoin-cli and the GUI. There is no server-side difference." ,
589
- {},
609
+ {
610
+ {" arg0" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
611
+ {" arg1" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
612
+ {" arg2" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
613
+ {" arg3" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
614
+ {" arg4" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
615
+ {" arg5" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
616
+ {" arg6" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
617
+ {" arg7" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
618
+ {" arg8" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
619
+ {" arg9" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " " },
620
+ },
590
621
RPCResult{RPCResult::Type::NONE, " " , " Returns whatever was passed in" },
591
622
RPCExamples{" " },
592
- }.ToString ()
593
- );
623
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
624
+ {
625
+ if (request.fHelp ) throw std::runtime_error (self.ToString ());
594
626
595
- CHECK_NONFATAL (request.params .size () != 100 );
627
+ if (request.params [9 ].isStr ()) {
628
+ CHECK_NONFATAL (request.params [9 ].get_str () != " trigger_internal_bug" );
629
+ }
596
630
597
631
return request.params ;
632
+ },
633
+ };
598
634
}
599
635
636
+ static RPCHelpMan echo () { return echo (" echo" ); }
637
+ static RPCHelpMan echojson () { return echo (" echojson" ); }
638
+
600
639
void RegisterMiscRPCCommands (CRPCTable &t)
601
640
{
602
641
// clang-format off
@@ -616,10 +655,10 @@ static const CRPCCommand commands[] =
616
655
{ " hidden" , " setmocktime" , &setmocktime, {" timestamp" }},
617
656
{ " hidden" , " mockscheduler" , &mockscheduler, {" delta_time" }},
618
657
{ " hidden" , " echo" , &echo, {" arg0" ," arg1" ," arg2" ," arg3" ," arg4" ," arg5" ," arg6" ," arg7" ," arg8" ," arg9" }},
619
- { " hidden" , " echojson" , &echo, {" arg0" ," arg1" ," arg2" ," arg3" ," arg4" ," arg5" ," arg6" ," arg7" ," arg8" ," arg9" }},
658
+ { " hidden" , " echojson" , &echojson, {" arg0" ," arg1" ," arg2" ," arg3" ," arg4" ," arg5" ," arg6" ," arg7" ," arg8" ," arg9" }},
620
659
};
621
660
// clang-format on
622
-
623
- for ( unsigned int vcidx = 0 ; vcidx < ARRAYLEN (commands); vcidx++)
624
- t. appendCommand (commands[vcidx]. name , &commands[vcidx]);
661
+ for ( const auto & c : commands) {
662
+ t. appendCommand (c. name , &c);
663
+ }
625
664
}
0 commit comments