Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show All 13 Lines | |||||
#include <core_io.h> | #include <core_io.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <miner.h> | #include <miner.h> | ||||
#include <net.h> | #include <net.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <pow.h> | #include <pow.h> | ||||
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <rpc/mining.h> | |||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <script/script.h> | |||||
#include <shutdown.h> | #include <shutdown.h> | ||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <univalue.h> | |||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/validation.h> | #include <util/validation.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <warnings.h> | #include <warnings.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
.Check(request); | .Check(request); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return GetNetworkHashPS( | return GetNetworkHashPS( | ||||
!request.params[0].isNull() ? request.params[0].get_int() : 120, | !request.params[0].isNull() ? request.params[0].get_int() : 120, | ||||
!request.params[1].isNull() ? request.params[1].get_int() : -1); | !request.params[1].isNull() ? request.params[1].get_int() : -1); | ||||
} | } | ||||
UniValue generateBlocks(const Config &config, | static UniValue generateBlocks(const Config &config, | ||||
std::shared_ptr<CReserveScript> coinbaseScript, | const CScript &coinbase_script, int nGenerate, | ||||
int nGenerate, uint64_t nMaxTries, bool keepScript) { | uint64_t nMaxTries) { | ||||
static const int nInnerLoopCount = 0x100000; | static const int nInnerLoopCount = 0x100000; | ||||
int nHeightEnd = 0; | int nHeightEnd = 0; | ||||
int nHeight = 0; | int nHeight = 0; | ||||
{ | { | ||||
// Don't keep cs_main locked. | // Don't keep cs_main locked. | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
nHeight = ::ChainActive().Height(); | nHeight = ::ChainActive().Height(); | ||||
nHeightEnd = nHeight + nGenerate; | nHeightEnd = nHeight + nGenerate; | ||||
} | } | ||||
const uint64_t nExcessiveBlockSize = config.GetMaxBlockSize(); | const uint64_t nExcessiveBlockSize = config.GetMaxBlockSize(); | ||||
unsigned int nExtraNonce = 0; | unsigned int nExtraNonce = 0; | ||||
UniValue blockHashes(UniValue::VARR); | UniValue blockHashes(UniValue::VARR); | ||||
while (nHeight < nHeightEnd && !ShutdownRequested()) { | while (nHeight < nHeightEnd && !ShutdownRequested()) { | ||||
std::unique_ptr<CBlockTemplate> pblocktemplate( | std::unique_ptr<CBlockTemplate> pblocktemplate( | ||||
BlockAssembler(config, g_mempool) | BlockAssembler(config, g_mempool).CreateNewBlock(coinbase_script)); | ||||
.CreateNewBlock(coinbaseScript->reserveScript)); | |||||
if (!pblocktemplate.get()) { | if (!pblocktemplate.get()) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); | throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); | ||||
} | } | ||||
CBlock *pblock = &pblocktemplate->block; | CBlock *pblock = &pblocktemplate->block; | ||||
{ | { | ||||
Show All 20 Lines | while (nHeight < nHeightEnd && !ShutdownRequested()) { | ||||
std::shared_ptr<const CBlock> shared_pblock = | std::shared_ptr<const CBlock> shared_pblock = | ||||
std::make_shared<const CBlock>(*pblock); | std::make_shared<const CBlock>(*pblock); | ||||
if (!ProcessNewBlock(config, shared_pblock, true, nullptr)) { | if (!ProcessNewBlock(config, shared_pblock, true, nullptr)) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, | throw JSONRPCError(RPC_INTERNAL_ERROR, | ||||
"ProcessNewBlock, block not accepted"); | "ProcessNewBlock, block not accepted"); | ||||
} | } | ||||
++nHeight; | ++nHeight; | ||||
blockHashes.push_back(pblock->GetHash().GetHex()); | blockHashes.push_back(pblock->GetHash().GetHex()); | ||||
// Mark script as important because it was used at least for one | |||||
// coinbase output if the script came from the wallet. | |||||
if (keepScript) { | |||||
coinbaseScript->KeepScript(); | |||||
} | |||||
} | } | ||||
return blockHashes; | return blockHashes; | ||||
} | } | ||||
static UniValue generatetoaddress(const Config &config, | static UniValue generatetoaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
Show All 26 Lines | static UniValue generatetoaddress(const Config &config, | ||||
CTxDestination destination = | CTxDestination destination = | ||||
DecodeDestination(request.params[1].get_str(), config.GetChainParams()); | DecodeDestination(request.params[1].get_str(), config.GetChainParams()); | ||||
if (!IsValidDestination(destination)) { | if (!IsValidDestination(destination)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Error: Invalid address"); | "Error: Invalid address"); | ||||
} | } | ||||
std::shared_ptr<CReserveScript> coinbaseScript = | CScript coinbase_script = GetScriptForDestination(destination); | ||||
std::make_shared<CReserveScript>(); | |||||
coinbaseScript->reserveScript = GetScriptForDestination(destination); | |||||
return generateBlocks(config, coinbaseScript, nGenerate, nMaxTries, false); | return generateBlocks(config, coinbase_script, nGenerate, nMaxTries); | ||||
} | } | ||||
static UniValue getmininginfo(const Config &config, | static UniValue getmininginfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getmininginfo", | "getmininginfo", | ||||
"\nReturns a json object containing mining-related " | "\nReturns a json object containing mining-related " | ||||
"information.", | "information.", | ||||
▲ Show 20 Lines • Show All 629 Lines • Show Last 20 Lines |