Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 751 Lines • ▼ Show 20 Lines | static UniValue submitblock(const Config &config, | ||||
if (!sc.found) { | if (!sc.found) { | ||||
return "inconclusive"; | return "inconclusive"; | ||||
} | } | ||||
return BIP22ValidationResult(config, sc.state); | return BIP22ValidationResult(config, sc.state); | ||||
} | } | ||||
static UniValue submitheader(const Config &config, | |||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | |||||
throw std::runtime_error("submitheader \"hexdata\"\n" | |||||
"\nDecode the given hexdata as a header and " | |||||
"submit it as a candidate chain tip if valid." | |||||
"\nThrows when the header is invalid.\n" | |||||
"\nArguments\n" | |||||
"1. \"hexdata\" (string, required) the " | |||||
"hex-encoded block header data\n" | |||||
"\nResult:\n" | |||||
"None" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("submitheader", "\"aabbcc\"") + | |||||
HelpExampleRpc("submitheader", "\"aabbcc\"")); | |||||
} | |||||
CBlockHeader h; | |||||
if (!DecodeHexBlockHeader(h, request.params[0].get_str())) { | |||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | |||||
"Block header decode failed"); | |||||
} | |||||
{ | |||||
LOCK(cs_main); | |||||
if (!LookupBlockIndex(h.hashPrevBlock)) { | |||||
throw JSONRPCError(RPC_VERIFY_ERROR, | |||||
"Must submit previous header (" + | |||||
h.hashPrevBlock.GetHex() + ") first"); | |||||
} | |||||
} | |||||
CValidationState state; | |||||
ProcessNewBlockHeaders(config, {h}, state, /* ppindex */ nullptr, | |||||
/* first_invalid */ nullptr); | |||||
if (state.IsValid()) { | |||||
return NullUniValue; | |||||
} | |||||
if (state.IsError()) { | |||||
throw JSONRPCError(RPC_VERIFY_ERROR, FormatStateMessage(state)); | |||||
} | |||||
throw JSONRPCError(RPC_VERIFY_ERROR, state.GetRejectReason()); | |||||
} | |||||
static UniValue estimatefee(const Config &config, | static UniValue estimatefee(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 0) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"estimatefee\n" | "estimatefee\n" | ||||
"\nEstimates the approximate fee per kilobyte needed for a " | "\nEstimates the approximate fee per kilobyte needed for a " | ||||
"transaction\n" | "transaction\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
Show All 9 Lines | |||||
static const ContextFreeRPCCommand commands[] = { | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ---------- ------------------------ ---------------------- ---------- | // ---------- ------------------------ ---------------------- ---------- | ||||
{"mining", "getnetworkhashps", getnetworkhashps, {"nblocks", "height"}}, | {"mining", "getnetworkhashps", getnetworkhashps, {"nblocks", "height"}}, | ||||
{"mining", "getmininginfo", getmininginfo, {}}, | {"mining", "getmininginfo", getmininginfo, {}}, | ||||
{"mining", "prioritisetransaction", prioritisetransaction, {"txid", "priority_delta", "fee_delta"}}, | {"mining", "prioritisetransaction", prioritisetransaction, {"txid", "priority_delta", "fee_delta"}}, | ||||
{"mining", "getblocktemplate", getblocktemplate, {"template_request"}}, | {"mining", "getblocktemplate", getblocktemplate, {"template_request"}}, | ||||
{"mining", "submitblock", submitblock, {"hexdata", "dummy"}}, | {"mining", "submitblock", submitblock, {"hexdata", "dummy"}}, | ||||
{"mining", "submitheader", submitheader, {"hexdata"}}, | |||||
{"generating", "generatetoaddress", generatetoaddress, {"nblocks", "address", "maxtries"}}, | {"generating", "generatetoaddress", generatetoaddress, {"nblocks", "address", "maxtries"}}, | ||||
{"util", "estimatefee", estimatefee, {"nblocks"}}, | {"util", "estimatefee", estimatefee, {"nblocks"}}, | ||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterMiningRPCCommands(CRPCTable &t) { | void RegisterMiningRPCCommands(CRPCTable &t) { | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } |