@ -15,6 +15,7 @@
# include "policy/fees.h"
# include "policy/policy.h"
# include "policy/rbf.h"
# include "rpc/mining.h"
# include "rpc/server.h"
# include "script/sign.h"
# include "timedata.h"
@ -2922,6 +2923,51 @@ UniValue bumpfee(const JSONRPCRequest& request)
return result ;
}
UniValue generate ( const JSONRPCRequest & request )
{
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
return NullUniValue ;
}
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 2 ) {
throw std : : runtime_error (
" generate nblocks ( maxtries ) \n "
" \n Mine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet. \n "
" \n Arguments: \n "
" 1. nblocks (numeric, required) How many blocks are generated immediately. \n "
" 2. maxtries (numeric, optional) How many iterations to try (default = 1000000). \n "
" \n Result: \n "
" [ blockhashes ] (array) hashes of blocks generated \n "
" \n Examples: \n "
" \n Generate 11 blocks \n "
+ HelpExampleCli ( " generate " , " 11 " )
) ;
}
int num_generate = request . params [ 0 ] . get_int ( ) ;
uint64_t max_tries = 1000000 ;
if ( request . params . size ( ) > 1 & & ! request . params [ 1 ] . isNull ( ) ) {
max_tries = request . params [ 1 ] . get_int ( ) ;
}
std : : shared_ptr < CReserveScript > coinbase_script ;
pwallet - > GetScriptForMining ( coinbase_script ) ;
// If the keypool is exhausted, no script is returned at all. Catch this.
if ( ! coinbase_script ) {
throw JSONRPCError ( RPC_WALLET_KEYPOOL_RAN_OUT , " Error: Keypool ran out, please call keypoolrefill first " ) ;
}
//throw an error if no script was provided
if ( coinbase_script - > reserveScript . empty ( ) ) {
throw JSONRPCError ( RPC_INTERNAL_ERROR , " No coinbase script available " ) ;
}
return generateBlocks ( coinbase_script , num_generate , max_tries , true ) ;
}
extern UniValue abortrescan ( const JSONRPCRequest & request ) ; // in rpcdump.cpp
extern UniValue dumpprivkey ( const JSONRPCRequest & request ) ; // in rpcdump.cpp
extern UniValue importprivkey ( const JSONRPCRequest & request ) ;
@ -2985,6 +3031,8 @@ static const CRPCCommand commands[] =
{ " wallet " , " walletpassphrasechange " , & walletpassphrasechange , true , { " oldpassphrase " , " newpassphrase " } } ,
{ " wallet " , " walletpassphrase " , & walletpassphrase , true , { " passphrase " , " timeout " } } ,
{ " wallet " , " removeprunedfunds " , & removeprunedfunds , true , { " txid " } } ,
{ " generating " , " generate " , & generate , true , { " nblocks " , " maxtries " } } ,
} ;
void RegisterWalletRPCCommands ( CRPCTable & t )