@ -81,9 +81,9 @@ static UniValue GetNetworkHashPS(int lookup, int height) {
return workDiff . getdouble ( ) / timeDiff ;
}
static UniValue getnetworkhashps ( const JSONRPCRequest & request )
static RPCHelpMan getnetworkhashps ( )
{
RPCHelpMan { " getnetworkhashps " ,
return RPCHelpMan { " getnetworkhashps " ,
" \n Returns the estimated network hashes per second based on the last n blocks. \n "
" Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change. \n "
" 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)
HelpExampleCli ( " getnetworkhashps " , " " )
+ HelpExampleRpc ( " getnetworkhashps " , " " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
LOCK ( cs_main ) ;
return GetNetworkHashPS ( ! request . params [ 0 ] . isNull ( ) ? request . params [ 0 ] . get_int ( ) : 120 , ! request . params [ 1 ] . isNull ( ) ? request . params [ 1 ] . get_int ( ) : - 1 ) ;
} ,
} ;
}
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
}
}
static UniValue generatetodescriptor ( const JSONRPCRequest & request )
static RPCHelpMan generatetodescriptor ( )
{
RPCHelpMan {
return RPCHelpMan {
" generatetodescriptor " ,
" \n Mine blocks immediately to a specified descriptor (before the RPC call returns) \n " ,
{
@ -218,9 +220,8 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request)
} ,
RPCExamples {
" \n Generate 11 blocks to mydesc \n " + HelpExampleCli ( " generatetodescriptor " , " 11 \" mydesc \" " ) } ,
}
. Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
const int num_blocks { request . params [ 0 ] . get_int ( ) } ;
const uint64_t max_tries { request . params [ 2 ] . isNull ( ) ? DEFAULT_MAX_TRIES : request . params [ 2 ] . get_int ( ) } ;
@ -234,22 +235,25 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request)
ChainstateManager & chainman = EnsureChainman ( request . context ) ;
return generateBlocks ( chainman , mempool , coinbase_script , num_blocks , max_tries ) ;
} ,
} ;
}
static UniValue generate ( const JSONRPCRequest & request )
static RPCHelpMan generate ( )
{
const std : : string help_str { " generate ( nblocks maxtries ) has been replaced by the -generate cli option. Refer to -help for more information." };
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 {
if ( request . fHelp ) {
throw std : : runtime_error ( help_str ) ;
throw std : : runtime_error ( self. ToString ( ) ) ;
} else {
throw JSONRPCError ( RPC_METHOD_NOT_FOUND , help_str ) ;
throw JSONRPCError ( RPC_METHOD_NOT_FOUND , self. ToString ( ) ) ;
}
} } ;
}
static UniValue generatetoaddress ( const JSONRPCRequest & request )
static RPCHelpMan generatetoaddress ( )
{
RPCHelpMan { " generatetoaddress " ,
return RPCHelpMan { " generatetoaddress " ,
" \n Mine blocks immediately to a specified address (before the RPC call returns) \n " ,
{
{ " nblocks " , RPCArg : : Type : : NUM , RPCArg : : Optional : : NO , " How many blocks are generated immediately. " } ,
@ -267,8 +271,8 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
+ " If you are using the " PACKAGE_NAME " wallet, you can get a new address to send the newly generated bitcoin to with: \n "
+ HelpExampleCli ( " getnewaddress " , " " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
const int num_blocks { request . params [ 0 ] . get_int ( ) } ;
const uint64_t max_tries { request . params [ 2 ] . isNull ( ) ? DEFAULT_MAX_TRIES : request . params [ 2 ] . get_int ( ) } ;
@ -283,11 +287,13 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
CScript coinbase_script = GetScriptForDestination ( destination ) ;
return generateBlocks ( chainman , mempool , coinbase_script , num_blocks , max_tries ) ;
} ,
} ;
}
static UniValue generateblock ( const JSONRPCRequest & request )
static RPCHelpMan generateblock ( )
{
RPCHelpMan { " generateblock " ,
return RPCHelpMan { " generateblock " ,
" \n Mine a block with a set of ordered transactions immediately to a specified address or descriptor (before the RPC call returns) \n " ,
{
{ " 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)
" \n Generate a block to myaddress, with txs rawtx and mempool_txid \n "
+ HelpExampleCli ( " generateblock " , R " ( " myaddress " '[ " rawtx " , " mempool_txid " ]') " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
const auto address_or_descriptor = request . params [ 0 ] . get_str ( ) ;
CScript coinbase_script ;
std : : string error ;
@ -390,11 +396,13 @@ static UniValue generateblock(const JSONRPCRequest& request)
UniValue obj ( UniValue : : VOBJ ) ;
obj . pushKV ( " hash " , block_hash . GetHex ( ) ) ;
return obj ;
} ,
} ;
}
static UniValue getmininginfo ( const JSONRPCRequest & request )
static RPCHelpMan getmininginfo ( )
{
RPCHelpMan { " getmininginfo " ,
return RPCHelpMan { " getmininginfo " ,
" \n Returns a json object containing mining-related information. " ,
{ } ,
RPCResult {
@ -413,8 +421,8 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
HelpExampleCli ( " getmininginfo " , " " )
+ HelpExampleRpc ( " getmininginfo " , " " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
LOCK ( cs_main ) ;
const CTxMemPool & mempool = EnsureMemPool ( request . context ) ;
@ -423,18 +431,20 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
if ( BlockAssembler : : m_last_block_weight ) obj . pushKV ( " currentblockweight " , * BlockAssembler : : m_last_block_weight ) ;
if ( BlockAssembler : : m_last_block_num_txs ) obj . pushKV ( " currentblocktx " , * BlockAssembler : : m_last_block_num_txs ) ;
obj . pushKV ( " difficulty " , ( double ) GetDifficulty ( : : ChainActive ( ) . Tip ( ) ) ) ;
obj . pushKV ( " networkhashps " , getnetworkhashps ( request ) ) ;
obj . pushKV ( " networkhashps " , getnetworkhashps ( ) . HandleRequest ( request ) ) ;
obj . pushKV ( " pooledtx " , ( uint64_t ) mempool . size ( ) ) ;
obj . pushKV ( " chain " , Params ( ) . NetworkIDString ( ) ) ;
obj . pushKV ( " warnings " , GetWarnings ( false ) . original ) ;
return obj ;
} ,
} ;
}
// NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
static UniValue prioritisetransaction ( const JSONRPCRequest & request )
static RPCHelpMan prioritisetransaction ( )
{
RPCHelpMan { " prioritisetransaction " ,
return RPCHelpMan { " prioritisetransaction " ,
" Accepts the transaction into mined blocks at a higher (or lower) priority \n " ,
{
{ " txid " , RPCArg : : Type : : STR_HEX , RPCArg : : Optional : : NO , " The transaction id. " } ,
@ -451,8 +461,8 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
HelpExampleCli ( " prioritisetransaction " , " \" txid \" 0.0 10000 " )
+ HelpExampleRpc ( " prioritisetransaction " , " \" txid \" , 0.0, 10000 " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
LOCK ( cs_main ) ;
uint256 hash ( ParseHashV ( request . params [ 0 ] , " txid " ) ) ;
@ -464,6 +474,8 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
EnsureMemPool ( request . context ) . PrioritiseTransaction ( hash , nAmount ) ;
return true ;
} ,
} ;
}
@ -495,9 +507,9 @@ static std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
return s ;
}
static UniValue getblocktemplate ( const JSONRPCRequest & request )
static RPCHelpMan getblocktemplate ( )
{
RPCHelpMan { " getblocktemplate " ,
return RPCHelpMan { " getblocktemplate " ,
" \n If the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'. \n "
" It returns data needed to construct a block to work on. \n "
" For full specification, see BIPs 22, 23, 9, and 145: \n "
@ -579,8 +591,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
HelpExampleCli ( " getblocktemplate " , " '{ \" rules \" : [ \" segwit \" ]}' " )
+ HelpExampleRpc ( " getblocktemplate " , " { \" rules \" : [ \" segwit \" ]} " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
LOCK ( cs_main ) ;
std : : string strMode = " template " ;
@ -888,6 +900,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
}
return result ;
} ,
} ;
}
class submitblock_StateCatcher final : public CValidationInterface
@ -908,10 +922,10 @@ protected:
}
} ;
static UniValue submitblock ( const JSONRPCRequest & request )
static RPCHelpMan submitblock ( )
{
// We allow 2 arguments for compliance with BIP22. Argument 2 is ignored.
RPCHelpMan { " submitblock " ,
return RPCHelpMan { " submitblock " ,
" \n Attempts to submit new block to network. \n "
" See https://en.bitcoin.it/wiki/BIP_0022 for full specification. \n " ,
{
@ -923,8 +937,8 @@ static UniValue submitblock(const JSONRPCRequest& request)
HelpExampleCli ( " submitblock " , " \" mydata \" " )
+ HelpExampleRpc ( " submitblock " , " \" mydata \" " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
std : : shared_ptr < CBlock > blockptr = std : : make_shared < CBlock > ( ) ;
CBlock & block = * blockptr ;
if ( ! DecodeHexBlk ( block , request . params [ 0 ] . get_str ( ) ) ) {
@ -969,11 +983,13 @@ static UniValue submitblock(const JSONRPCRequest& request)
return " inconclusive " ;
}
return BIP22ValidationResult ( sc - > state ) ;
} ,
} ;
}
static UniValue submitheader ( const JSONRPCRequest & request )
static RPCHelpMan submitheader ( )
{
RPCHelpMan { " submitheader " ,
return RPCHelpMan { " submitheader " ,
" \n Decode the given hexdata as a header and submit it as a candidate chain tip if valid. "
" \n Throws when the header is invalid. \n " ,
{
@ -985,8 +1001,8 @@ static UniValue submitheader(const JSONRPCRequest& request)
HelpExampleCli ( " submitheader " , " \" aabbcc \" " ) +
HelpExampleRpc ( " submitheader " , " \" aabbcc \" " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
CBlockHeader h ;
if ( ! DecodeHexBlockHeader ( h , request . params [ 0 ] . get_str ( ) ) ) {
throw JSONRPCError ( RPC_DESERIALIZATION_ERROR , " Block header decode failed " ) ;
@ -1005,11 +1021,13 @@ static UniValue submitheader(const JSONRPCRequest& request)
throw JSONRPCError ( RPC_VERIFY_ERROR , state . ToString ( ) ) ;
}
throw JSONRPCError ( RPC_VERIFY_ERROR , state . GetRejectReason ( ) ) ;
} ,
} ;
}
static UniValue estimatesmartfee ( const JSONRPCRequest & request )
static RPCHelpMan estimatesmartfee ( )
{
RPCHelpMan { " estimatesmartfee " ,
return RPCHelpMan { " estimatesmartfee " ,
" \n Estimates the approximate fee per kilobyte needed for a transaction to begin \n "
" confirmation within conf_target blocks if possible and return the number of blocks \n "
" for which the estimate is valid. Uses virtual transaction size as defined \n "
@ -1043,8 +1061,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
RPCExamples {
HelpExampleCli ( " estimatesmartfee " , " 6 " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
RPCTypeCheck ( request . params , { UniValue : : VNUM , UniValue : : VSTR } ) ;
RPCTypeCheckArgument ( request . params [ 0 ] , UniValue : : VNUM ) ;
unsigned int max_target = : : feeEstimator . HighestTargetTracked ( FeeEstimateHorizon : : LONG_HALFLIFE ) ;
@ -1070,11 +1088,13 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
}
result . pushKV ( " blocks " , feeCalc . returnedTarget ) ;
return result ;
} ,
} ;
}
static UniValue estimaterawfee ( const JSONRPCRequest & request )
static RPCHelpMan estimaterawfee ( )
{
RPCHelpMan { " estimaterawfee " ,
return RPCHelpMan { " estimaterawfee " ,
" \n WARNING: This interface is unstable and may disappear or change! \n "
" \n WARNING: This is an advanced API call that is tightly coupled to the specific \n "
" implementation of fee estimation. The parameters it can be called with \n "
@ -1126,8 +1146,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
RPCExamples {
HelpExampleCli ( " estimaterawfee " , " 6 0.9 " )
} ,
} . Check ( request ) ;
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
RPCTypeCheck ( request . params , { UniValue : : VNUM , UniValue : : VNUM } , true ) ;
RPCTypeCheckArgument ( request . params [ 0 ] , UniValue : : VNUM ) ;
unsigned int max_target = : : feeEstimator . HighestTargetTracked ( FeeEstimateHorizon : : LONG_HALFLIFE ) ;
@ -1186,6 +1206,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
result . pushKV ( StringForFeeEstimateHorizon ( horizon ) , horizon_result ) ;
}
return result ;
} ,
} ;
}
void RegisterMiningRPCCommands ( CRPCTable & t )