Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/misc.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <httpserver.h> | #include <httpserver.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <logging.h> | #include <logging.h> | ||||
#include <node/context.h> | |||||
#include <outputtype.h> | #include <outputtype.h> | ||||
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <scheduler.h> | |||||
#include <script/descriptor.h> | #include <script/descriptor.h> | ||||
#include <util/check.h> | #include <util/check.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 <univalue.h> | #include <univalue.h> | ||||
▲ Show 20 Lines • Show All 418 Lines • ▼ Show 20 Lines | if (mockTime < 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Timestamp must be 0 or greater"); | "Timestamp must be 0 or greater"); | ||||
} | } | ||||
SetMockTime(mockTime); | SetMockTime(mockTime); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue mockscheduler(const Config &config, | |||||
const JSONRPCRequest &request) { | |||||
RPCHelpMan{ | |||||
"mockscheduler", | |||||
"\nBump the scheduler into the future (-regtest only)\n", | |||||
{ | |||||
{"delta_time", RPCArg::Type::NUM, RPCArg::Optional::NO, | |||||
"Number of seconds to forward the scheduler into the future."}, | |||||
}, | |||||
RPCResults{}, | |||||
RPCExamples{""}, | |||||
} | |||||
.Check(request); | |||||
if (!Params().IsMockableChain()) { | |||||
throw std::runtime_error( | |||||
"mockscheduler is for regression testing (-regtest mode) only"); | |||||
} | |||||
// check params are valid values | |||||
RPCTypeCheck(request.params, {UniValue::VNUM}); | |||||
int64_t delta_seconds = request.params[0].get_int64(); | |||||
if ((delta_seconds <= 0) || (delta_seconds > 3600)) { | |||||
throw std::runtime_error( | |||||
"delta_time must be between 1 and 3600 seconds (1 hr)"); | |||||
} | |||||
// protect against null pointer dereference | |||||
CHECK_NONFATAL(g_rpc_node); | |||||
CHECK_NONFATAL(g_rpc_node->scheduler); | |||||
g_rpc_node->scheduler->MockForward(boost::chrono::seconds(delta_seconds)); | |||||
return NullUniValue; | |||||
} | |||||
static UniValue RPCLockedMemoryInfo() { | static UniValue RPCLockedMemoryInfo() { | ||||
LockedPool::Stats stats = LockedPoolManager::Instance().stats(); | LockedPool::Stats stats = LockedPoolManager::Instance().stats(); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("used", uint64_t(stats.used)); | obj.pushKV("used", uint64_t(stats.used)); | ||||
obj.pushKV("free", uint64_t(stats.free)); | obj.pushKV("free", uint64_t(stats.free)); | ||||
obj.pushKV("total", uint64_t(stats.total)); | obj.pushKV("total", uint64_t(stats.total)); | ||||
obj.pushKV("locked", uint64_t(stats.locked)); | obj.pushKV("locked", uint64_t(stats.locked)); | ||||
obj.pushKV("chunks_used", uint64_t(stats.chunks_used)); | obj.pushKV("chunks_used", uint64_t(stats.chunks_used)); | ||||
▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | static const CRPCCommand commands[] = { | ||||
{ "control", "logging", logging, {"include", "exclude"} }, | { "control", "logging", logging, {"include", "exclude"} }, | ||||
{ "util", "validateaddress", validateaddress, {"address"} }, | { "util", "validateaddress", validateaddress, {"address"} }, | ||||
{ "util", "createmultisig", createmultisig, {"nrequired","keys"} }, | { "util", "createmultisig", createmultisig, {"nrequired","keys"} }, | ||||
{ "util", "deriveaddresses", deriveaddresses, {"descriptor", "begin", "end"} }, | { "util", "deriveaddresses", deriveaddresses, {"descriptor", "begin", "end"} }, | ||||
{ "util", "verifymessage", verifymessage, {"address","signature","message"} }, | { "util", "verifymessage", verifymessage, {"address","signature","message"} }, | ||||
{ "util", "signmessagewithprivkey", signmessagewithprivkey, {"privkey","message"} }, | { "util", "signmessagewithprivkey", signmessagewithprivkey, {"privkey","message"} }, | ||||
/* Not shown in help */ | /* Not shown in help */ | ||||
{ "hidden", "setmocktime", setmocktime, {"timestamp"}}, | { "hidden", "setmocktime", setmocktime, {"timestamp"}}, | ||||
{ "hidden", "mockscheduler", mockscheduler, {"delta_time"}}, | |||||
{ "hidden", "echo", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | { "hidden", "echo", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | ||||
{ "hidden", "echojson", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | { "hidden", "echojson", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | ||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterMiscRPCCommands(CRPCTable &t) { | void RegisterMiscRPCCommands(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]); | ||||
} | } | ||||
} | } |