diff --git a/src/wallet/rpc/encrypt.cpp b/src/wallet/rpc/encrypt.cpp index 0226d15698bab8..3e3c3b87c374bb 100644 --- a/src/wallet/rpc/encrypt.cpp +++ b/src/wallet/rpc/encrypt.cpp @@ -18,7 +18,7 @@ RPCHelpMan walletpassphrase() "time that overrides the old one.\n", { {"passphrase", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet passphrase"}, - {"timeout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The time to keep the decryption key in seconds; capped at 100000000 (~3 years)."}, + {"timeout", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The time to keep the decryption key in seconds; capped at 100000000 (~3 years), will use cap if left empty"}, }, RPCResult{RPCResult::Type::NONE, "", ""}, RPCExamples{ @@ -35,7 +35,8 @@ RPCHelpMan walletpassphrase() if (!wallet) return UniValue::VNULL; CWallet* const pwallet = wallet.get(); - int64_t nSleepTime; + constexpr int64_t MAX_SLEEP_TIME = 100000000; // larger values trigger a macos/libevent bug? + int64_t nSleepTime = MAX_SLEEP_TIME; int64_t relock_time; // Prevent concurrent calls to walletpassphrase with the same wallet. LOCK(pwallet->m_unlock_mutex); @@ -51,16 +52,17 @@ RPCHelpMan walletpassphrase() strWalletPass.reserve(100); strWalletPass = std::string_view{request.params[0].get_str()}; - // Get the timeout - nSleepTime = request.params[1].getInt(); - // Timeout cannot be negative, otherwise it will relock immediately - if (nSleepTime < 0) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Timeout cannot be negative."); - } - // Clamp timeout - constexpr int64_t MAX_SLEEP_TIME = 100000000; // larger values trigger a macos/libevent bug? - if (nSleepTime > MAX_SLEEP_TIME) { - nSleepTime = MAX_SLEEP_TIME; + if(!request.params[1].isNull()){ + // Get the timeout + nSleepTime = request.params[1].getInt(); + // Timeout cannot be negative, otherwise it will relock immediately + if (nSleepTime < 0) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Timeout cannot be negative."); + } + // Clamp timeout + if (nSleepTime > MAX_SLEEP_TIME) { + nSleepTime = MAX_SLEEP_TIME; + } } if (strWalletPass.empty()) {