@@ -81,9 +81,9 @@ static UniValue GetNetworkHashPS(int lookup, int height) {
81
81
return workDiff.getdouble () / timeDiff;
82
82
}
83
83
84
- static UniValue getnetworkhashps (const JSONRPCRequest& request )
84
+ static RPCHelpMan getnetworkhashps ()
85
85
{
86
- RPCHelpMan{" getnetworkhashps" ,
86
+ return RPCHelpMan{" getnetworkhashps" ,
87
87
" \n Returns the estimated network hashes per second based on the last n blocks.\n "
88
88
" Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n "
89
89
" Pass in [height] to estimate the network speed at the time when a certain block was found.\n " ,
@@ -97,10 +97,12 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request)
97
97
HelpExampleCli (" getnetworkhashps" , " " )
98
98
+ HelpExampleRpc (" getnetworkhashps" , " " )
99
99
},
100
- }. Check ( request);
101
-
100
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
101
+ {
102
102
LOCK (cs_main);
103
103
return GetNetworkHashPS (!request.params [0 ].isNull () ? request.params [0 ].get_int () : 120 , !request.params [1 ].isNull () ? request.params [1 ].get_int () : -1 );
104
+ },
105
+ };
104
106
}
105
107
106
108
static bool GenerateBlock (ChainstateManager& chainman, CBlock& block, uint64_t & max_tries, unsigned int & extra_nonce, uint256& block_hash)
@@ -200,9 +202,9 @@ static bool getScriptFromDescriptor(const std::string& descriptor, CScript& scri
200
202
}
201
203
}
202
204
203
- static UniValue generatetodescriptor (const JSONRPCRequest& request )
205
+ static RPCHelpMan generatetodescriptor ()
204
206
{
205
- RPCHelpMan{
207
+ return RPCHelpMan{
206
208
" generatetodescriptor" ,
207
209
" \n Mine blocks immediately to a specified descriptor (before the RPC call returns)\n " ,
208
210
{
@@ -218,9 +220,8 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request)
218
220
},
219
221
RPCExamples{
220
222
" \n Generate 11 blocks to mydesc\n " + HelpExampleCli (" generatetodescriptor" , " 11 \" mydesc\" " )},
221
- }
222
- .Check (request);
223
-
223
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
224
+ {
224
225
const int num_blocks{request.params [0 ].get_int ()};
225
226
const uint64_t max_tries{request.params [2 ].isNull () ? DEFAULT_MAX_TRIES : request.params [2 ].get_int ()};
226
227
@@ -234,22 +235,25 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request)
234
235
ChainstateManager& chainman = EnsureChainman (request.context );
235
236
236
237
return generateBlocks (chainman, mempool, coinbase_script, num_blocks, max_tries);
238
+ },
239
+ };
237
240
}
238
241
239
- static UniValue generate (const JSONRPCRequest& request )
242
+ static RPCHelpMan generate ()
240
243
{
241
- const std::string help_str {" generate ( nblocks maxtries ) has been replaced by the -generate cli option. Refer to -help for more information." };
244
+ return RPCHelpMan {" generate" , " has been replaced by the -generate cli option. Refer to -help for more information." , {}, {}, RPCExamples{ " " }, [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
242
245
243
246
if (request.fHelp ) {
244
- throw std::runtime_error (help_str );
247
+ throw std::runtime_error (self. ToString () );
245
248
} else {
246
- throw JSONRPCError (RPC_METHOD_NOT_FOUND, help_str );
249
+ throw JSONRPCError (RPC_METHOD_NOT_FOUND, self. ToString () );
247
250
}
251
+ }};
248
252
}
249
253
250
- static UniValue generatetoaddress (const JSONRPCRequest& request )
254
+ static RPCHelpMan generatetoaddress ()
251
255
{
252
- RPCHelpMan{" generatetoaddress" ,
256
+ return RPCHelpMan{" generatetoaddress" ,
253
257
" \n Mine blocks immediately to a specified address (before the RPC call returns)\n " ,
254
258
{
255
259
{" nblocks" , RPCArg::Type::NUM, RPCArg::Optional::NO, " How many blocks are generated immediately." },
@@ -267,8 +271,8 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
267
271
+ " If you are using the " PACKAGE_NAME " wallet, you can get a new address to send the newly generated bitcoin to with:\n "
268
272
+ HelpExampleCli (" getnewaddress" , " " )
269
273
},
270
- }. Check ( request);
271
-
274
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
275
+ {
272
276
const int num_blocks{request.params [0 ].get_int ()};
273
277
const uint64_t max_tries{request.params [2 ].isNull () ? DEFAULT_MAX_TRIES : request.params [2 ].get_int ()};
274
278
@@ -283,11 +287,13 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
283
287
CScript coinbase_script = GetScriptForDestination (destination);
284
288
285
289
return generateBlocks (chainman, mempool, coinbase_script, num_blocks, max_tries);
290
+ },
291
+ };
286
292
}
287
293
288
- static UniValue generateblock (const JSONRPCRequest& request )
294
+ static RPCHelpMan generateblock ()
289
295
{
290
- RPCHelpMan{" generateblock" ,
296
+ return RPCHelpMan{" generateblock" ,
291
297
" \n Mine a block with a set of ordered transactions immediately to a specified address or descriptor (before the RPC call returns)\n " ,
292
298
{
293
299
{" output" , RPCArg::Type::STR, RPCArg::Optional::NO, " The address or descriptor to send the newly generated bitcoin to." },
@@ -309,8 +315,8 @@ static UniValue generateblock(const JSONRPCRequest& request)
309
315
" \n Generate a block to myaddress, with txs rawtx and mempool_txid\n "
310
316
+ HelpExampleCli (" generateblock" , R"( "myaddress" '["rawtx", "mempool_txid"]')" )
311
317
},
312
- }. Check ( request);
313
-
318
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
319
+ {
314
320
const auto address_or_descriptor = request.params [0 ].get_str ();
315
321
CScript coinbase_script;
316
322
std::string error;
@@ -390,11 +396,13 @@ static UniValue generateblock(const JSONRPCRequest& request)
390
396
UniValue obj (UniValue::VOBJ);
391
397
obj.pushKV (" hash" , block_hash.GetHex ());
392
398
return obj;
399
+ },
400
+ };
393
401
}
394
402
395
- static UniValue getmininginfo (const JSONRPCRequest& request )
403
+ static RPCHelpMan getmininginfo ()
396
404
{
397
- RPCHelpMan{" getmininginfo" ,
405
+ return RPCHelpMan{" getmininginfo" ,
398
406
" \n Returns a json object containing mining-related information." ,
399
407
{},
400
408
RPCResult{
@@ -413,8 +421,8 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
413
421
HelpExampleCli (" getmininginfo" , " " )
414
422
+ HelpExampleRpc (" getmininginfo" , " " )
415
423
},
416
- }. Check ( request);
417
-
424
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
425
+ {
418
426
LOCK (cs_main);
419
427
const CTxMemPool& mempool = EnsureMemPool (request.context );
420
428
@@ -423,18 +431,20 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
423
431
if (BlockAssembler::m_last_block_weight) obj.pushKV (" currentblockweight" , *BlockAssembler::m_last_block_weight);
424
432
if (BlockAssembler::m_last_block_num_txs) obj.pushKV (" currentblocktx" , *BlockAssembler::m_last_block_num_txs);
425
433
obj.pushKV (" difficulty" , (double )GetDifficulty (::ChainActive ().Tip ()));
426
- obj.pushKV (" networkhashps" , getnetworkhashps (request));
434
+ obj.pushKV (" networkhashps" , getnetworkhashps (). HandleRequest ( request));
427
435
obj.pushKV (" pooledtx" , (uint64_t )mempool.size ());
428
436
obj.pushKV (" chain" , Params ().NetworkIDString ());
429
437
obj.pushKV (" warnings" , GetWarnings (false ).original );
430
438
return obj;
439
+ },
440
+ };
431
441
}
432
442
433
443
434
444
// NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
435
- static UniValue prioritisetransaction (const JSONRPCRequest& request )
445
+ static RPCHelpMan prioritisetransaction ()
436
446
{
437
- RPCHelpMan{" prioritisetransaction" ,
447
+ return RPCHelpMan{" prioritisetransaction" ,
438
448
" Accepts the transaction into mined blocks at a higher (or lower) priority\n " ,
439
449
{
440
450
{" txid" , RPCArg::Type::STR_HEX, RPCArg::Optional::NO, " The transaction id." },
@@ -451,8 +461,8 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
451
461
HelpExampleCli (" prioritisetransaction" , " \" txid\" 0.0 10000" )
452
462
+ HelpExampleRpc (" prioritisetransaction" , " \" txid\" , 0.0, 10000" )
453
463
},
454
- }. Check ( request);
455
-
464
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
465
+ {
456
466
LOCK (cs_main);
457
467
458
468
uint256 hash (ParseHashV (request.params [0 ], " txid" ));
@@ -464,6 +474,8 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
464
474
465
475
EnsureMemPool (request.context ).PrioritiseTransaction (hash, nAmount);
466
476
return true ;
477
+ },
478
+ };
467
479
}
468
480
469
481
@@ -495,9 +507,9 @@ static std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
495
507
return s;
496
508
}
497
509
498
- static UniValue getblocktemplate (const JSONRPCRequest& request )
510
+ static RPCHelpMan getblocktemplate ()
499
511
{
500
- RPCHelpMan{" getblocktemplate" ,
512
+ return RPCHelpMan{" getblocktemplate" ,
501
513
" \n If the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n "
502
514
" It returns data needed to construct a block to work on.\n "
503
515
" For full specification, see BIPs 22, 23, 9, and 145:\n "
@@ -578,8 +590,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
578
590
HelpExampleCli (" getblocktemplate" , " '{\" rules\" : [\" segwit\" ]}'" )
579
591
+ HelpExampleRpc (" getblocktemplate" , " {\" rules\" : [\" segwit\" ]}" )
580
592
},
581
- }. Check ( request);
582
-
593
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
594
+ {
583
595
LOCK (cs_main);
584
596
585
597
std::string strMode = " template" ;
@@ -887,6 +899,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
887
899
}
888
900
889
901
return result;
902
+ },
903
+ };
890
904
}
891
905
892
906
class submitblock_StateCatcher final : public CValidationInterface
@@ -907,10 +921,10 @@ class submitblock_StateCatcher final : public CValidationInterface
907
921
}
908
922
};
909
923
910
- static UniValue submitblock (const JSONRPCRequest& request )
924
+ static RPCHelpMan submitblock ()
911
925
{
912
926
// We allow 2 arguments for compliance with BIP22. Argument 2 is ignored.
913
- RPCHelpMan{" submitblock" ,
927
+ return RPCHelpMan{" submitblock" ,
914
928
" \n Attempts to submit new block to network.\n "
915
929
" See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n " ,
916
930
{
@@ -922,8 +936,8 @@ static UniValue submitblock(const JSONRPCRequest& request)
922
936
HelpExampleCli (" submitblock" , " \" mydata\" " )
923
937
+ HelpExampleRpc (" submitblock" , " \" mydata\" " )
924
938
},
925
- }. Check ( request);
926
-
939
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
940
+ {
927
941
std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
928
942
CBlock& block = *blockptr;
929
943
if (!DecodeHexBlk (block, request.params [0 ].get_str ())) {
@@ -968,11 +982,13 @@ static UniValue submitblock(const JSONRPCRequest& request)
968
982
return " inconclusive" ;
969
983
}
970
984
return BIP22ValidationResult (sc->state );
985
+ },
986
+ };
971
987
}
972
988
973
- static UniValue submitheader (const JSONRPCRequest& request )
989
+ static RPCHelpMan submitheader ()
974
990
{
975
- RPCHelpMan{" submitheader" ,
991
+ return RPCHelpMan{" submitheader" ,
976
992
" \n Decode the given hexdata as a header and submit it as a candidate chain tip if valid."
977
993
" \n Throws when the header is invalid.\n " ,
978
994
{
@@ -984,8 +1000,8 @@ static UniValue submitheader(const JSONRPCRequest& request)
984
1000
HelpExampleCli (" submitheader" , " \" aabbcc\" " ) +
985
1001
HelpExampleRpc (" submitheader" , " \" aabbcc\" " )
986
1002
},
987
- }. Check ( request);
988
-
1003
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1004
+ {
989
1005
CBlockHeader h;
990
1006
if (!DecodeHexBlockHeader (h, request.params [0 ].get_str ())) {
991
1007
throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " Block header decode failed" );
@@ -1004,11 +1020,13 @@ static UniValue submitheader(const JSONRPCRequest& request)
1004
1020
throw JSONRPCError (RPC_VERIFY_ERROR, state.ToString ());
1005
1021
}
1006
1022
throw JSONRPCError (RPC_VERIFY_ERROR, state.GetRejectReason ());
1023
+ },
1024
+ };
1007
1025
}
1008
1026
1009
- static UniValue estimatesmartfee (const JSONRPCRequest& request )
1027
+ static RPCHelpMan estimatesmartfee ()
1010
1028
{
1011
- RPCHelpMan{" estimatesmartfee" ,
1029
+ return RPCHelpMan{" estimatesmartfee" ,
1012
1030
" \n Estimates the approximate fee per kilobyte needed for a transaction to begin\n "
1013
1031
" confirmation within conf_target blocks if possible and return the number of blocks\n "
1014
1032
" for which the estimate is valid. Uses virtual transaction size as defined\n "
@@ -1042,8 +1060,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
1042
1060
RPCExamples{
1043
1061
HelpExampleCli (" estimatesmartfee" , " 6" )
1044
1062
},
1045
- }. Check ( request);
1046
-
1063
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1064
+ {
1047
1065
RPCTypeCheck (request.params , {UniValue::VNUM, UniValue::VSTR});
1048
1066
RPCTypeCheckArgument (request.params [0 ], UniValue::VNUM);
1049
1067
unsigned int max_target = ::feeEstimator.HighestTargetTracked (FeeEstimateHorizon::LONG_HALFLIFE);
@@ -1069,11 +1087,13 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
1069
1087
}
1070
1088
result.pushKV (" blocks" , feeCalc.returnedTarget );
1071
1089
return result;
1090
+ },
1091
+ };
1072
1092
}
1073
1093
1074
- static UniValue estimaterawfee (const JSONRPCRequest& request )
1094
+ static RPCHelpMan estimaterawfee ()
1075
1095
{
1076
- RPCHelpMan{" estimaterawfee" ,
1096
+ return RPCHelpMan{" estimaterawfee" ,
1077
1097
" \n WARNING: This interface is unstable and may disappear or change!\n "
1078
1098
" \n WARNING: This is an advanced API call that is tightly coupled to the specific\n "
1079
1099
" implementation of fee estimation. The parameters it can be called with\n "
@@ -1125,8 +1145,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
1125
1145
RPCExamples{
1126
1146
HelpExampleCli (" estimaterawfee" , " 6 0.9" )
1127
1147
},
1128
- }. Check ( request);
1129
-
1148
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1149
+ {
1130
1150
RPCTypeCheck (request.params , {UniValue::VNUM, UniValue::VNUM}, true );
1131
1151
RPCTypeCheckArgument (request.params [0 ], UniValue::VNUM);
1132
1152
unsigned int max_target = ::feeEstimator.HighestTargetTracked (FeeEstimateHorizon::LONG_HALFLIFE);
@@ -1185,6 +1205,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
1185
1205
result.pushKV (StringForFeeEstimateHorizon (horizon), horizon_result);
1186
1206
}
1187
1207
return result;
1208
+ },
1209
+ };
1188
1210
}
1189
1211
1190
1212
void RegisterMiningRPCCommands (CRPCTable &t)
0 commit comments