29
29
30
30
#include < univalue.h>
31
31
32
- static UniValue getconnectioncount (const JSONRPCRequest& request )
32
+ static RPCHelpMan getconnectioncount ()
33
33
{
34
- RPCHelpMan{" getconnectioncount" ,
34
+ return RPCHelpMan{" getconnectioncount" ,
35
35
" \n Returns the number of connections to other nodes.\n " ,
36
36
{},
37
37
RPCResult{
@@ -41,18 +41,20 @@ static UniValue getconnectioncount(const JSONRPCRequest& request)
41
41
HelpExampleCli (" getconnectioncount" , " " )
42
42
+ HelpExampleRpc (" getconnectioncount" , " " )
43
43
},
44
- }. Check ( request);
45
-
44
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
45
+ {
46
46
NodeContext& node = EnsureNodeContext (request.context );
47
47
if (!node.connman )
48
48
throw JSONRPCError (RPC_CLIENT_P2P_DISABLED, " Error: Peer-to-peer functionality missing or disabled" );
49
49
50
50
return (int )node.connman ->GetNodeCount (CConnman::CONNECTIONS_ALL);
51
+ },
52
+ };
51
53
}
52
54
53
- static UniValue ping (const JSONRPCRequest& request )
55
+ static RPCHelpMan ping ()
54
56
{
55
- RPCHelpMan{" ping" ,
57
+ return RPCHelpMan{" ping" ,
56
58
" \n Requests that a ping be sent to all other nodes, to measure ping time.\n "
57
59
" Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n "
58
60
" Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n " ,
@@ -62,8 +64,8 @@ static UniValue ping(const JSONRPCRequest& request)
62
64
HelpExampleCli (" ping" , " " )
63
65
+ HelpExampleRpc (" ping" , " " )
64
66
},
65
- }. Check ( request);
66
-
67
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
68
+ {
67
69
NodeContext& node = EnsureNodeContext (request.context );
68
70
if (!node.connman )
69
71
throw JSONRPCError (RPC_CLIENT_P2P_DISABLED, " Error: Peer-to-peer functionality missing or disabled" );
@@ -73,11 +75,13 @@ static UniValue ping(const JSONRPCRequest& request)
73
75
pnode->fPingQueued = true ;
74
76
});
75
77
return NullUniValue;
78
+ },
79
+ };
76
80
}
77
81
78
- static UniValue getpeerinfo (const JSONRPCRequest& request )
82
+ static RPCHelpMan getpeerinfo ()
79
83
{
80
- RPCHelpMan{" getpeerinfo" ,
84
+ return RPCHelpMan{" getpeerinfo" ,
81
85
" \n Returns data about each connected network node as a json array of objects.\n " ,
82
86
{},
83
87
RPCResult{
@@ -142,8 +146,8 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
142
146
HelpExampleCli (" getpeerinfo" , " " )
143
147
+ HelpExampleRpc (" getpeerinfo" , " " )
144
148
},
145
- }. Check ( request);
146
-
149
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
150
+ {
147
151
NodeContext& node = EnsureNodeContext (request.context );
148
152
if (!node.connman )
149
153
throw JSONRPCError (RPC_CLIENT_P2P_DISABLED, " Error: Peer-to-peer functionality missing or disabled" );
@@ -233,17 +237,13 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
233
237
}
234
238
235
239
return ret;
240
+ },
241
+ };
236
242
}
237
243
238
- static UniValue addnode (const JSONRPCRequest& request )
244
+ static RPCHelpMan addnode ()
239
245
{
240
- std::string strCommand;
241
- if (!request.params [1 ].isNull ())
242
- strCommand = request.params [1 ].get_str ();
243
- if (request.fHelp || request.params .size () != 2 ||
244
- (strCommand != " onetry" && strCommand != " add" && strCommand != " remove" ))
245
- throw std::runtime_error (
246
- RPCHelpMan{" addnode" ,
246
+ return RPCHelpMan{" addnode" ,
247
247
" \n Attempts to add or remove a node from the addnode list.\n "
248
248
" Or try a connection to a node once.\n "
249
249
" Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n "
@@ -257,7 +257,15 @@ static UniValue addnode(const JSONRPCRequest& request)
257
257
HelpExampleCli (" addnode" , " \" 192.168.0.6:8333\" \" onetry\" " )
258
258
+ HelpExampleRpc (" addnode" , " \" 192.168.0.6:8333\" , \" onetry\" " )
259
259
},
260
- }.ToString ());
260
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
261
+ {
262
+ std::string strCommand;
263
+ if (!request.params [1 ].isNull ())
264
+ strCommand = request.params [1 ].get_str ();
265
+ if (request.fHelp || request.params .size () != 2 ||
266
+ (strCommand != " onetry" && strCommand != " add" && strCommand != " remove" ))
267
+ throw std::runtime_error (
268
+ self.ToString ());
261
269
262
270
NodeContext& node = EnsureNodeContext (request.context );
263
271
if (!node.connman )
@@ -284,11 +292,13 @@ static UniValue addnode(const JSONRPCRequest& request)
284
292
}
285
293
286
294
return NullUniValue;
295
+ },
296
+ };
287
297
}
288
298
289
- static UniValue disconnectnode (const JSONRPCRequest& request )
299
+ static RPCHelpMan disconnectnode ()
290
300
{
291
- RPCHelpMan{" disconnectnode" ,
301
+ return RPCHelpMan{" disconnectnode" ,
292
302
" \n Immediately disconnects from the specified peer node.\n "
293
303
" \n Strictly one out of 'address' and 'nodeid' can be provided to identify the node.\n "
294
304
" \n To disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n " ,
@@ -303,8 +313,8 @@ static UniValue disconnectnode(const JSONRPCRequest& request)
303
313
+ HelpExampleRpc (" disconnectnode" , " \" 192.168.0.6:8333\" " )
304
314
+ HelpExampleRpc (" disconnectnode" , " \"\" , 1" )
305
315
},
306
- }. Check ( request);
307
-
316
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
317
+ {
308
318
NodeContext& node = EnsureNodeContext (request.context );
309
319
if (!node.connman )
310
320
throw JSONRPCError (RPC_CLIENT_P2P_DISABLED, " Error: Peer-to-peer functionality missing or disabled" );
@@ -329,11 +339,13 @@ static UniValue disconnectnode(const JSONRPCRequest& request)
329
339
}
330
340
331
341
return NullUniValue;
342
+ },
343
+ };
332
344
}
333
345
334
- static UniValue getaddednodeinfo (const JSONRPCRequest& request )
346
+ static RPCHelpMan getaddednodeinfo ()
335
347
{
336
- RPCHelpMan{" getaddednodeinfo" ,
348
+ return RPCHelpMan{" getaddednodeinfo" ,
337
349
" \n Returns information about the given added node, or all added nodes\n "
338
350
" (note that onetry addnodes are not listed here)\n " ,
339
351
{
@@ -361,8 +373,8 @@ static UniValue getaddednodeinfo(const JSONRPCRequest& request)
361
373
HelpExampleCli (" getaddednodeinfo" , " \" 192.168.0.201\" " )
362
374
+ HelpExampleRpc (" getaddednodeinfo" , " \" 192.168.0.201\" " )
363
375
},
364
- }. Check ( request);
365
-
376
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
377
+ {
366
378
NodeContext& node = EnsureNodeContext (request.context );
367
379
if (!node.connman )
368
380
throw JSONRPCError (RPC_CLIENT_P2P_DISABLED, " Error: Peer-to-peer functionality missing or disabled" );
@@ -401,11 +413,13 @@ static UniValue getaddednodeinfo(const JSONRPCRequest& request)
401
413
}
402
414
403
415
return ret;
416
+ },
417
+ };
404
418
}
405
419
406
- static UniValue getnettotals (const JSONRPCRequest& request )
420
+ static RPCHelpMan getnettotals ()
407
421
{
408
- RPCHelpMan{" getnettotals" ,
422
+ return RPCHelpMan{" getnettotals" ,
409
423
" \n Returns information about network traffic, including bytes in, bytes out,\n "
410
424
" and current time.\n " ,
411
425
{},
@@ -430,7 +444,8 @@ static UniValue getnettotals(const JSONRPCRequest& request)
430
444
HelpExampleCli (" getnettotals" , " " )
431
445
+ HelpExampleRpc (" getnettotals" , " " )
432
446
},
433
- }.Check (request);
447
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
448
+ {
434
449
NodeContext& node = EnsureNodeContext (request.context );
435
450
if (!node.connman )
436
451
throw JSONRPCError (RPC_CLIENT_P2P_DISABLED, " Error: Peer-to-peer functionality missing or disabled" );
@@ -449,6 +464,8 @@ static UniValue getnettotals(const JSONRPCRequest& request)
449
464
outboundLimit.pushKV (" time_left_in_cycle" , node.connman ->GetMaxOutboundTimeLeftInCycle ());
450
465
obj.pushKV (" uploadtarget" , outboundLimit);
451
466
return obj;
467
+ },
468
+ };
452
469
}
453
470
454
471
static UniValue GetNetworksInfo ()
@@ -472,9 +489,9 @@ static UniValue GetNetworksInfo()
472
489
return networks;
473
490
}
474
491
475
- static UniValue getnetworkinfo (const JSONRPCRequest& request )
492
+ static RPCHelpMan getnetworkinfo ()
476
493
{
477
- RPCHelpMan{" getnetworkinfo" ,
494
+ return RPCHelpMan{" getnetworkinfo" ,
478
495
" Returns an object containing various state info regarding P2P networking.\n " ,
479
496
{},
480
497
RPCResult{
@@ -523,8 +540,8 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
523
540
HelpExampleCli (" getnetworkinfo" , " " )
524
541
+ HelpExampleRpc (" getnetworkinfo" , " " )
525
542
},
526
- }. Check ( request);
527
-
543
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
544
+ {
528
545
LOCK (cs_main);
529
546
UniValue obj (UniValue::VOBJ);
530
547
obj.pushKV (" version" , CLIENT_VERSION);
@@ -562,11 +579,13 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
562
579
obj.pushKV (" localaddresses" , localAddresses);
563
580
obj.pushKV (" warnings" , GetWarnings (false ).original );
564
581
return obj;
582
+ },
583
+ };
565
584
}
566
585
567
- static UniValue setban (const JSONRPCRequest& request )
586
+ static RPCHelpMan setban ()
568
587
{
569
- const RPCHelpMan help {" setban" ,
588
+ return RPCHelpMan{" setban" ,
570
589
" \n Attempts to add or remove an IP/Subnet from the banned list.\n " ,
571
590
{
572
591
{" subnet" , RPCArg::Type::STR, RPCArg::Optional::NO, " The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP)" },
@@ -580,7 +599,8 @@ static UniValue setban(const JSONRPCRequest& request)
580
599
+ HelpExampleCli (" setban" , " \" 192.168.0.0/24\" \" add\" " )
581
600
+ HelpExampleRpc (" setban" , " \" 192.168.0.6\" , \" add\" , 86400" )
582
601
},
583
- };
602
+ [&](const RPCHelpMan& help, const JSONRPCRequest& request) -> UniValue
603
+ {
584
604
std::string strCommand;
585
605
if (!request.params [1 ].isNull ())
586
606
strCommand = request.params [1 ].get_str ();
@@ -643,11 +663,13 @@ static UniValue setban(const JSONRPCRequest& request)
643
663
}
644
664
}
645
665
return NullUniValue;
666
+ },
667
+ };
646
668
}
647
669
648
- static UniValue listbanned (const JSONRPCRequest& request )
670
+ static RPCHelpMan listbanned ()
649
671
{
650
- RPCHelpMan{" listbanned" ,
672
+ return RPCHelpMan{" listbanned" ,
651
673
" \n List all manually banned IPs/Subnets.\n " ,
652
674
{},
653
675
RPCResult{RPCResult::Type::ARR, " " , " " ,
@@ -663,8 +685,8 @@ static UniValue listbanned(const JSONRPCRequest& request)
663
685
HelpExampleCli (" listbanned" , " " )
664
686
+ HelpExampleRpc (" listbanned" , " " )
665
687
},
666
- }. Check ( request);
667
-
688
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
689
+ {
668
690
NodeContext& node = EnsureNodeContext (request.context );
669
691
if (!node.banman ) {
670
692
throw JSONRPCError (RPC_DATABASE_ERROR, " Error: Ban database not loaded" );
@@ -686,19 +708,22 @@ static UniValue listbanned(const JSONRPCRequest& request)
686
708
}
687
709
688
710
return bannedAddresses;
711
+ },
712
+ };
689
713
}
690
714
691
- static UniValue clearbanned (const JSONRPCRequest& request )
715
+ static RPCHelpMan clearbanned ()
692
716
{
693
- RPCHelpMan{" clearbanned" ,
717
+ return RPCHelpMan{" clearbanned" ,
694
718
" \n Clear all banned IPs.\n " ,
695
719
{},
696
720
RPCResult{RPCResult::Type::NONE, " " , " " },
697
721
RPCExamples{
698
722
HelpExampleCli (" clearbanned" , " " )
699
723
+ HelpExampleRpc (" clearbanned" , " " )
700
724
},
701
- }.Check (request);
725
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
726
+ {
702
727
NodeContext& node = EnsureNodeContext (request.context );
703
728
if (!node.banman ) {
704
729
throw JSONRPCError (RPC_DATABASE_ERROR, " Error: Ban database not loaded" );
@@ -707,19 +732,21 @@ static UniValue clearbanned(const JSONRPCRequest& request)
707
732
node.banman ->ClearBanned ();
708
733
709
734
return NullUniValue;
735
+ },
736
+ };
710
737
}
711
738
712
- static UniValue setnetworkactive (const JSONRPCRequest& request )
739
+ static RPCHelpMan setnetworkactive ()
713
740
{
714
- RPCHelpMan{" setnetworkactive" ,
741
+ return RPCHelpMan{" setnetworkactive" ,
715
742
" \n Disable/enable all p2p network activity.\n " ,
716
743
{
717
744
{" state" , RPCArg::Type::BOOL, RPCArg::Optional::NO, " true to enable networking, false to disable" },
718
745
},
719
746
RPCResult{RPCResult::Type::BOOL, " " , " The value that was passed in" },
720
747
RPCExamples{" " },
721
- }. Check ( request);
722
-
748
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
749
+ {
723
750
NodeContext& node = EnsureNodeContext (request.context );
724
751
if (!node.connman ) {
725
752
throw JSONRPCError (RPC_CLIENT_P2P_DISABLED, " Error: Peer-to-peer functionality missing or disabled" );
@@ -728,11 +755,13 @@ static UniValue setnetworkactive(const JSONRPCRequest& request)
728
755
node.connman ->SetNetworkActive (request.params [0 ].get_bool ());
729
756
730
757
return node.connman ->GetNetworkActive ();
758
+ },
759
+ };
731
760
}
732
761
733
- static UniValue getnodeaddresses (const JSONRPCRequest& request )
762
+ static RPCHelpMan getnodeaddresses ()
734
763
{
735
- RPCHelpMan{" getnodeaddresses" ,
764
+ return RPCHelpMan{" getnodeaddresses" ,
736
765
" \n Return known addresses which can potentially be used to find new nodes in the network\n " ,
737
766
{
738
767
{" count" , RPCArg::Type::NUM, /* default */ " 1" , " The maximum number of addresses to return. Specify 0 to return all known addresses." },
@@ -753,7 +782,8 @@ static UniValue getnodeaddresses(const JSONRPCRequest& request)
753
782
HelpExampleCli (" getnodeaddresses" , " 8" )
754
783
+ HelpExampleRpc (" getnodeaddresses" , " 8" )
755
784
},
756
- }.Check (request);
785
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
786
+ {
757
787
NodeContext& node = EnsureNodeContext (request.context );
758
788
if (!node.connman ) {
759
789
throw JSONRPCError (RPC_CLIENT_P2P_DISABLED, " Error: Peer-to-peer functionality missing or disabled" );
@@ -779,11 +809,13 @@ static UniValue getnodeaddresses(const JSONRPCRequest& request)
779
809
ret.push_back (obj);
780
810
}
781
811
return ret;
812
+ },
813
+ };
782
814
}
783
815
784
- static UniValue addpeeraddress (const JSONRPCRequest& request )
816
+ static RPCHelpMan addpeeraddress ()
785
817
{
786
- RPCHelpMan{" addpeeraddress" ,
818
+ return RPCHelpMan{" addpeeraddress" ,
787
819
" \n Add the address of a potential peer to the address manager. This RPC is for testing only.\n " ,
788
820
{
789
821
{" address" , RPCArg::Type::STR, RPCArg::Optional::NO, " The IP address of the peer" },
@@ -799,8 +831,8 @@ static UniValue addpeeraddress(const JSONRPCRequest& request)
799
831
HelpExampleCli (" addpeeraddress" , " \" 1.2.3.4\" 8333" )
800
832
+ HelpExampleRpc (" addpeeraddress" , " \" 1.2.3.4\" , 8333" )
801
833
},
802
- }. Check ( request);
803
-
834
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
835
+ {
804
836
NodeContext& node = EnsureNodeContext (request.context );
805
837
if (!node.connman ) {
806
838
throw JSONRPCError (RPC_CLIENT_P2P_DISABLED, " Error: Peer-to-peer functionality missing or disabled" );
@@ -827,6 +859,8 @@ static UniValue addpeeraddress(const JSONRPCRequest& request)
827
859
828
860
obj.pushKV (" success" , true );
829
861
return obj;
862
+ },
863
+ };
830
864
}
831
865
832
866
void RegisterNetRPCCommands (CRPCTable &t)
0 commit comments