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 <interfaces/chain.h> | |||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <logging.h> | #include <logging.h> | ||||
#include <node/context.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 <scheduler.h> | ||||
▲ Show 20 Lines • Show All 426 Lines • ▼ Show 20 Lines | static UniValue setmocktime(const Config &config, | ||||
// For now, don't change mocktime if we're in the middle of validation, as | // For now, don't change mocktime if we're in the middle of validation, as | ||||
// this could have an effect on mempool time-based eviction, as well as | // this could have an effect on mempool time-based eviction, as well as | ||||
// IsInitialBlockDownload(). | // IsInitialBlockDownload(). | ||||
// TODO: figure out the right way to synchronize around mocktime, and | // TODO: figure out the right way to synchronize around mocktime, and | ||||
// ensure all call sites of GetTime() are accessing this safely. | // ensure all call sites of GetTime() are accessing this safely. | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
RPCTypeCheck(request.params, {UniValue::VNUM}); | RPCTypeCheck(request.params, {UniValue::VNUM}); | ||||
int64_t mockTime = request.params[0].get_int64(); | int64_t time = request.params[0].get_int64(); | ||||
if (mockTime < 0) { | if (time < 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(time); | ||||
if (g_rpc_node) { | |||||
for (const auto &chain_client : g_rpc_node->chain_clients) { | |||||
chain_client->setMockTime(time); | |||||
} | |||||
} | |||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue mockscheduler(const Config &config, | static UniValue mockscheduler(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"mockscheduler", | "mockscheduler", | ||||
▲ Show 20 Lines • Show All 278 Lines • Show Last 20 Lines |