|
5 | 5 |
|
6 | 6 | #include <httpserver.h>
|
7 | 7 | #include <key_io.h>
|
| 8 | +#include <node/context.h> |
8 | 9 | #include <outputtype.h>
|
9 | 10 | #include <rpc/blockchain.h>
|
10 | 11 | #include <rpc/server.h>
|
11 | 12 | #include <rpc/util.h>
|
| 13 | +#include <scheduler.h> |
12 | 14 | #include <script/descriptor.h>
|
13 | 15 | #include <util/check.h>
|
14 | 16 | #include <util/strencodings.h>
|
@@ -366,6 +368,36 @@ static UniValue setmocktime(const JSONRPCRequest& request)
|
366 | 368 | return NullUniValue;
|
367 | 369 | }
|
368 | 370 |
|
| 371 | +static UniValue mockscheduler(const JSONRPCRequest& request) |
| 372 | +{ |
| 373 | + RPCHelpMan{"mockscheduler", |
| 374 | + "\nBump the scheduler into the future (-regtest only)\n", |
| 375 | + { |
| 376 | + {"delta_time", RPCArg::Type::NUM, RPCArg::Optional::NO, "Number of seconds to forward the scheduler into the future." }, |
| 377 | + }, |
| 378 | + RPCResults{}, |
| 379 | + RPCExamples{""}, |
| 380 | + }.Check(request); |
| 381 | + |
| 382 | + if (!Params().IsMockableChain()) { |
| 383 | + throw std::runtime_error("mockscheduler is for regression testing (-regtest mode) only"); |
| 384 | + } |
| 385 | + |
| 386 | + // check params are valid values |
| 387 | + RPCTypeCheck(request.params, {UniValue::VNUM}); |
| 388 | + int64_t delta_seconds = request.params[0].get_int64(); |
| 389 | + if ((delta_seconds <= 0) || (delta_seconds > 3600)) { |
| 390 | + throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)"); |
| 391 | + } |
| 392 | + |
| 393 | + // protect against null pointer dereference |
| 394 | + CHECK_NONFATAL(g_rpc_node); |
| 395 | + CHECK_NONFATAL(g_rpc_node->scheduler); |
| 396 | + g_rpc_node->scheduler->MockForward(boost::chrono::seconds(delta_seconds)); |
| 397 | + |
| 398 | + return NullUniValue; |
| 399 | +} |
| 400 | + |
369 | 401 | static UniValue RPCLockedMemoryInfo()
|
370 | 402 | {
|
371 | 403 | LockedPool::Stats stats = LockedPoolManager::Instance().stats();
|
@@ -570,6 +602,7 @@ static const CRPCCommand commands[] =
|
570 | 602 |
|
571 | 603 | /* Not shown in help */
|
572 | 604 | { "hidden", "setmocktime", &setmocktime, {"timestamp"}},
|
| 605 | + { "hidden", "mockscheduler", &mockscheduler, {"delta_time"}}, |
573 | 606 | { "hidden", "echo", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
|
574 | 607 | { "hidden", "echojson", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
|
575 | 608 | };
|
|
0 commit comments