Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | static UniValue generatetodescriptor(const Config &config, | ||||
FlatSigningProvider provider; | FlatSigningProvider provider; | ||||
std::vector<CScript> coinbase_script; | std::vector<CScript> coinbase_script; | ||||
if (!desc->Expand(0, key_provider, coinbase_script, provider)) { | if (!desc->Expand(0, key_provider, coinbase_script, provider)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_ADDRESS_OR_KEY, | RPC_INVALID_ADDRESS_OR_KEY, | ||||
strprintf("Cannot derive script without private keys")); | strprintf("Cannot derive script without private keys")); | ||||
} | } | ||||
const CTxMemPool &mempool = EnsureMemPool(); | const CTxMemPool &mempool = EnsureMemPool(request.context); | ||||
CHECK_NONFATAL(coinbase_script.size() == 1); | CHECK_NONFATAL(coinbase_script.size() == 1); | ||||
return generateBlocks(config, mempool, coinbase_script.at(0), num_blocks, | return generateBlocks(config, mempool, coinbase_script.at(0), num_blocks, | ||||
max_tries); | max_tries); | ||||
} | } | ||||
static UniValue generatetoaddress(const Config &config, | static UniValue generatetoaddress(const Config &config, | ||||
Show All 28 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"); | ||||
} | } | ||||
const CTxMemPool &mempool = EnsureMemPool(); | const CTxMemPool &mempool = EnsureMemPool(request.context); | ||||
CScript coinbase_script = GetScriptForDestination(destination); | CScript coinbase_script = GetScriptForDestination(destination); | ||||
return generateBlocks(config, mempool, coinbase_script, nGenerate, | return generateBlocks(config, mempool, coinbase_script, nGenerate, | ||||
nMaxTries); | nMaxTries); | ||||
} | } | ||||
static UniValue getmininginfo(const Config &config, | static UniValue getmininginfo(const Config &config, | ||||
Show All 22 Lines | RPCHelpMan{ | ||||
"blockchain warnings\n" | "blockchain warnings\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("getmininginfo", "") + | RPCExamples{HelpExampleCli("getmininginfo", "") + | ||||
HelpExampleRpc("getmininginfo", "")}, | HelpExampleRpc("getmininginfo", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CTxMemPool &mempool = EnsureMemPool(); | const CTxMemPool &mempool = EnsureMemPool(request.context); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("blocks", int(::ChainActive().Height())); | obj.pushKV("blocks", int(::ChainActive().Height())); | ||||
if (BlockAssembler::m_last_block_size) { | if (BlockAssembler::m_last_block_size) { | ||||
obj.pushKV("currentblocksize", *BlockAssembler::m_last_block_size); | obj.pushKV("currentblocksize", *BlockAssembler::m_last_block_size); | ||||
} | } | ||||
if (BlockAssembler::m_last_block_num_txs) { | if (BlockAssembler::m_last_block_num_txs) { | ||||
obj.pushKV("currentblocktx", *BlockAssembler::m_last_block_num_txs); | obj.pushKV("currentblocktx", *BlockAssembler::m_last_block_num_txs); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | static UniValue prioritisetransaction(const Config &config, | ||||
Amount nAmount = request.params[2].get_int64() * SATOSHI; | Amount nAmount = request.params[2].get_int64() * SATOSHI; | ||||
if (!(request.params[1].isNull() || request.params[1].get_real() == 0)) { | if (!(request.params[1].isNull() || request.params[1].get_real() == 0)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Priority is no longer supported, dummy argument to " | "Priority is no longer supported, dummy argument to " | ||||
"prioritisetransaction must be 0."); | "prioritisetransaction must be 0."); | ||||
} | } | ||||
EnsureMemPool().PrioritiseTransaction(txid, nAmount); | EnsureMemPool(request.context).PrioritiseTransaction(txid, nAmount); | ||||
return true; | return true; | ||||
} | } | ||||
// NOTE: Assumes a conclusive result; if result is inconclusive, it must be | // NOTE: Assumes a conclusive result; if result is inconclusive, it must be | ||||
// handled by caller | // handled by caller | ||||
static UniValue BIP22ValidationResult(const Config &config, | static UniValue BIP22ValidationResult(const Config &config, | ||||
const BlockValidationState &state) { | const BlockValidationState &state) { | ||||
if (state.IsValid()) { | if (state.IsValid()) { | ||||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | if (!request.params[0].isNull()) { | ||||
return BIP22ValidationResult(config, state); | return BIP22ValidationResult(config, state); | ||||
} | } | ||||
} | } | ||||
if (strMode != "template") { | if (strMode != "template") { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); | ||||
} | } | ||||
if (!g_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!node.connman) { | |||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
if (g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0) { | if (node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0) { | ||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, | throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, | ||||
"Bitcoin is not connected!"); | "Bitcoin is not connected!"); | ||||
} | } | ||||
if (::ChainstateActive().IsInitialBlockDownload()) { | if (::ChainstateActive().IsInitialBlockDownload()) { | ||||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, PACKAGE_NAME | throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, PACKAGE_NAME | ||||
" is in initial sync and waiting for blocks..."); | " is in initial sync and waiting for blocks..."); | ||||
} | } | ||||
static unsigned int nTransactionsUpdatedLast; | static unsigned int nTransactionsUpdatedLast; | ||||
const CTxMemPool &mempool = EnsureMemPool(); | const CTxMemPool &mempool = EnsureMemPool(request.context); | ||||
if (!lpval.isNull()) { | if (!lpval.isNull()) { | ||||
// Wait to respond until either the best block changes, OR a minute has | // Wait to respond until either the best block changes, OR a minute has | ||||
// passed and there are more transactions | // passed and there are more transactions | ||||
uint256 hashWatchedChain; | uint256 hashWatchedChain; | ||||
std::chrono::steady_clock::time_point checktxtime; | std::chrono::steady_clock::time_point checktxtime; | ||||
unsigned int nTransactionsUpdatedLastLP; | unsigned int nTransactionsUpdatedLastLP; | ||||
▲ Show 20 Lines • Show All 306 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"Estimates the approximate fee per kilobyte needed for a " | "Estimates the approximate fee per kilobyte needed for a " | ||||
"transaction\n", | "transaction\n", | ||||
{}, | {}, | ||||
RPCResult{"n (numeric) estimated fee-per-kilobyte\n"}, | RPCResult{"n (numeric) estimated fee-per-kilobyte\n"}, | ||||
RPCExamples{HelpExampleCli("estimatefee", "")}, | RPCExamples{HelpExampleCli("estimatefee", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
const CTxMemPool &mempool = EnsureMemPool(); | const CTxMemPool &mempool = EnsureMemPool(request.context); | ||||
return ValueFromAmount(mempool.estimateFee().GetFeePerK()); | return ValueFromAmount(mempool.estimateFee().GetFeePerK()); | ||||
} | } | ||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ---------- ------------------------ ---------------------- ---------- | // ---------- ------------------------ ---------------------- ---------- | ||||
{"mining", "getnetworkhashps", getnetworkhashps, {"nblocks", "height"}}, | {"mining", "getnetworkhashps", getnetworkhashps, {"nblocks", "height"}}, | ||||
Show All 18 Lines |