@@ -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 "
@@ -579,8 +591,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
579
591
HelpExampleCli (" getblocktemplate" , " '{\" rules\" : [\" segwit\" ]}'" )
580
592
+ HelpExampleRpc (" getblocktemplate" , " {\" rules\" : [\" segwit\" ]}" )
581
593
},
582
- }. Check ( request);
583
-
594
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
595
+ {
584
596
LOCK (cs_main);
585
597
586
598
std::string strMode = " template" ;
@@ -888,6 +900,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
888
900
}
889
901
890
902
return result;
903
+ },
904
+ };
891
905
}
892
906
893
907
class submitblock_StateCatcher final : public CValidationInterface
@@ -908,10 +922,10 @@ class submitblock_StateCatcher final : public CValidationInterface
908
922
}
909
923
};
910
924
911
- static UniValue submitblock (const JSONRPCRequest& request )
925
+ static RPCHelpMan submitblock ()
912
926
{
913
927
// We allow 2 arguments for compliance with BIP22. Argument 2 is ignored.
914
- RPCHelpMan{" submitblock" ,
928
+ return RPCHelpMan{" submitblock" ,
915
929
" \n Attempts to submit new block to network.\n "
916
930
" See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n " ,
917
931
{
@@ -923,8 +937,8 @@ static UniValue submitblock(const JSONRPCRequest& request)
923
937
HelpExampleCli (" submitblock" , " \" mydata\" " )
924
938
+ HelpExampleRpc (" submitblock" , " \" mydata\" " )
925
939
},
926
- }. Check ( request);
927
-
940
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
941
+ {
928
942
std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
929
943
CBlock& block = *blockptr;
930
944
if (!DecodeHexBlk (block, request.params [0 ].get_str ())) {
@@ -969,11 +983,13 @@ static UniValue submitblock(const JSONRPCRequest& request)
969
983
return " inconclusive" ;
970
984
}
971
985
return BIP22ValidationResult (sc->state );
986
+ },
987
+ };
972
988
}
973
989
974
- static UniValue submitheader (const JSONRPCRequest& request )
990
+ static RPCHelpMan submitheader ()
975
991
{
976
- RPCHelpMan{" submitheader" ,
992
+ return RPCHelpMan{" submitheader" ,
977
993
" \n Decode the given hexdata as a header and submit it as a candidate chain tip if valid."
978
994
" \n Throws when the header is invalid.\n " ,
979
995
{
@@ -985,8 +1001,8 @@ static UniValue submitheader(const JSONRPCRequest& request)
985
1001
HelpExampleCli (" submitheader" , " \" aabbcc\" " ) +
986
1002
HelpExampleRpc (" submitheader" , " \" aabbcc\" " )
987
1003
},
988
- }. Check ( request);
989
-
1004
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1005
+ {
990
1006
CBlockHeader h;
991
1007
if (!DecodeHexBlockHeader (h, request.params [0 ].get_str ())) {
992
1008
throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " Block header decode failed" );
@@ -1005,11 +1021,13 @@ static UniValue submitheader(const JSONRPCRequest& request)
1005
1021
throw JSONRPCError (RPC_VERIFY_ERROR, state.ToString ());
1006
1022
}
1007
1023
throw JSONRPCError (RPC_VERIFY_ERROR, state.GetRejectReason ());
1024
+ },
1025
+ };
1008
1026
}
1009
1027
1010
- static UniValue estimatesmartfee (const JSONRPCRequest& request )
1028
+ static RPCHelpMan estimatesmartfee ()
1011
1029
{
1012
- RPCHelpMan{" estimatesmartfee" ,
1030
+ return RPCHelpMan{" estimatesmartfee" ,
1013
1031
" \n Estimates the approximate fee per kilobyte needed for a transaction to begin\n "
1014
1032
" confirmation within conf_target blocks if possible and return the number of blocks\n "
1015
1033
" for which the estimate is valid. Uses virtual transaction size as defined\n "
@@ -1043,8 +1061,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
1043
1061
RPCExamples{
1044
1062
HelpExampleCli (" estimatesmartfee" , " 6" )
1045
1063
},
1046
- }. Check ( request);
1047
-
1064
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1065
+ {
1048
1066
RPCTypeCheck (request.params , {UniValue::VNUM, UniValue::VSTR});
1049
1067
RPCTypeCheckArgument (request.params [0 ], UniValue::VNUM);
1050
1068
unsigned int max_target = ::feeEstimator.HighestTargetTracked (FeeEstimateHorizon::LONG_HALFLIFE);
@@ -1070,11 +1088,13 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
1070
1088
}
1071
1089
result.pushKV (" blocks" , feeCalc.returnedTarget );
1072
1090
return result;
1091
+ },
1092
+ };
1073
1093
}
1074
1094
1075
- static UniValue estimaterawfee (const JSONRPCRequest& request )
1095
+ static RPCHelpMan estimaterawfee ()
1076
1096
{
1077
- RPCHelpMan{" estimaterawfee" ,
1097
+ return RPCHelpMan{" estimaterawfee" ,
1078
1098
" \n WARNING: This interface is unstable and may disappear or change!\n "
1079
1099
" \n WARNING: This is an advanced API call that is tightly coupled to the specific\n "
1080
1100
" implementation of fee estimation. The parameters it can be called with\n "
@@ -1126,8 +1146,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
1126
1146
RPCExamples{
1127
1147
HelpExampleCli (" estimaterawfee" , " 6 0.9" )
1128
1148
},
1129
- }. Check ( request);
1130
-
1149
+ [&]( const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1150
+ {
1131
1151
RPCTypeCheck (request.params , {UniValue::VNUM, UniValue::VNUM}, true );
1132
1152
RPCTypeCheckArgument (request.params [0 ], UniValue::VNUM);
1133
1153
unsigned int max_target = ::feeEstimator.HighestTargetTracked (FeeEstimateHorizon::LONG_HALFLIFE);
@@ -1186,6 +1206,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
1186
1206
result.pushKV (StringForFeeEstimateHorizon (horizon), horizon_result);
1187
1207
}
1188
1208
return result;
1209
+ },
1210
+ };
1189
1211
}
1190
1212
1191
1213
void RegisterMiningRPCCommands (CRPCTable &t)
0 commit comments