Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show All 21 Lines | |||||
#include "util.h" | #include "util.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include "validationinterface.h" | #include "validationinterface.h" | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <memory> | #include <memory> | ||||
#include <boost/shared_ptr.hpp> | |||||
#include <univalue.h> | #include <univalue.h> | ||||
/** | /** | ||||
* Return average network hashes per second based on the last 'lookup' blocks, | * Return average network hashes per second based on the last 'lookup' blocks, | ||||
* or from the last difficulty change if 'lookup' is nonpositive. If 'height' is | * or from the last difficulty change if 'lookup' is nonpositive. If 'height' is | ||||
* nonnegative, compute the estimate at the time when a given block was found. | * nonnegative, compute the estimate at the time when a given block was found. | ||||
*/ | */ | ||||
static UniValue GetNetworkHashPS(int lookup, int height) { | static UniValue GetNetworkHashPS(int lookup, int height) { | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | static UniValue getnetworkhashps(const Config &config, | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return GetNetworkHashPS( | return GetNetworkHashPS( | ||||
request.params.size() > 0 ? request.params[0].get_int() : 120, | request.params.size() > 0 ? request.params[0].get_int() : 120, | ||||
request.params.size() > 1 ? request.params[1].get_int() : -1); | request.params.size() > 1 ? request.params[1].get_int() : -1); | ||||
} | } | ||||
static UniValue generateBlocks(const Config &config, | static UniValue generateBlocks(const Config &config, | ||||
boost::shared_ptr<CReserveScript> coinbaseScript, | std::shared_ptr<CReserveScript> coinbaseScript, | ||||
int nGenerate, uint64_t nMaxTries, | int nGenerate, uint64_t nMaxTries, | ||||
bool keepScript) { | bool keepScript) { | ||||
static const int nInnerLoopCount = 0x100000; | static const int nInnerLoopCount = 0x100000; | ||||
int nHeightStart = 0; | int nHeightStart = 0; | ||||
int nHeightEnd = 0; | int nHeightEnd = 0; | ||||
int nHeight = 0; | int nHeight = 0; | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | static UniValue generate(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
int nGenerate = request.params[0].get_int(); | int nGenerate = request.params[0].get_int(); | ||||
uint64_t nMaxTries = 1000000; | uint64_t nMaxTries = 1000000; | ||||
if (request.params.size() > 1) { | if (request.params.size() > 1) { | ||||
nMaxTries = request.params[1].get_int(); | nMaxTries = request.params[1].get_int(); | ||||
} | } | ||||
boost::shared_ptr<CReserveScript> coinbaseScript; | std::shared_ptr<CReserveScript> coinbaseScript; | ||||
GetMainSignals().ScriptForMining(coinbaseScript); | GetMainSignals().ScriptForMining(coinbaseScript); | ||||
// If the keypool is exhausted, no script is returned at all. Catch this. | // If the keypool is exhausted, no script is returned at all. Catch this. | ||||
if (!coinbaseScript) { | if (!coinbaseScript) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_KEYPOOL_RAN_OUT, | RPC_WALLET_KEYPOOL_RAN_OUT, | ||||
"Error: Keypool ran out, please call keypoolrefill first"); | "Error: Keypool ran out, please call keypoolrefill first"); | ||||
} | } | ||||
Show All 37 Lines | static UniValue generatetoaddress(const Config &config, | ||||
} | } | ||||
CBitcoinAddress address(request.params[1].get_str()); | CBitcoinAddress address(request.params[1].get_str()); | ||||
if (!address.IsValid()) { | if (!address.IsValid()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Error: Invalid address"); | "Error: Invalid address"); | ||||
} | } | ||||
boost::shared_ptr<CReserveScript> coinbaseScript(new CReserveScript()); | std::shared_ptr<CReserveScript> coinbaseScript(new CReserveScript()); | ||||
coinbaseScript->reserveScript = GetScriptForDestination(address.Get()); | coinbaseScript->reserveScript = GetScriptForDestination(address.Get()); | ||||
return generateBlocks(config, coinbaseScript, nGenerate, nMaxTries, false); | return generateBlocks(config, coinbaseScript, nGenerate, nMaxTries, false); | ||||
} | } | ||||
static UniValue getmininginfo(const Config &config, | static UniValue getmininginfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
▲ Show 20 Lines • Show All 835 Lines • Show Last 20 Lines |