mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
util: Disallow negative mocktime
Signed-off-by: practicalswift <practicalswift@users.noreply.github.com>
This commit is contained in:
parent
f5f2f97168
commit
3ddbf22ed1
3 changed files with 20 additions and 9 deletions
|
|
@ -365,13 +365,13 @@ static RPCHelpMan signmessagewithprivkey()
|
|||
static RPCHelpMan setmocktime()
|
||||
{
|
||||
return RPCHelpMan{"setmocktime",
|
||||
"\nSet the local time to given timestamp (-regtest only)\n",
|
||||
{
|
||||
{"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, UNIX_EPOCH_TIME + "\n"
|
||||
" Pass 0 to go back to using the system time."},
|
||||
},
|
||||
RPCResult{RPCResult::Type::NONE, "", ""},
|
||||
RPCExamples{""},
|
||||
"\nSet the local time to given timestamp (-regtest only)\n",
|
||||
{
|
||||
{"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, UNIX_EPOCH_TIME + "\n"
|
||||
"Pass 0 to go back to using the system time."},
|
||||
},
|
||||
RPCResult{RPCResult::Type::NONE, "", ""},
|
||||
RPCExamples{""},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
if (!Params().IsMockableChain()) {
|
||||
|
|
@ -386,7 +386,10 @@ static RPCHelpMan setmocktime()
|
|||
LOCK(cs_main);
|
||||
|
||||
RPCTypeCheck(request.params, {UniValue::VNUM});
|
||||
int64_t time = request.params[0].get_int64();
|
||||
const int64_t time{request.params[0].get_int64()};
|
||||
if (time < 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime can not be negative: %s.", time));
|
||||
}
|
||||
SetMockTime(time);
|
||||
if (request.context.Has<NodeContext>()) {
|
||||
for (const auto& chain_client : request.context.Get<NodeContext>().chain_clients) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue