diff --git a/.gitignore b/.gitignore index dd1a98f8d0de..023edd5f3498 100644 --- a/.gitignore +++ b/.gitignore @@ -49,8 +49,6 @@ src/obj share/setup.nsi share/qt/Info.plist -src/univalue/gen - src/qt/*.moc src/qt/moc_*.cpp src/qt/forms/ui_*.h diff --git a/Makefile.am b/Makefile.am index b059d0c6f7d4..ad1c903f1acb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -169,7 +169,6 @@ LCOV_FILTER_PATTERN = \ -p "src/leveldb/" \ -p "src/crc32c/" \ -p "src/bench/" \ - -p "src/univalue" \ -p "src/crypto/ctaes" \ -p "src/minisketch" \ -p "src/secp256k1" \ diff --git a/ci/lint/06_script.sh b/ci/lint/06_script.sh index 1493aa45b2fd..2912edd2dd42 100755 --- a/ci/lint/06_script.sh +++ b/ci/lint/06_script.sh @@ -26,7 +26,6 @@ export COMMIT_RANGE test/lint/git-subtree-check.sh src/crypto/ctaes test/lint/git-subtree-check.sh src/secp256k1 test/lint/git-subtree-check.sh src/minisketch -test/lint/git-subtree-check.sh src/univalue test/lint/git-subtree-check.sh src/leveldb test/lint/check-doc.py test/lint/all-lint.py diff --git a/ci/test/wrap-wine.sh b/ci/test/wrap-wine.sh index 525db9eded56..1662f8f6a335 100755 --- a/ci/test/wrap-wine.sh +++ b/ci/test/wrap-wine.sh @@ -6,7 +6,7 @@ export LC_ALL=C.UTF-8 -for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/minisketch/test{,-verify},src/univalue/{no_nul,test_json,unitester,object}}.exe; do +for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/minisketch/test{,-verify},src/univalue/{test_json,unitester,object}}.exe; do # shellcheck disable=SC2044 for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name "$(basename "$b_name")"); do if (file "$b" | grep "Windows"); then diff --git a/configure.ac b/configure.ac index c2598bd69da8..ac4bd086422d 100644 --- a/configure.ac +++ b/configure.ac @@ -450,7 +450,7 @@ if test "$enable_werror" = "yes"; then fi ERROR_CXXFLAGS=$CXXFLAG_WERROR - dnl -Warray-bounds and -Wdangling-reference cause problems with GCC. Do not treat these warnings as errors. + dnl -Warray-bounds cause problems with GCC. Do not treat these warnings as errors. dnl Suppress -Warray-bounds entirely because of noisy output, currently unhappy with immer implementation. AX_CHECK_COMPILE_FLAG([-Warray-bounds], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-array-bounds"], [], [$CXXFLAG_WERROR], [AC_LANG_SOURCE([ #if defined(__clang__) || defined(__INTEL_COMPILER) || !defined(__GNUC__) @@ -458,13 +458,6 @@ if test "$enable_werror" = "yes"; then #endif int main(void) { return 0; } ])]) - dnl TODO: Remove suppression after backporting bitcoin#27605 - AX_CHECK_COMPILE_FLAG([-Wdangling-reference], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-error=dangling-reference"], [], [$CXXFLAG_WERROR], [AC_LANG_SOURCE([ - #if defined(__clang__) || defined(__INTEL_COMPILER) || !defined(__GNUC__) - #error Non-GCC compiler detected, not setting flag - #endif - int main(void) { return 0; } - ])]) dnl -Wattributes cause problems with some versions of GCC. Do not treat these warnings as errors. AX_CHECK_COMPILE_FLAG([-Wattributes], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-error=attributes"], [], [$CXXFLAG_WERROR], [AC_LANG_SOURCE([ diff --git a/contrib/devtools/copyright_header.py b/contrib/devtools/copyright_header.py index f46f90e52d45..540e0fd5713c 100755 --- a/contrib/devtools/copyright_header.py +++ b/contrib/devtools/copyright_header.py @@ -45,7 +45,6 @@ "src/leveldb/", "src/minisketch", "src/secp256k1/", - "src/univalue/", ] INCLUDE = ['*.h', '*.cpp', '*.cc', '*.c', '*.mm', '*.py', '*.sh', '*.bash-completion'] diff --git a/doc/developer-notes.md b/doc/developer-notes.md index 91616f46bcee..9824956fe908 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -1155,10 +1155,6 @@ Current subtrees include: - src/crypto/ctaes - Upstream at https://github.com/bitcoin-core/ctaes ; maintained by Core contributors. -- src/univalue - - Subtree at https://github.com/bitcoin-core/univalue-subtree ; maintained by Core contributors. - - Deviates from upstream https://github.com/jgarzik/univalue. - - src/minisketch - Upstream at https://github.com/sipa/minisketch ; maintained by Core contributors. diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 8375969549ae..0dbd466722ee 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -405,7 +405,7 @@ endif $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check if ENABLE_TESTS -UNIVALUE_TESTS = univalue/test/object univalue/test/unitester univalue/test/no_nul +UNIVALUE_TESTS = univalue/test/object univalue/test/unitester noinst_PROGRAMS += $(UNIVALUE_TESTS) TESTS += $(UNIVALUE_TESTS) @@ -414,11 +414,6 @@ univalue_test_unitester_LDADD = $(LIBUNIVALUE) univalue_test_unitester_CPPFLAGS = -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) -DJSON_TEST_SRC=\"$(srcdir)/$(UNIVALUE_TEST_DATA_DIR_INT)\" univalue_test_unitester_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS) -univalue_test_no_nul_SOURCES = $(UNIVALUE_TEST_NO_NUL_INT) -univalue_test_no_nul_LDADD = $(LIBUNIVALUE) -univalue_test_no_nul_CPPFLAGS = -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) -univalue_test_no_nul_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS) - univalue_test_object_SOURCES = $(UNIVALUE_TEST_OBJECT_INT) univalue_test_object_LDADD = $(LIBUNIVALUE) univalue_test_object_CPPFLAGS = -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 75f9c69f434d..430ebb9257b6 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -483,7 +483,7 @@ class NetinfoRequestHandler : public BaseRequestHandler if (!batch[ID_NETWORKINFO]["error"].isNull()) return batch[ID_NETWORKINFO]; const UniValue& networkinfo{batch[ID_NETWORKINFO]["result"]}; - if (networkinfo["version"].get_int() < 200000) { + if (networkinfo["version"].getInt() < 200000) { throw std::runtime_error("-netinfo requires dashd server to be running v20.0 and up"); } const int64_t time_now{TicksSinceEpoch(CliClock::now())}; @@ -504,16 +504,16 @@ class NetinfoRequestHandler : public BaseRequestHandler if (conn_type == "manual") ++m_manual_peers_count; if (DetailsRequested()) { // Push data for this peer to the peers vector. - const int peer_id{peer["id"].get_int()}; - const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].get_int()}; - const int version{peer["version"].get_int()}; - const int64_t addr_processed{peer["addr_processed"].isNull() ? 0 : peer["addr_processed"].get_int64()}; - const int64_t addr_rate_limited{peer["addr_rate_limited"].isNull() ? 0 : peer["addr_rate_limited"].get_int64()}; - const int64_t conn_time{peer["conntime"].get_int64()}; - const int64_t last_blck{peer["last_block"].get_int64()}; - const int64_t last_recv{peer["lastrecv"].get_int64()}; - const int64_t last_send{peer["lastsend"].get_int64()}; - const int64_t last_trxn{peer["last_transaction"].get_int64()}; + const int peer_id{peer["id"].getInt()}; + const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].getInt()}; + const int version{peer["version"].getInt()}; + const int64_t addr_processed{peer["addr_processed"].isNull() ? 0 : peer["addr_processed"].getInt()}; + const int64_t addr_rate_limited{peer["addr_rate_limited"].isNull() ? 0 : peer["addr_rate_limited"].getInt()}; + const int64_t conn_time{peer["conntime"].getInt()}; + const int64_t last_blck{peer["last_block"].getInt()}; + const int64_t last_recv{peer["lastrecv"].getInt()}; + const int64_t last_send{peer["lastsend"].getInt()}; + const int64_t last_trxn{peer["last_transaction"].getInt()}; const double min_ping{peer["minping"].isNull() ? -1 : peer["minping"].get_real()}; const double ping{peer["pingtime"].isNull() ? -1 : peer["pingtime"].get_real()}; const std::string addr{peer["addr"].get_str()}; @@ -534,7 +534,7 @@ class NetinfoRequestHandler : public BaseRequestHandler } // Generate report header. - std::string result{strprintf("%s client %s%s - server %i%s\n\n", PACKAGE_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].get_int(), networkinfo["subversion"].get_str())}; + std::string result{strprintf("%s client %s%s - server %i%s\n\n", PACKAGE_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].getInt(), networkinfo["subversion"].get_str())}; // Report detailed peer connections list sorted by direction and minimum ping time. if (DetailsRequested() && !m_peers.empty()) { @@ -623,7 +623,7 @@ class NetinfoRequestHandler : public BaseRequestHandler max_addr_size = std::max(addr["address"].get_str().length() + 1, max_addr_size); } for (const UniValue& addr : local_addrs) { - result += strprintf("\n%-*s port %6i score %6i", max_addr_size, addr["address"].get_str(), addr["port"].get_int(), addr["score"].get_int()); + result += strprintf("\n%-*s port %6i score %6i", max_addr_size, addr["address"].get_str(), addr["port"].getInt(), addr["score"].getInt()); } } @@ -876,8 +876,8 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str try { response = CallRPC(rh, strMethod, args, rpcwallet); if (fWait) { - const UniValue& error = find_value(response, "error"); - if (!error.isNull() && error["code"].get_int() == RPC_IN_WARMUP) { + const UniValue& error = response.find_value("error"); + if (!error.isNull() && error["code"].getInt() == RPC_IN_WARMUP) { throw CConnectionFailed("server in warmup"); } } @@ -904,21 +904,21 @@ static void ParseResult(const UniValue& result, std::string& strPrint) static void ParseError(const UniValue& error, std::string& strPrint, int& nRet) { if (error.isObject()) { - const UniValue& err_code = find_value(error, "code"); - const UniValue& err_msg = find_value(error, "message"); + const UniValue& err_code = error.find_value("code"); + const UniValue& err_msg = error.find_value("message"); if (!err_code.isNull()) { strPrint = "error code: " + err_code.getValStr() + "\n"; } if (err_msg.isStr()) { strPrint += ("error message:\n" + err_msg.get_str()); } - if (err_code.isNum() && err_code.get_int() == RPC_WALLET_NOT_SPECIFIED) { + if (err_code.isNum() && err_code.getInt() == RPC_WALLET_NOT_SPECIFIED) { strPrint += "\nTry adding \"-rpcwallet=\" option to dash-cli command line."; } } else { strPrint = "error: " + error.write(); } - nRet = abs(error["code"].get_int()); + nRet = abs(error["code"].getInt()); } /** @@ -931,15 +931,15 @@ static void GetWalletBalances(UniValue& result) { DefaultRequestHandler rh; const UniValue listwallets = ConnectAndCallRPC(&rh, "listwallets", /* args=*/{}); - if (!find_value(listwallets, "error").isNull()) return; - const UniValue& wallets = find_value(listwallets, "result"); + if (!listwallets.find_value("error").isNull()) return; + const UniValue& wallets = listwallets.find_value("result"); if (wallets.size() <= 1) return; UniValue balances(UniValue::VOBJ); for (const UniValue& wallet : wallets.getValues()) { const std::string wallet_name = wallet.get_str(); const UniValue getbalances = ConnectAndCallRPC(&rh, "getbalances", /* args=*/{}, wallet_name); - const UniValue& balance = find_value(getbalances, "result")["mine"]["trusted"]; + const UniValue& balance = getbalances.find_value("result")["mine"]["trusted"]; balances.pushKV(wallet_name, balance); } result.pushKV("balances", balances); @@ -975,7 +975,7 @@ static void GetProgressBar(double progress, std::string& progress_bar) */ static void ParseGetInfoResult(UniValue& result) { - if (!find_value(result, "error").isNull()) return; + if (!result.find_value("error").isNull()) return; std::string RESET, GREEN, BLUE, YELLOW, MAGENTA, CYAN; bool should_colorize = false; @@ -1191,9 +1191,9 @@ static int CommandLineRPC(int argc, char *argv[]) rh.reset(new NetinfoRequestHandler()); } else if (gArgs.GetBoolArg("-generate", false)) { const UniValue getnewaddress{GetNewAddress()}; - const UniValue& error{find_value(getnewaddress, "error")}; + const UniValue& error{getnewaddress.find_value("error")}; if (error.isNull()) { - SetGenerateToAddressArgs(find_value(getnewaddress, "result").get_str(), args); + SetGenerateToAddressArgs(getnewaddress.find_value("result").get_str(), args); rh.reset(new GenerateToAddressRequestHandler()); } else { ParseError(error, strPrint, nRet); @@ -1215,8 +1215,8 @@ static int CommandLineRPC(int argc, char *argv[]) const UniValue reply = ConnectAndCallRPC(rh.get(), method, args, wallet_name); // Parse reply - UniValue result = find_value(reply, "result"); - const UniValue& error = find_value(reply, "error"); + UniValue result = reply.find_value("result"); + const UniValue& error = reply.find_value("error"); if (error.isNull()) { if (gArgs.GetBoolArg("-getinfo", false)) { if (!gArgs.IsArgSet("-rpcwallet")) { diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 93e70ed89359..e140a55617cf 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -569,7 +569,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr) throw std::runtime_error("txid must be hexadecimal string (not '" + prevOut["txid"].get_str() + "')"); } - const int nOut = prevOut["vout"].get_int(); + const int nOut = prevOut["vout"].getInt(); if (nOut < 0) throw std::runtime_error("vout cannot be negative"); diff --git a/src/coinjoin/options.cpp b/src/coinjoin/options.cpp index 3ac9234baf20..f6e3e133d0e1 100644 --- a/src/coinjoin/options.cpp +++ b/src/coinjoin/options.cpp @@ -78,11 +78,11 @@ void CCoinJoinClientOptions::GetJsonInfo(UniValue& obj) { assert(obj.isObject()); const CCoinJoinClientOptions& options = CCoinJoinClientOptions::Get(); - obj.pushKV("enabled", options.fEnableCoinJoin); - obj.pushKV("multisession", options.fCoinJoinMultiSession); - obj.pushKV("max_sessions", options.nCoinJoinSessions); - obj.pushKV("max_rounds", options.nCoinJoinRounds); - obj.pushKV("max_amount", options.nCoinJoinAmount); - obj.pushKV("denoms_goal", options.nCoinJoinDenomsGoal); - obj.pushKV("denoms_hardcap", options.nCoinJoinDenomsHardCap); + obj.pushKV("enabled", options.fEnableCoinJoin.load()); + obj.pushKV("multisession", options.fCoinJoinMultiSession.load()); + obj.pushKV("max_sessions", options.nCoinJoinSessions.load()); + obj.pushKV("max_rounds", options.nCoinJoinRounds.load()); + obj.pushKV("max_amount", options.nCoinJoinAmount.load()); + obj.pushKV("denoms_goal", options.nCoinJoinDenomsGoal.load()); + obj.pushKV("denoms_hardcap", options.nCoinJoinDenomsHardCap.load()); } diff --git a/src/core_write.cpp b/src/core_write.cpp index f57f28f5aca9..575c8c143945 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -270,7 +270,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry if (it != ptxSpentInfo->mSpentInfo.end()) { auto spentInfo = it->second; out.pushKV("spentTxId", spentInfo.m_tx_hash.GetHex()); - out.pushKV("spentIndex", (int)spentInfo.m_tx_index); + out.pushKV("spentIndex", spentInfo.m_tx_index); out.pushKV("spentHeight", spentInfo.m_block_height); } } @@ -283,7 +283,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry entry.pushKV("vout", vout); if (!tx.vExtraPayload.empty()) { - entry.pushKV("extraPayloadSize", (int)tx.vExtraPayload.size()); + entry.pushKV("extraPayloadSize", tx.vExtraPayload.size()); entry.pushKV("extraPayload", HexStr(tx.vExtraPayload)); } diff --git a/src/evo/core_write.cpp b/src/evo/core_write.cpp index 828b7938881d..e61c82d8bdc0 100644 --- a/src/evo/core_write.cpp +++ b/src/evo/core_write.cpp @@ -3,6 +3,8 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include + #include #include #include @@ -28,7 +30,7 @@ } UniValue ret(UniValue::VOBJ); - ret.pushKV("version", int(nVersion)); + ret.pushKV("version", nVersion); ret.pushKV("creditOutputs", outputs); return ret; } @@ -36,10 +38,10 @@ [[nodiscard]] UniValue CAssetUnlockPayload::ToJson() const { UniValue ret(UniValue::VOBJ); - ret.pushKV("version", int(nVersion)); - ret.pushKV("index", int(index)); - ret.pushKV("fee", int(fee)); - ret.pushKV("requestedHeight", int(requestedHeight)); + ret.pushKV("version", nVersion); + ret.pushKV("index", index); + ret.pushKV("fee", fee); + ret.pushKV("requestedHeight", requestedHeight); ret.pushKV("quorumHash", quorumHash.ToString()); ret.pushKV("quorumSig", quorumSig.ToString()); return ret; @@ -48,13 +50,13 @@ [[nodiscard]] UniValue CCbTx::ToJson() const { UniValue ret(UniValue::VOBJ); - ret.pushKV("version", (int)nVersion); + ret.pushKV("version", ToUnderlying(nVersion)); ret.pushKV("height", nHeight); ret.pushKV("merkleRootMNList", merkleRootMNList.ToString()); if (nVersion >= CCbTx::Version::MERKLE_ROOT_QUORUMS) { ret.pushKV("merkleRootQuorums", merkleRootQuorums.ToString()); if (nVersion >= CCbTx::Version::CLSIG_AND_BALANCE) { - ret.pushKV("bestCLHeightDiff", static_cast(bestCLHeightDiff)); + ret.pushKV("bestCLHeightDiff", bestCLHeightDiff); ret.pushKV("bestCLSignature", bestCLSignature.ToString()); ret.pushKV("creditPoolBalance", ValueFromAmount(creditPoolBalance)); } @@ -68,7 +70,7 @@ ret.pushKV("version", nVersion); ret.pushKV("type", ToUnderlying(nType)); ret.pushKV("collateralHash", collateralOutpoint.hash.ToString()); - ret.pushKV("collateralIndex", (int)collateralOutpoint.n); + ret.pushKV("collateralIndex", collateralOutpoint.n); if (IsServiceDeprecatedRPCEnabled()) { ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort()); } @@ -108,7 +110,7 @@ UniValue ret(UniValue::VOBJ); ret.pushKV("version", nVersion); ret.pushKV("proTxHash", proTxHash.ToString()); - ret.pushKV("reason", (int)nReason); + ret.pushKV("reason", nReason); ret.pushKV("inputsHash", inputsHash.ToString()); return ret; } @@ -138,7 +140,7 @@ [[nodiscard]] UniValue MNHFTxPayload::ToJson() const { UniValue ret(UniValue::VOBJ); - ret.pushKV("version", (int)nVersion); + ret.pushKV("version", nVersion); ret.pushKV("signal", signal.ToJson()); return ret; } @@ -146,8 +148,8 @@ [[nodiscard]] UniValue llmq::CFinalCommitmentTxPayload::ToJson() const { UniValue ret(UniValue::VOBJ); - ret.pushKV("version", int{nVersion}); - ret.pushKV("height", int(nHeight)); + ret.pushKV("version", nVersion); + ret.pushKV("height", nHeight); ret.pushKV("commitment", commitment.ToJson()); return ret; } diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 4554944b41ba..1983b34ea2cf 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -56,7 +56,7 @@ UniValue CDeterministicMN::ToJson() const obj.pushKV("type", std::string(GetMnType(nType).description)); obj.pushKV("proTxHash", proTxHash.ToString()); obj.pushKV("collateralHash", collateralOutpoint.hash.ToString()); - obj.pushKV("collateralIndex", (int)collateralOutpoint.n); + obj.pushKV("collateralIndex", collateralOutpoint.n); if (g_txindex) { CTransactionRef collateralTx; diff --git a/src/governance/classes.cpp b/src/governance/classes.cpp index 62be337be3d1..03b3c4d6ceca 100644 --- a/src/governance/classes.cpp +++ b/src/governance/classes.cpp @@ -88,12 +88,12 @@ CSuperblock::CSuperblock(const CGovernanceObject& govObj, uint256& nHash) : UniValue obj = govObj.GetJSONObject(); - if (obj["type"].get_int() != ToUnderlying(GovernanceObject::TRIGGER)) { + if (obj["type"].getInt() != ToUnderlying(GovernanceObject::TRIGGER)) { throw std::runtime_error("CSuperblock: invalid data type"); } // FIRST WE GET THE START HEIGHT, THE BLOCK HEIGHT AT WHICH THE PAYMENT SHALL OCCUR - nBlockHeight = obj["event_block_height"].get_int(); + nBlockHeight = obj["event_block_height"].getInt(); // NEXT WE GET THE PAYMENT INFORMATION AND RECONSTRUCT THE PAYMENT VECTOR std::string strAddresses = obj["payment_addresses"].get_str(); diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index d2ca46cffd74..91adfe6a9255 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -659,8 +659,8 @@ std::optional CGovernanceManager::CreateSuperblockCandidate(i // Skip proposals that are too expensive if (budgetAllocated + payment.nAmount > governanceBudget) continue; - int64_t windowStart = jproposal["start_epoch"].get_int64() - GOVERNANCE_FUDGE_WINDOW; - int64_t windowEnd = jproposal["end_epoch"].get_int64() + GOVERNANCE_FUDGE_WINDOW; + int64_t windowStart = jproposal["start_epoch"].getInt() - GOVERNANCE_FUDGE_WINDOW; + int64_t windowEnd = jproposal["end_epoch"].getInt() + GOVERNANCE_FUDGE_WINDOW; // Skip proposals if the SB isn't within the proposal time window if (SBEpochTime < windowStart) { @@ -1504,12 +1504,12 @@ UniValue CGovernanceManager::ToJson() const } UniValue jsonObj(UniValue::VOBJ); - jsonObj.pushKV("objects_total", (int)mapObjects.size()); + jsonObj.pushKV("objects_total", mapObjects.size()); jsonObj.pushKV("proposals", nProposalCount); jsonObj.pushKV("triggers", nTriggerCount); jsonObj.pushKV("other", nOtherCount); - jsonObj.pushKV("erased", (int)mapErasedGovernanceObjects.size()); - jsonObj.pushKV("votes", (int)cmapVoteToObject.GetSize()); + jsonObj.pushKV("erased", mapErasedGovernanceObjects.size()); + jsonObj.pushKV("votes", cmapVoteToObject.GetSize()); return jsonObj; } diff --git a/src/governance/object.cpp b/src/governance/object.cpp index 839d7d118f3c..41268bb8adbf 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -312,7 +312,7 @@ void CGovernanceObject::LoadData() GetData(objResult); LogPrint(BCLog::GOBJECT, "CGovernanceObject::LoadData -- GetDataAsPlainString = %s\n", GetDataAsPlainString()); UniValue obj = GetJSONObject(); - m_obj.type = GovernanceObject(obj["type"].get_int()); + m_obj.type = GovernanceObject(obj["type"].getInt()); } catch (std::exception& e) { fUnparsable = true; LogPrintf("%s\n", strprintf("CGovernanceObject::LoadData -- Error parsing JSON, e.what() = %s", e.what())); diff --git a/src/governance/validators.cpp b/src/governance/validators.cpp index 6b5cc640582d..bbe10d90439d 100644 --- a/src/governance/validators.cpp +++ b/src/governance/validators.cpp @@ -268,7 +268,7 @@ bool CProposalValidator::GetDataValue(const std::string& strKey, int64_t& nValue const UniValue uValue = objJSON[strKey]; switch (uValue.getType()) { case UniValue::VNUM: - nValueRet = uValue.get_int64(); + nValueRet = uValue.getInt(); fOK = true; break; default: diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 42ce94c3190c..22c1be063a8b 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -116,7 +116,7 @@ static bool JSONErrorReply(RpcHttpRequest& rpcRequest, const UniValue& objError, { // Send error reply from json-rpc error object int nStatus = HTTP_INTERNAL_SERVER_ERROR; - int code = find_value(objError, "code").get_int(); + int code = objError.find_value("code").getInt(); if (code == RPC_INVALID_REQUEST) nStatus = HTTP_BAD_REQUEST; @@ -253,7 +253,7 @@ static bool HTTPReq_JSONRPC(const CoreContext& context, HTTPRequest* req) } else { const UniValue& request = valRequest[reqIdx].get_obj(); // Parse method - std::string strMethod = find_value(request, "method").get_str(); + std::string strMethod = request.find_value("method").get_str(); if (!whitelisted(jreq)) { LogPrintf("RPC User %s not allowed to call method %s\n", jreq.authUser, strMethod); return rpcRequest.send_reply(HTTP_FORBIDDEN); diff --git a/src/llmq/commitment.h b/src/llmq/commitment.h index ca55131c9665..1569e59694fc 100644 --- a/src/llmq/commitment.h +++ b/src/llmq/commitment.h @@ -122,7 +122,7 @@ class CFinalCommitment [[nodiscard]] UniValue ToJson() const { UniValue obj(UniValue::VOBJ); - obj.pushKV("version", int{nVersion}); + obj.pushKV("version", nVersion); obj.pushKV("llmqType", ToUnderlying(llmqType)); obj.pushKV("quorumHash", quorumHash.ToString()); obj.pushKV("quorumIndex", quorumIndex); diff --git a/src/masternode/meta.cpp b/src/masternode/meta.cpp index 3cc3ffbb5932..3610d0d23db9 100644 --- a/src/masternode/meta.cpp +++ b/src/masternode/meta.cpp @@ -36,13 +36,13 @@ UniValue CMasternodeMetaInfo::ToJson() const int64_t now = GetTime().count(); - ret.pushKV("lastDSQ", nLastDsq); - ret.pushKV("mixingTxCount", nMixingTxCount); - ret.pushKV("outboundAttemptCount", outboundAttemptCount); - ret.pushKV("lastOutboundAttempt", lastOutboundAttempt); - ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt); - ret.pushKV("lastOutboundSuccess", lastOutboundSuccess); - ret.pushKV("lastOutboundSuccessElapsed", now - lastOutboundSuccess); + ret.pushKV("lastDSQ", nLastDsq.load()); + ret.pushKV("mixingTxCount", nMixingTxCount.load()); + ret.pushKV("outboundAttemptCount", outboundAttemptCount.load()); + ret.pushKV("lastOutboundAttempt", lastOutboundAttempt.load()); + ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt.load()); + ret.pushKV("lastOutboundSuccess", lastOutboundSuccess.load()); + ret.pushKV("lastOutboundSuccessElapsed", now - lastOutboundSuccess.load()); return ret; } diff --git a/src/net_types.cpp b/src/net_types.cpp index cdde5221fc77..9407ff8e68ba 100644 --- a/src/net_types.cpp +++ b/src/net_types.cpp @@ -12,9 +12,9 @@ static const char* BANMAN_JSON_VERSION_KEY{"version"}; CBanEntry::CBanEntry(const UniValue& json) - : nVersion(json[BANMAN_JSON_VERSION_KEY].get_int()), - nCreateTime(json["ban_created"].get_int64()), - nBanUntil(json["banned_until"].get_int64()) + : nVersion(json[BANMAN_JSON_VERSION_KEY].getInt()), + nCreateTime(json["ban_created"].getInt()), + nBanUntil(json["banned_until"].getInt()) { } @@ -58,7 +58,7 @@ UniValue BanMapToJson(const banmap_t& bans) void BanMapFromJson(const UniValue& bans_json, banmap_t& bans) { for (const auto& ban_entry_json : bans_json.getValues()) { - const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].get_int()}; + const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].getInt()}; if (version != CBanEntry::CURRENT_VERSION) { LogPrintf("Dropping entry with unknown version (%s) from ban list\n", version); continue; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index b9b96e18082c..493c8606c86c 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -698,7 +698,7 @@ class RpcHandlerImpl : public Handler // try to handle the request. Otherwise, reraise the exception. if (!last_handler) { const UniValue& code = e["code"]; - if (code.isNum() && code.get_int() == RPC_WALLET_NOT_FOUND) { + if (code.isNum() && code.getInt() == RPC_WALLET_NOT_FOUND) { return false; } } diff --git a/src/qt/governancelist.cpp b/src/qt/governancelist.cpp index 157690e24733..c001a03de796 100644 --- a/src/qt/governancelist.cpp +++ b/src/qt/governancelist.cpp @@ -45,23 +45,23 @@ Proposal::Proposal(ClientModel* _clientModel, const CGovernanceObject& _govObj, { UniValue prop_data; if (prop_data.read(govObj.GetDataAsPlainString())) { - if (UniValue titleValue = find_value(prop_data, "name"); titleValue.isStr()) { + if (UniValue titleValue = prop_data.find_value("name"); titleValue.isStr()) { m_title = QString::fromStdString(titleValue.get_str()); } - if (UniValue paymentStartValue = find_value(prop_data, "start_epoch"); paymentStartValue.isNum()) { - m_startDate = QDateTime::fromSecsSinceEpoch(paymentStartValue.get_int64()); + if (UniValue paymentStartValue = prop_data.find_value("start_epoch"); paymentStartValue.isNum()) { + m_startDate = QDateTime::fromSecsSinceEpoch(paymentStartValue.getInt()); } - if (UniValue paymentEndValue = find_value(prop_data, "end_epoch"); paymentEndValue.isNum()) { - m_endDate = QDateTime::fromSecsSinceEpoch(paymentEndValue.get_int64()); + if (UniValue paymentEndValue = prop_data.find_value("end_epoch"); paymentEndValue.isNum()) { + m_endDate = QDateTime::fromSecsSinceEpoch(paymentEndValue.getInt()); } - if (UniValue amountValue = find_value(prop_data, "payment_amount"); amountValue.isNum()) { + if (UniValue amountValue = prop_data.find_value("payment_amount"); amountValue.isNum()) { m_paymentAmount = amountValue.get_real(); } - if (UniValue urlValue = find_value(prop_data, "url"); urlValue.isStr()) { + if (UniValue urlValue = prop_data.find_value("url"); urlValue.isStr()) { m_url = QString::fromStdString(urlValue.get_str()); } } diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index a44190ff71b1..74a59ff04035 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -261,7 +261,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes subelement = lastResult[parsed.value()]; } else if (lastResult.isObject()) - subelement = find_value(lastResult, curarg); + subelement = lastResult.find_value(curarg); else throw std::runtime_error("Invalid result query"); //no array or object: abort lastResult = subelement; @@ -460,8 +460,8 @@ void RPCExecutor::request(const QString &command, const WalletModel* wallet_mode { try // Nice formatting for standard-format error { - int code = find_value(objError, "code").get_int(); - std::string message = find_value(objError, "message").get_str(); + int code = objError.find_value("code").getInt(); + std::string message = objError.find_value("message").get_str(); Q_EMIT reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")"); } catch (const std::runtime_error&) // raised when converting to invalid type, i.e. missing code or message diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index dd08f585103b..582b4adb3722 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -108,7 +108,7 @@ static const CBlockIndex* ParseHashOrHeight(const UniValue& param, ChainstateMan CChain& active_chain = chainman.ActiveChain(); if (param.isNum()) { - const int height{param.get_int()}; + const int height{param.getInt()}; if (height < 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Target block height %d is negative", height)); } @@ -326,7 +326,7 @@ static RPCHelpMan waitfornewblock() { int timeout = 0; if (!request.params[0].isNull()) - timeout = request.params[0].get_int(); + timeout = request.params[0].getInt(); CUpdatedBlock block; { @@ -372,7 +372,7 @@ static RPCHelpMan waitforblock() uint256 hash(ParseHashV(request.params[0], "blockhash")); if (!request.params[1].isNull()) - timeout = request.params[1].get_int(); + timeout = request.params[1].getInt(); CUpdatedBlock block; { @@ -416,10 +416,10 @@ static RPCHelpMan waitforblockheight() { int timeout = 0; - int height = request.params[0].get_int(); + int height = request.params[0].getInt(); if (!request.params[1].isNull()) - timeout = request.params[1].get_int(); + timeout = request.params[1].getInt(); CUpdatedBlock block; { @@ -506,7 +506,7 @@ static RPCHelpMan getblockfrompeer() PeerManager& peerman = EnsurePeerman(node); const uint256& block_hash{ParseHashV(request.params[0], "blockhash")}; - const NodeId peer_id{request.params[1].get_int64()}; + const NodeId peer_id{request.params[1].getInt()}; const CBlockIndex* const index = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(block_hash);); @@ -543,8 +543,8 @@ static RPCHelpMan getblockhashes() }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - unsigned int high = request.params[0].get_int(); - unsigned int low = request.params[1].get_int(); + unsigned int high = request.params[0].getInt(); + unsigned int low = request.params[1].getInt(); std::vector blockHashes; ChainstateManager& chainman = EnsureAnyChainman(request.context); @@ -581,7 +581,7 @@ static RPCHelpMan getblockhash() LOCK(cs_main); const CChain& active_chain = chainman.ActiveChain(); - int nHeight = request.params[0].get_int(); + int nHeight = request.params[0].getInt(); if (nHeight < 0 || nHeight > active_chain.Height()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); @@ -732,7 +732,7 @@ static RPCHelpMan getblockheaders() int nCount = MAX_HEADERS_UNCOMPRESSED_RESULT; if (!request.params[1].isNull()) - nCount = request.params[1].get_int(); + nCount = request.params[1].getInt(); if (nCount <= 0 || nCount > (int)MAX_HEADERS_UNCOMPRESSED_RESULT) throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range"); @@ -849,7 +849,7 @@ static RPCHelpMan getmerkleblocks() int nCount = MAX_HEADERS_UNCOMPRESSED_RESULT; if (!request.params[2].isNull()) - nCount = request.params[2].get_int(); + nCount = request.params[2].getInt(); if (nCount <= 0 || nCount > (int)MAX_HEADERS_UNCOMPRESSED_RESULT) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range"); @@ -988,7 +988,7 @@ static RPCHelpMan getblock() if (request.params[1].isBool()) { verbosity = request.params[1].get_bool() ? 1 : 0; } else { - verbosity = request.params[1].get_int(); + verbosity = request.params[1].getInt(); } } @@ -1055,7 +1055,7 @@ static RPCHelpMan pruneblockchain() CChainState& active_chainstate = chainman.ActiveChainstate(); CChain& active_chain = active_chainstate.m_chain; - int heightParam = request.params[0].get_int(); + int heightParam = request.params[0].getInt(); if (heightParam < 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative block height."); } @@ -1294,7 +1294,7 @@ static RPCHelpMan gettxout() UniValue ret(UniValue::VOBJ); uint256 hash(ParseHashV(request.params[0], "txid")); - int n = request.params[1].get_int(); + int n = request.params[1].getInt(); COutPoint out(hash, n); bool fMempool = true; if (!request.params[2].isNull()) @@ -1351,8 +1351,8 @@ static RPCHelpMan verifychain() }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - const int check_level{request.params[0].isNull() ? DEFAULT_CHECKLEVEL : request.params[0].get_int()}; - const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].get_int()}; + const int check_level{request.params[0].isNull() ? DEFAULT_CHECKLEVEL : request.params[0].getInt()}; + const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].getInt()}; const NodeContext& node = EnsureAnyNodeContext(request.context); @@ -1650,8 +1650,8 @@ static RPCHelpMan getchaintips() // Always report the currently active tip. setTips.insert(active_chain.Tip()); - int nCountMax{request.params[0].isNull() ? INT_MAX : request.params[0].get_int()}; - const int nBranchMin{request.params[1].isNull() ? -1: request.params[1].get_int()}; + int nCountMax{request.params[0].isNull() ? INT_MAX : request.params[0].getInt()}; + const int nBranchMin{request.params[1].isNull() ? -1: request.params[1].getInt()}; /* Construct the output array. */ UniValue res(UniValue::VARR); @@ -1883,7 +1883,7 @@ static RPCHelpMan getchaintxstats() if (request.params[0].isNull()) { blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1)); } else { - blockcount = request.params[0].get_int(); + blockcount = request.params[0].getInt(); if (blockcount < 0 || (blockcount > 0 && blockcount >= pindex->nHeight)) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 0 and the block's height - 1"); @@ -2252,26 +2252,26 @@ static RPCHelpMan getspecialtxes() int nTxType = -1; if (!request.params[1].isNull()) { - nTxType = request.params[1].get_int(); + nTxType = request.params[1].getInt(); } int nCount = 10; if (!request.params[2].isNull()) { - nCount = request.params[2].get_int(); + nCount = request.params[2].getInt(); if (nCount < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count"); } int nSkip = 0; if (!request.params[3].isNull()) { - nSkip = request.params[3].get_int(); + nSkip = request.params[3].getInt(); if (nSkip < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative skip"); } int nVerbosity = 0; if (!request.params[4].isNull()) { - nVerbosity = request.params[4].get_int(); + nVerbosity = request.params[4].getInt(); if (nVerbosity < 0 || nVerbosity > 2) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Verbosity must be in range 0..2"); } @@ -2461,7 +2461,7 @@ static RPCHelpMan scantxoutset() // no scan in progress return NullUniValue; } - result.pushKV("progress", g_scan_progress); + result.pushKV("progress", g_scan_progress.load()); return result; } else if (request.params[0].get_str() == "abort") { CoinsViewScanReserver reserver; diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index ab433de19eb0..eeb75eba835d 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -5,9 +5,12 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include +#include +#include class CRPCConvertParam { @@ -262,15 +265,15 @@ class CRPCConvertTable CRPCConvertTable(); /** Return arg_value as UniValue, and first parse it if it is a non-string parameter */ - UniValue ArgToUniValue(const std::string& arg_value, const std::string& method, int param_idx) + UniValue ArgToUniValue(std::string_view arg_value, const std::string& method, int param_idx) { - return members.count(std::make_pair(method, param_idx)) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; + return members.count({method, param_idx}) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; } /** Return arg_value as UniValue, and first parse it if it is a non-string parameter */ - UniValue ArgToUniValue(const std::string& arg_value, const std::string& method, const std::string& param_name) + UniValue ArgToUniValue(std::string_view arg_value, const std::string& method, const std::string& param_name) { - return membersByName.count(std::make_pair(method, param_name)) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; + return membersByName.count({method, param_name}) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; } }; @@ -287,13 +290,11 @@ static CRPCConvertTable rpcCvtTable; /** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null) * as well as objects and arrays. */ -UniValue ParseNonRFCJSONValue(const std::string& strVal) +UniValue ParseNonRFCJSONValue(std::string_view raw) { - UniValue jVal; - if (!jVal.read(std::string("[")+strVal+std::string("]")) || - !jVal.isArray() || jVal.size()!=1) - throw std::runtime_error(std::string("Error parsing JSON: ") + strVal); - return jVal[0]; + UniValue parsed; + if (!parsed.read(raw)) throw std::runtime_error(tfm::format("Error parsing JSON: %s", raw)); + return parsed; } UniValue RPCConvertValues(const std::string &strMethod, const std::vector &strParams) @@ -301,8 +302,8 @@ UniValue RPCConvertValues(const std::string &strMethod, const std::vector +#include + #include /** Convert positional arguments to command-specific RPC representation */ @@ -17,6 +20,6 @@ UniValue RPCConvertNamedValues(const std::string& strMethod, const std::vector UniValue { uint256 hashMnCollateralTx(ParseHashV(request.params[0], "mn collateral tx hash")); - int nMnCollateralTxIndex = request.params[1].get_int(); + int nMnCollateralTxIndex = request.params[1].getInt(); COutPoint outpoint = COutPoint(hashMnCollateralTx, nMnCollateralTxIndex); uint256 hashGovObj(ParseHashV(request.params[2], "Governance hash")); @@ -939,7 +939,7 @@ static RPCHelpMan voteraw() }(); - int64_t nTime = request.params[5].get_int64(); + int64_t nTime = request.params[5].getInt(); std::string strSig = request.params[6].get_str(); auto opt_vchSig = DecodeBase64(strSig); @@ -1018,7 +1018,7 @@ static RPCHelpMan getgovernanceinfo() obj.pushKV("superblockmaturitywindow", Params().GetConsensus().nSuperblockMaturityWindow); obj.pushKV("lastsuperblock", nLastSuperblock); obj.pushKV("nextsuperblock", nNextSuperblock); - obj.pushKV("fundingthreshold", int(CHECK_NONFATAL(node.dmnman)->GetListAtChainTip().GetValidWeightedMNsCount() / 10)); + obj.pushKV("fundingthreshold", CHECK_NONFATAL(node.dmnman)->GetListAtChainTip().GetValidWeightedMNsCount() / 10); obj.pushKV("governancebudget", ValueFromAmount(CSuperblock::GetPaymentsLimit(chainman.ActiveChain(), nNextSuperblock))); return obj; @@ -1042,7 +1042,7 @@ static RPCHelpMan getsuperblockbudget() }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - int nBlockHeight = request.params[0].get_int(); + int nBlockHeight = request.params[0].getInt(); if (nBlockHeight < 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); } diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 266845d3e90d..46131ea785a0 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -180,7 +180,7 @@ static RPCHelpMan masternode_status() mnObj.pushKV("proTxHash", dmn->proTxHash.ToString()); mnObj.pushKV("type", std::string(GetMnType(dmn->nType).description)); mnObj.pushKV("collateralHash", dmn->collateralOutpoint.hash.ToString()); - mnObj.pushKV("collateralIndex", (int)dmn->collateralOutpoint.n); + mnObj.pushKV("collateralIndex", dmn->collateralOutpoint.n); mnObj.pushKV("dmnState", dmn->pdmnState->ToJson(dmn->nType)); } mnObj.pushKV("state", node.mn_activeman->GetStateString()); diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp index 1e3d67c3ea70..ab527f39f824 100644 --- a/src/rpc/mempool.cpp +++ b/src/rpc/mempool.cpp @@ -395,8 +395,8 @@ UniValue MempoolInfoToJSON(const CTxMemPool& pool, const llmq::CInstantSendManag ret.pushKV("maxmempool", maxmempool); ret.pushKV("mempoolminfee", ValueFromAmount(std::max(pool.GetMinFee(maxmempool), ::minRelayTxFee).GetFeePerK())); ret.pushKV("minrelaytxfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())); - ret.pushKV("instantsendlocks", (int64_t)isman.GetInstantSendLockCount()); - ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()}); + ret.pushKV("instantsendlocks", isman.GetInstantSendLockCount()); + ret.pushKV("unbroadcastcount", pool.GetUnbroadcastTxs().size()); return ret; } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 5f498d654cb0..ec3723e1d9bd 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -120,7 +120,7 @@ static RPCHelpMan getnetworkhashps() ChainstateManager& chainman = EnsureAnyChainman(request.context); LOCK(cs_main); - return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1, chainman.ActiveChain()); + return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].getInt() : 120, !request.params[1].isNull() ? request.params[1].getInt() : -1, chainman.ActiveChain()); }, }; } @@ -232,8 +232,8 @@ static RPCHelpMan generatetodescriptor() "\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")}, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - const int num_blocks{request.params[0].get_int()}; - const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()}; + const int num_blocks{request.params[0].getInt()}; + const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].getInt()}; CScript coinbase_script; std::string error; @@ -271,8 +271,8 @@ static RPCHelpMan generatetoaddress() + HelpExampleCli("getnewaddress", "")}, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - const int num_blocks{request.params[0].get_int()}; - const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()}; + const int num_blocks{request.params[0].getInt()}; + const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].getInt()}; CTxDestination destination = DecodeDestination(request.params[1].get_str()); if (!IsValidDestination(destination)) { @@ -503,7 +503,7 @@ static RPCHelpMan prioritisetransaction() LOCK(cs_main); uint256 hash(ParseHashV(request.params[0].get_str(), "txid")); - CAmount nAmount = request.params[1].get_int64(); + CAmount nAmount = request.params[1].getInt(); EnsureAnyMemPool(request.context).PrioritiseTransaction(hash, nAmount); return true; @@ -668,7 +668,7 @@ static RPCHelpMan getblocktemplate() if (!request.params[0].isNull()) { const UniValue& oparam = request.params[0].get_obj(); - const UniValue& modeval = find_value(oparam, "mode"); + const UniValue& modeval = oparam.find_value("mode"); if (modeval.isStr()) strMode = modeval.get_str(); else if (modeval.isNull()) @@ -677,11 +677,11 @@ static RPCHelpMan getblocktemplate() } else throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); - lpval = find_value(oparam, "longpollid"); + lpval = oparam.find_value("longpollid"); if (strMode == "proposal") { - const UniValue& dataval = find_value(oparam, "data"); + const UniValue& dataval = oparam.find_value("data"); if (!dataval.isStr()) throw JSONRPCError(RPC_TYPE_ERROR, "Missing data String key for proposal"); @@ -711,7 +711,7 @@ static RPCHelpMan getblocktemplate() return BIP22ValidationResult(state); } - const UniValue& aClientRules = find_value(oparam, "rules"); + const UniValue& aClientRules = oparam.find_value("rules"); if (aClientRules.isArray()) { for (unsigned int i = 0; i < aClientRules.size(); ++i) { const UniValue& v = aClientRules[i]; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 95cdfdf6cb11..6cb93c9c534d 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -66,7 +66,7 @@ static RPCHelpMan getconnectioncount() const NodeContext& node = EnsureAnyNodeContext(request.context); const CConnman& connman = EnsureConnman(node); - return (int)connman.GetNodeCount(ConnectionDirection::Both); + return connman.GetNodeCount(ConnectionDirection::Both); }, }; } @@ -450,7 +450,7 @@ static RPCHelpMan disconnectnode() success = connman.DisconnectNode(address_arg.get_str()); } else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) { /* handle disconnect-by-id */ - NodeId nodeid = (NodeId) id_arg.get_int64(); + NodeId nodeid = (NodeId) id_arg.getInt(); success = connman.DisconnectNode(nodeid); } else { throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided."); @@ -684,12 +684,12 @@ static RPCHelpMan getnetworkinfo() obj.pushKV("timeoffset", GetTimeOffset()); if (node.connman) { obj.pushKV("networkactive", node.connman->GetNetworkActive()); - obj.pushKV("connections", (int)node.connman->GetNodeCount(ConnectionDirection::Both)); - obj.pushKV("connections_in", (int)node.connman->GetNodeCount(ConnectionDirection::In)); - obj.pushKV("connections_out", (int)node.connman->GetNodeCount(ConnectionDirection::Out)); - obj.pushKV("connections_mn", (int)node.connman->GetNodeCount(ConnectionDirection::Verified)); - obj.pushKV("connections_mn_in", (int)node.connman->GetNodeCount(ConnectionDirection::VerifiedIn)); - obj.pushKV("connections_mn_out", (int)node.connman->GetNodeCount(ConnectionDirection::VerifiedOut)); + obj.pushKV("connections", node.connman->GetNodeCount(ConnectionDirection::Both)); + obj.pushKV("connections_in", node.connman->GetNodeCount(ConnectionDirection::In)); + obj.pushKV("connections_out", node.connman->GetNodeCount(ConnectionDirection::Out)); + obj.pushKV("connections_mn", node.connman->GetNodeCount(ConnectionDirection::Verified)); + obj.pushKV("connections_mn_in", node.connman->GetNodeCount(ConnectionDirection::VerifiedIn)); + obj.pushKV("connections_mn_out", node.connman->GetNodeCount(ConnectionDirection::VerifiedOut)); std::string_view sem_str = SEMToString(node.connman->GetSocketEventsMode()); CHECK_NONFATAL(sem_str != "unknown"); obj.pushKV("socketevents", std::string(sem_str)); @@ -772,7 +772,7 @@ static RPCHelpMan setban() int64_t banTime = 0; //use standard bantime if not specified if (!request.params[2].isNull()) - banTime = request.params[2].get_int64(); + banTime = request.params[2].getInt(); bool absolute = false; if (request.params[3].isTrue()) @@ -957,7 +957,7 @@ static RPCHelpMan getnodeaddresses() const NodeContext& node = EnsureAnyNodeContext(request.context); const CConnman& connman = EnsureConnman(node); - const int count{request.params[0].isNull() ? 1 : request.params[0].get_int()}; + const int count{request.params[0].isNull() ? 1 : request.params[0].getInt()}; if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range"); const std::optional network{request.params[1].isNull() ? std::nullopt : std::optional{ParseNetwork(request.params[1].get_str())}}; @@ -1011,7 +1011,7 @@ static RPCHelpMan addpeeraddress() } const std::string& addr_string{request.params[0].get_str()}; - const uint16_t port = request.params[1].get_int(); + const uint16_t port = request.params[1].getInt(); const bool tried{request.params[2].isTrue()}; UniValue obj(UniValue::VOBJ); @@ -1055,7 +1055,7 @@ static RPCHelpMan sendmsgtopeer() RPCExamples{ HelpExampleCli("sendmsgtopeer", "0 \"addr\" \"ffffff\"") + HelpExampleRpc("sendmsgtopeer", "0 \"addr\" \"ffffff\"")}, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - const NodeId peer_id{request.params[0].get_int()}; + const NodeId peer_id{request.params[0].getInt()}; const std::string& msg_type{request.params[1].get_str()}; if (msg_type.size() > CMessageHeader::COMMAND_SIZE) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Error: msg_type too long, max length is %i", CMessageHeader::COMMAND_SIZE)); diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp index 10d76dc99efb..0e9d6dd023ee 100644 --- a/src/rpc/node.cpp +++ b/src/rpc/node.cpp @@ -224,7 +224,7 @@ static RPCHelpMan sporkupdate() CHECK_NONFATAL(node.sporkman); // SPORK VALUE - int64_t nValue = request.params[1].get_int64(); + int64_t nValue = request.params[1].getInt(); // broadcast new spork if (node.sporkman->UpdateSpork(peerman, nSporkID, nValue)) { @@ -261,7 +261,7 @@ static RPCHelpMan setmocktime() LOCK(cs_main); RPCTypeCheck(request.params, {UniValue::VNUM}); - const int64_t time{request.params[0].get_int64()}; + const int64_t time{request.params[0].getInt()}; if (time < 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time)); } @@ -296,7 +296,7 @@ static RPCHelpMan mnauth() if (!Params().MineBlocksOnDemand()) throw std::runtime_error("mnauth for regression testing (-regtest mode) only"); - int64_t nodeId = request.params[0].get_int64(); + int64_t nodeId = request.params[0].getInt(); uint256 proTxHash = ParseHashV(request.params[1], "proTxHash"); if (proTxHash.IsNull()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "proTxHash invalid"); @@ -357,7 +357,7 @@ static bool getAddressesFromParams(const UniValue& params, std::vector UniValue { - UniValue startValue = find_value(request.params[0].get_obj(), "start"); - UniValue endValue = find_value(request.params[0].get_obj(), "end"); + UniValue startValue = request.params[0].get_obj().find_value("start"); + UniValue endValue = request.params[0].get_obj().find_value("end"); int start = 0; int end = 0; if (startValue.isNum() && endValue.isNum()) { - start = startValue.get_int(); - end = endValue.get_int(); + start = startValue.getInt(); + end = endValue.getInt(); if (end < start) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "End value is expected to be greater than start"); } @@ -596,8 +596,8 @@ static RPCHelpMan getaddressdeltas() UniValue delta(UniValue::VOBJ); delta.pushKV("satoshis", indexDelta); delta.pushKV("txid", indexKey.m_tx_hash.GetHex()); - delta.pushKV("index", (int)indexKey.m_tx_index); - delta.pushKV("blockindex", (int)indexKey.m_block_tx_pos); + delta.pushKV("index", indexKey.m_tx_index); + delta.pushKV("blockindex", indexKey.m_block_tx_pos); delta.pushKV("height", indexKey.m_block_height); delta.pushKV("address", address); result.push_back(delta); @@ -715,11 +715,11 @@ static RPCHelpMan getaddresstxids() int start = 0; int end = 0; if (request.params[0].isObject()) { - UniValue startValue = find_value(request.params[0].get_obj(), "start"); - UniValue endValue = find_value(request.params[0].get_obj(), "end"); + UniValue startValue = request.params[0].get_obj().find_value("start"); + UniValue endValue = request.params[0].get_obj().find_value("end"); if (startValue.isNum() && endValue.isNum()) { - start = startValue.get_int(); - end = endValue.get_int(); + start = startValue.getInt(); + end = endValue.getInt(); } } @@ -789,15 +789,15 @@ static RPCHelpMan getspentinfo() }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - UniValue txidValue = find_value(request.params[0].get_obj(), "txid"); - UniValue indexValue = find_value(request.params[0].get_obj(), "index"); + UniValue txidValue = request.params[0].get_obj().find_value("txid"); + UniValue indexValue = request.params[0].get_obj().find_value("index"); if (!txidValue.isStr() || !indexValue.isNum()) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid txid or index"); } uint256 txid = ParseHashV(txidValue, "txid"); - int outputIndex = indexValue.get_int(); + int outputIndex = indexValue.getInt(); CSpentIndexKey key(txid, outputIndex); CSpentIndexValue value; @@ -835,7 +835,7 @@ static RPCHelpMan mockscheduler() // check params are valid values RPCTypeCheck(request.params, {UniValue::VNUM}); - int64_t delta_seconds = request.params[0].get_int64(); + int64_t delta_seconds = request.params[0].getInt(); if (delta_seconds <= 0 || delta_seconds > 3600) { throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)"); } diff --git a/src/rpc/output_script.cpp b/src/rpc/output_script.cpp index f6e87278c59f..2e238ecfbab9 100644 --- a/src/rpc/output_script.cpp +++ b/src/rpc/output_script.cpp @@ -105,7 +105,7 @@ static RPCHelpMan createmultisig() }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - int required = request.params[0].get_int(); + int required = request.params[0].getInt(); // Get the public keys const UniValue& keys = request.params[1].get_array(); diff --git a/src/rpc/quorums.cpp b/src/rpc/quorums.cpp index c8bfd6cd0128..05fc271ef3de 100644 --- a/src/rpc/quorums.cpp +++ b/src/rpc/quorums.cpp @@ -164,7 +164,7 @@ static RPCHelpMan quorum_list_extended() } j.pushKV("creationHeight", q->m_quorum_base_block_index->nHeight); j.pushKV("minedBlockHash", q->minedBlockHash.ToString()); - j.pushKV("numValidMembers", (int32_t)num_valid_members); + j.pushKV("numValidMembers", num_valid_members); j.pushKV("healthRatio", ss.str()); obj.pushKV(q->qc->quorumHash.ToString(),j); } @@ -211,7 +211,7 @@ static UniValue BuildQuorumInfo(const llmq::CQuorumBlockProcessor& quorum_block_ } mo.pushKV("addresses", dmn->pdmnState->netInfo->ToJson()); mo.pushKV("pubKeyOperator", dmn->pdmnState->pubKeyOperator.ToString()); - mo.pushKV("valid", quorum->qc->validMembers[i]); + mo.pushKV("valid", static_cast(quorum->qc->validMembers[i])); if (quorum->qc->validMembers[i]) { if (quorum->params.size == 1) { mo.pushKV("pubKeyShare", dmn->pdmnState->pubKeyOperator.ToString()); @@ -916,7 +916,7 @@ static RPCHelpMan quorum_dkginfo() llmq::CDKGDebugStatus status; llmq_ctx.dkg_debugman->GetLocalDebugStatus(status); UniValue ret(UniValue::VOBJ); - ret.pushKV("active_dkgs", int(status.sessions.size())); + ret.pushKV("active_dkgs", status.sessions.size()); const int nTipHeight{WITH_LOCK(cs_main, return chainman.ActiveChain().Height())}; auto minNextDKG = [](const Consensus::Params& consensusParams, int nTipHeight) { @@ -997,7 +997,7 @@ static RPCHelpMan verifychainlock() } nBlockHeight = pIndex->nHeight; } else { - nBlockHeight = request.params[2].get_int(); + nBlockHeight = request.params[2].getInt(); LOCK(cs_main); if (nBlockHeight < 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); @@ -1063,7 +1063,7 @@ static RPCHelpMan verifyislock() int maxHeight{-1}; if (!request.params[3].isNull()) { - maxHeight = request.params[3].get_int(); + maxHeight = request.params[3].getInt(); } int signHeight; @@ -1118,7 +1118,7 @@ static RPCHelpMan submitchainlock() { const uint256 nBlockHash(ParseHashV(request.params[0], "blockHash")); - const int nBlockHeight = request.params[2].get_int(); + const int nBlockHeight = request.params[2].getInt(); if (nBlockHeight <= 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid block height"); } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 0ad984c98faa..dfe73acfead3 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -263,7 +263,7 @@ static RPCHelpMan getrawtransaction() // Accept either a bool (true) or a num (>=1) to indicate verbose output. bool fVerbose = false; if (!request.params[1].isNull()) { - fVerbose = request.params[1].isNum() ? (request.params[1].get_int() != 0) : request.params[1].get_bool(); + fVerbose = request.params[1].isNum() ? (request.params[1].getInt() != 0) : request.params[1].get_bool(); } if (!request.params[2].isNull()) { @@ -352,7 +352,7 @@ static RPCHelpMan getrawtransactionmulti() { // Accept either a bool (true) or a num (>=1) to indicate verbose output. bool fVerbose{false}; if (!request.params[1].isNull()) { - fVerbose = request.params[1].isNum() ? (request.params[1].get_int() != 0) : request.params[1].get_bool(); + fVerbose = request.params[1].isNum() ? (request.params[1].getInt() != 0) : request.params[1].get_bool(); } const NodeContext& node{EnsureAnyNodeContext(request.context)}; @@ -627,7 +627,7 @@ static RPCHelpMan getassetunlockstatuses() std::optional nSpecificCoreHeight{std::nullopt}; if (!request.params[1].isNull()) { - nSpecificCoreHeight = request.params[1].get_int(); + nSpecificCoreHeight = request.params[1].getInt(); if (nSpecificCoreHeight.value() < 0 || nSpecificCoreHeight.value() > chainman.ActiveChain().Height()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); } diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp index 1c8ebf834c31..e66a5b2d3aa9 100644 --- a/src/rpc/rawtransaction_util.cpp +++ b/src/rpc/rawtransaction_util.cpp @@ -39,7 +39,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal CMutableTransaction rawTx; if (!locktime.isNull()) { - int64_t nLockTime = locktime.get_int64(); + int64_t nLockTime = locktime.getInt(); if (nLockTime < 0 || nLockTime > LOCKTIME_MAX) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range"); rawTx.nLockTime = nLockTime; @@ -51,10 +51,10 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal uint256 txid = ParseHashO(o, "txid"); - const UniValue& vout_v = find_value(o, "vout"); + const UniValue& vout_v = o.find_value("vout"); if (!vout_v.isNum()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key"); - int nOutput = vout_v.get_int(); + int nOutput = vout_v.getInt(); if (nOutput < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative"); @@ -66,9 +66,9 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal } // set the sequence number if passed in the parameters object - const UniValue& sequenceObj = find_value(o, "sequence"); + const UniValue& sequenceObj = o.find_value("sequence"); if (sequenceObj.isNum()) { - int64_t seqNr64 = sequenceObj.get_int64(); + int64_t seqNr64 = sequenceObj.getInt(); if (seqNr64 < 0 || seqNr64 > CTxIn::SEQUENCE_FINAL) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range"); else @@ -164,7 +164,7 @@ void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keyst uint256 txid = ParseHashO(prevOut, "txid"); - int nOut = find_value(prevOut, "vout").get_int(); + int nOut = prevOut.find_value("vout").getInt(); if (nOut < 0) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout cannot be negative"); } @@ -185,7 +185,7 @@ void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keyst newcoin.out.scriptPubKey = scriptPubKey; newcoin.out.nValue = 0; if (prevOut.exists("amount")) { - newcoin.out.nValue = AmountFromValue(find_value(prevOut, "amount")); + newcoin.out.nValue = AmountFromValue(prevOut.find_value("amount")); } newcoin.nHeight = 1; coins[out] = std::move(newcoin); @@ -198,7 +198,7 @@ void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keyst { {"redeemScript", UniValueType(UniValue::VSTR)}, }); - UniValue rs = find_value(prevOut, "redeemScript"); + const UniValue& rs{prevOut.find_value("redeemScript")}; if (rs.isNull()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing redeemScript"); } diff --git a/src/rpc/request.cpp b/src/rpc/request.cpp index 5cdf43468782..f1cd256e3549 100644 --- a/src/rpc/request.cpp +++ b/src/rpc/request.cpp @@ -146,7 +146,7 @@ std::vector JSONRPCProcessBatchReply(const UniValue& in) if (!rec.isObject()) { throw std::runtime_error("Batch member must be an object"); } - size_t id = rec["id"].get_int(); + size_t id = rec["id"].getInt(); if (id >= num) { throw std::runtime_error("Batch member id is larger than batch size"); } @@ -163,10 +163,10 @@ void JSONRPCRequest::parse(const UniValue& valRequest) const UniValue& request = valRequest.get_obj(); // Parse id now so errors from here on will have the id - id = find_value(request, "id"); + id = request.find_value("id"); // Parse method - UniValue valMethod = find_value(request, "method"); + const UniValue& valMethod{request.find_value("method")}; if (valMethod.isNull()) throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method"); if (!valMethod.isStr()) @@ -181,7 +181,7 @@ void JSONRPCRequest::parse(const UniValue& valRequest) } // Parse params - UniValue valParams = find_value(request, "params"); + const UniValue& valParams{request.find_value("params")}; if (valParams.isArray() || valParams.isObject()) params = valParams; else if (valParams.isNull()) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 79dc6f9e67ca..cbb8d0f93e46 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -194,7 +194,7 @@ static RPCHelpMan stop() // this reply will get back to the client. StartShutdown(); if (jsonRequest.params[0].isNum()) { - UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].get_int()}); + UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].getInt()}); } return RESULT; }, diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 1c11ba793ab6..482caccec770 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -61,7 +61,7 @@ void RPCTypeCheckObj(const UniValue& o, bool fStrict) { for (const auto& t : typesExpected) { - const UniValue& v = find_value(o, t.first); + const UniValue& v = o.find_value(t.first); if (!fAllowNull && v.isNull()) throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first)); @@ -108,7 +108,7 @@ uint256 ParseHashV(const UniValue& v, std::string strName) } uint256 ParseHashO(const UniValue& o, std::string strKey) { - return ParseHashV(find_value(o, strKey), strKey); + return ParseHashV(o.find_value(strKey), strKey); } std::vector ParseHexV(const UniValue& v, std::string strName) { @@ -121,7 +121,7 @@ std::vector ParseHexV(const UniValue& v, std::string strName) } std::vector ParseHexO(const UniValue& o, std::string strKey) { - return ParseHexV(find_value(o, strKey), strKey); + return ParseHexV(o.find_value(strKey), strKey); } int32_t ParseInt32V(const UniValue& v, const std::string &strName) @@ -148,7 +148,7 @@ bool ParseBoolV(const UniValue& v, const std::string &strName) if (v.isBool()) return v.get_bool(); else if (v.isNum()) - strBool = ToString(v.get_int()); + strBool = ToString(v.getInt()); else if (v.isStr()) strBool = v.get_str(); @@ -322,7 +322,7 @@ UniValue DescribeAddress(const CTxDestination& dest) unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target) { - const int target{value.get_int()}; + const int target{value.getInt()}; const unsigned int unsigned_target{static_cast(target)}; if (target < 1 || unsigned_target > max_target) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u and %u", 1, max_target)); @@ -936,11 +936,11 @@ std::string RPCArg::ToString(const bool oneline) const static std::pair ParseRange(const UniValue& value) { if (value.isNum()) { - return {0, value.get_int64()}; + return {0, value.getInt()}; } if (value.isArray() && value.size() == 2 && value[0].isNum() && value[1].isNum()) { - int64_t low = value[0].get_int64(); - int64_t high = value[1].get_int64(); + int64_t low = value[0].getInt(); + int64_t high = value[1].getInt(); if (low > high) throw JSONRPCError(RPC_INVALID_PARAMETER, "Range specified as [begin,end] must not have begin after end"); return {low, high}; } @@ -1009,10 +1009,10 @@ std::vector EvalDescriptorStringOrObject(const UniValue& scanobject, Fl if (scanobject.isStr()) { desc_str = scanobject.get_str(); } else if (scanobject.isObject()) { - UniValue desc_uni = find_value(scanobject, "desc"); + const UniValue& desc_uni{scanobject.find_value("desc")}; if (desc_uni.isNull()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Descriptor needs to be provided in scan object"); desc_str = desc_uni.get_str(); - UniValue range_uni = find_value(scanobject, "range"); + const UniValue& range_uni{scanobject.find_value("range")}; if (!range_uni.isNull()) { range = ParseDescriptorRange(range_uni); } diff --git a/src/test/blockfilter_tests.cpp b/src/test/blockfilter_tests.cpp index f9c4f01090b3..3b16f36058ed 100644 --- a/src/test/blockfilter_tests.cpp +++ b/src/test/blockfilter_tests.cpp @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(blockfilters_json_test) } unsigned int pos = 0; - /*int block_height =*/ test[pos++].get_int(); + /*int block_height =*/ test[pos++].getInt(); uint256 block_hash; BOOST_CHECK(ParseHashStr(test[pos++].get_str(), block_hash)); diff --git a/src/test/fuzz/rpc.cpp b/src/test/fuzz/rpc.cpp index 2ca48f787575..892823dea067 100644 --- a/src/test/fuzz/rpc.cpp +++ b/src/test/fuzz/rpc.cpp @@ -356,7 +356,7 @@ FUZZ_TARGET(rpc, .init = initialize_rpc) try { rpc_testing_setup->CallRPC(rpc_command, arguments); } catch (const UniValue& json_rpc_error) { - const std::string error_msg{find_value(json_rpc_error, "message").get_str()}; + const std::string error_msg{json_rpc_error.find_value("message").get_str()}; if (error_msg.starts_with("Internal bug detected")) { // Only allow the intentional internal bug assert(error_msg.find("trigger_internal_bug") != std::string::npos); diff --git a/src/test/key_io_tests.cpp b/src/test/key_io_tests.cpp index 2548e51d889c..d01e4cb6fbe7 100644 --- a/src/test/key_io_tests.cpp +++ b/src/test/key_io_tests.cpp @@ -37,11 +37,11 @@ BOOST_AUTO_TEST_CASE(key_io_valid_parse) std::string exp_base58string = test[0].get_str(); const std::vector exp_payload{ParseHex(test[1].get_str())}; const UniValue &metadata = test[2].get_obj(); - bool isPrivkey = find_value(metadata, "isPrivkey").get_bool(); - SelectParams(find_value(metadata, "chain").get_str()); - bool try_case_flip = find_value(metadata, "tryCaseFlip").isNull() ? false : find_value(metadata, "tryCaseFlip").get_bool(); + bool isPrivkey = metadata.find_value("isPrivkey").get_bool(); + SelectParams(metadata.find_value("chain").get_str()); + bool try_case_flip = metadata.find_value("tryCaseFlip").isNull() ? false : metadata.find_value("tryCaseFlip").get_bool(); if (isPrivkey) { - bool isCompressed = find_value(metadata, "isCompressed").get_bool(); + bool isCompressed = metadata.find_value("isCompressed").get_bool(); // Must be valid private key privkey = DecodeSecret(exp_base58string); BOOST_CHECK_MESSAGE(privkey.IsValid(), "!IsValid:" + strTest); @@ -96,10 +96,10 @@ BOOST_AUTO_TEST_CASE(key_io_valid_gen) std::string exp_base58string = test[0].get_str(); std::vector exp_payload = ParseHex(test[1].get_str()); const UniValue &metadata = test[2].get_obj(); - bool isPrivkey = find_value(metadata, "isPrivkey").get_bool(); - SelectParams(find_value(metadata, "chain").get_str()); + bool isPrivkey = metadata.find_value("isPrivkey").get_bool(); + SelectParams(metadata.find_value("chain").get_str()); if (isPrivkey) { - bool isCompressed = find_value(metadata, "isCompressed").get_bool(); + bool isCompressed = metadata.find_value("isCompressed").get_bool(); CKey key; key.Set(exp_payload.begin(), exp_payload.end(), isCompressed); assert(key.IsValid()); diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index e0c9ee2dc932..6a6bc9fbba34 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -80,7 +80,7 @@ UniValue RPCTestingSetup::CallRPC(std::string args) return result; } catch (const UniValue& objError) { - throw std::runtime_error(find_value(objError, "message").get_str()); + throw std::runtime_error(objError.find_value("message").get_str()); } } @@ -139,9 +139,9 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams) BOOST_CHECK_THROW(CallRPC("decoderawtransaction DEADBEEF"), std::runtime_error); std::string rawtx = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000"; BOOST_CHECK_NO_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx)); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").get_int(), 193); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").get_int(), 1); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").get_int(), 0); + BOOST_CHECK_EQUAL(r.get_obj().find_value("size").getInt(), 193); + BOOST_CHECK_EQUAL(r.get_obj().find_value("version").getInt(), 1); + BOOST_CHECK_EQUAL(r.get_obj().find_value("locktime").getInt(), 0); BOOST_CHECK_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" extra"), std::runtime_error); // Only check failure cases for sendrawtransaction, there's no network to send to... @@ -156,20 +156,20 @@ BOOST_AUTO_TEST_CASE(rpc_togglenetwork) UniValue r; r = CallRPC("getnetworkinfo"); - bool netState = find_value(r.get_obj(), "networkactive").get_bool(); + bool netState = r.get_obj().find_value("networkactive").get_bool(); BOOST_CHECK_EQUAL(netState, true); BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive false")); r = CallRPC("getnetworkinfo"); - int numConnection = find_value(r.get_obj(), "connections").get_int(); + int numConnection = r.get_obj().find_value("connections").getInt(); BOOST_CHECK_EQUAL(numConnection, 0); - netState = find_value(r.get_obj(), "networkactive").get_bool(); + netState = r.get_obj().find_value("networkactive").get_bool(); BOOST_CHECK_EQUAL(netState, false); BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive true")); r = CallRPC("getnetworkinfo"); - netState = find_value(r.get_obj(), "networkactive").get_bool(); + netState = r.get_obj().find_value("networkactive").get_bool(); BOOST_CHECK_EQUAL(netState, true); } @@ -187,9 +187,9 @@ BOOST_AUTO_TEST_CASE(rpc_rawsign) std::string privkey1 = "\"XEwTRsCX3CiWSQf8YmKMTeb84KyTbibkUv9mDTZHQ5MwuKG2ZzES\""; std::string privkey2 = "\"XDmZ7LjGd94Q81eUBjb2h6uV5Y14s7fmeXWEGYabfBJP8RVpprBu\""; r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" [] "+prevout); - BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false); + BOOST_CHECK(r.get_obj().find_value("complete").get_bool() == false); r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" ["+privkey1+","+privkey2+"] "+prevout); - BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == true); + BOOST_CHECK(r.get_obj().find_value("complete").get_bool() == true); } BOOST_AUTO_TEST_CASE(rpc_createraw_op_return) @@ -252,10 +252,10 @@ BOOST_AUTO_TEST_CASE(rpc_format_monetary_values) BOOST_CHECK_EQUAL(ValueFromAmount(std::numeric_limits::min()).write(), "-92233720368.54775808"); } -static UniValue ValueFromString(const std::string &str) +static UniValue ValueFromString(const std::string& str) noexcept { UniValue value; - BOOST_CHECK(value.setNumStr(str)); + value.setNumStr(str); return value; } @@ -296,6 +296,10 @@ BOOST_AUTO_TEST_CASE(json_parse_errors) { // Valid BOOST_CHECK_EQUAL(ParseNonRFCJSONValue("1.0").get_real(), 1.0); + BOOST_CHECK_EQUAL(ParseNonRFCJSONValue("true").get_bool(), true); + BOOST_CHECK_EQUAL(ParseNonRFCJSONValue("[false]")[0].get_bool(), false); + BOOST_CHECK_EQUAL(ParseNonRFCJSONValue("{\"a\": true}")["a"].get_bool(), true); + BOOST_CHECK_EQUAL(ParseNonRFCJSONValue("{\"1\": \"true\"}")["1"].get_str(), "true"); // Valid, with leading or trailing whitespace BOOST_CHECK_EQUAL(ParseNonRFCJSONValue(" 1.0").get_real(), 1.0); BOOST_CHECK_EQUAL(ParseNonRFCJSONValue("1.0 ").get_real(), 1.0); @@ -308,6 +312,11 @@ BOOST_AUTO_TEST_CASE(json_parse_errors) // Invalid, trailing garbage BOOST_CHECK_THROW(ParseNonRFCJSONValue("1.0sds"), std::runtime_error); BOOST_CHECK_THROW(ParseNonRFCJSONValue("1.0]"), std::runtime_error); + // Invalid, keys have to be names + BOOST_CHECK_THROW(ParseNonRFCJSONValue("{1: \"true\"}"), std::runtime_error); + BOOST_CHECK_THROW(ParseNonRFCJSONValue("{true: 1}"), std::runtime_error); + BOOST_CHECK_THROW(ParseNonRFCJSONValue("{[1]: 1}"), std::runtime_error); + BOOST_CHECK_THROW(ParseNonRFCJSONValue("{{\"a\": \"a\"}: 1}"), std::runtime_error); // BTC addresses should fail parsing BOOST_CHECK_THROW(ParseNonRFCJSONValue("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"), std::runtime_error); BOOST_CHECK_THROW(ParseNonRFCJSONValue("3J98t1WpEZ73CNmQviecrnyiWrnqRhWNL"), std::runtime_error); @@ -323,7 +332,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban) BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned"))); UniValue ar = r.get_array(); UniValue o1 = ar[0].get_obj(); - UniValue adr = find_value(o1, "address"); + UniValue adr = o1.find_value("address"); BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/32"); BOOST_CHECK_NO_THROW(CallRPC(std::string("setban 127.0.0.0 remove"))); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned"))); @@ -334,8 +343,8 @@ BOOST_AUTO_TEST_CASE(rpc_ban) BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned"))); ar = r.get_array(); o1 = ar[0].get_obj(); - adr = find_value(o1, "address"); - int64_t banned_until{find_value(o1, "banned_until").get_int64()}; + adr = o1.find_value("address"); + int64_t banned_until{o1.find_value("banned_until").getInt()}; BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24"); BOOST_CHECK_EQUAL(banned_until, 9907731200); // absolute time check @@ -349,11 +358,11 @@ BOOST_AUTO_TEST_CASE(rpc_ban) BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned"))); ar = r.get_array(); o1 = ar[0].get_obj(); - adr = find_value(o1, "address"); - banned_until = find_value(o1, "banned_until").get_int64(); - const int64_t ban_created{find_value(o1, "ban_created").get_int64()}; - const int64_t ban_duration{find_value(o1, "ban_duration").get_int64()}; - const int64_t time_remaining{find_value(o1, "time_remaining").get_int64()}; + adr = o1.find_value("address"); + banned_until = o1.find_value("banned_until").getInt(); + const int64_t ban_created{o1.find_value("ban_created").getInt()}; + const int64_t ban_duration{o1.find_value("ban_duration").getInt()}; + const int64_t time_remaining{o1.find_value("time_remaining").getInt()}; BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24"); BOOST_CHECK_EQUAL(banned_until, time_remaining_expected + now.count()); BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created); @@ -383,7 +392,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban) BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned"))); ar = r.get_array(); o1 = ar[0].get_obj(); - adr = find_value(o1, "address"); + adr = o1.find_value("address"); BOOST_CHECK_EQUAL(adr.get_str(), "fe80::202:b3ff:fe1e:8329/128"); BOOST_CHECK_NO_THROW(CallRPC(std::string("clearbanned"))); @@ -391,7 +400,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban) BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned"))); ar = r.get_array(); o1 = ar[0].get_obj(); - adr = find_value(o1, "address"); + adr = o1.find_value("address"); BOOST_CHECK_EQUAL(adr.get_str(), "2001:db8::/30"); BOOST_CHECK_NO_THROW(CallRPC(std::string("clearbanned"))); @@ -399,7 +408,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban) BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned"))); ar = r.get_array(); o1 = ar[0].get_obj(); - adr = find_value(o1, "address"); + adr = o1.find_value("address"); BOOST_CHECK_EQUAL(adr.get_str(), "2001:4d48:ac57:400:cacf:e9ff:fe1d:9c63/128"); } @@ -409,22 +418,22 @@ BOOST_AUTO_TEST_CASE(rpc_convert_values_generatetoaddress) UniValue result; BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"101", "yhq7ifNCtTKEpY4Yu5XPCcztQco6Fh6JsZ"})); - BOOST_CHECK_EQUAL(result[0].get_int(), 101); + BOOST_CHECK_EQUAL(result[0].getInt(), 101); BOOST_CHECK_EQUAL(result[1].get_str(), "yhq7ifNCtTKEpY4Yu5XPCcztQco6Fh6JsZ"); BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"101", "yTretFTpoi3oQ3maZk5QadGaDWPiKnmDBc"})); - BOOST_CHECK_EQUAL(result[0].get_int(), 101); + BOOST_CHECK_EQUAL(result[0].getInt(), 101); BOOST_CHECK_EQUAL(result[1].get_str(), "yTretFTpoi3oQ3maZk5QadGaDWPiKnmDBc"); BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"1", "yNbNZyCiTYSFtDwEXt7jChV7tZVYX862ua", "9"})); - BOOST_CHECK_EQUAL(result[0].get_int(), 1); + BOOST_CHECK_EQUAL(result[0].getInt(), 1); BOOST_CHECK_EQUAL(result[1].get_str(), "yNbNZyCiTYSFtDwEXt7jChV7tZVYX862ua"); - BOOST_CHECK_EQUAL(result[2].get_int(), 9); + BOOST_CHECK_EQUAL(result[2].getInt(), 9); BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"1", "yTG8jLL3MvteKXgbEcHyaN7JvTPCejQpSh", "9"})); - BOOST_CHECK_EQUAL(result[0].get_int(), 1); + BOOST_CHECK_EQUAL(result[0].getInt(), 1); BOOST_CHECK_EQUAL(result[1].get_str(), "yTG8jLL3MvteKXgbEcHyaN7JvTPCejQpSh"); - BOOST_CHECK_EQUAL(result[2].get_int(), 9); + BOOST_CHECK_EQUAL(result[2].getInt(), 9); } #endif // ENABLE_MINER @@ -546,45 +555,45 @@ BOOST_AUTO_TEST_CASE(rpc_bls) UniValue r; BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls generate"))); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "basic"); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "basic"); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls generate 1"))); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "legacy"); - std::string secret_legacy = find_value(r.get_obj(), "secret").get_str(); - std::string public_legacy = find_value(r.get_obj(), "public").get_str(); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "legacy"); + std::string secret_legacy = r.get_obj().find_value("secret").get_str(); + std::string public_legacy = r.get_obj().find_value("public").get_str(); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls generate 0"))); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "basic"); - std::string secret_basic = find_value(r.get_obj(), "secret").get_str(); - std::string public_basic = find_value(r.get_obj(), "public").get_str(); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "basic"); + std::string secret_basic = r.get_obj().find_value("secret").get_str(); + std::string public_basic = r.get_obj().find_value("public").get_str(); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls fromsecret ") + secret_basic)); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "basic"); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "public").get_str(), public_basic); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "basic"); + BOOST_CHECK_EQUAL(r.get_obj().find_value("public").get_str(), public_basic); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls fromsecret ") + secret_legacy + std::string(" 1"))); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "legacy"); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "public").get_str(), public_legacy); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "legacy"); + BOOST_CHECK_EQUAL(r.get_obj().find_value("public").get_str(), public_legacy); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls fromsecret ") + secret_basic + std::string(" 0"))); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "basic"); - BOOST_CHECK(find_value(r.get_obj(), "public").get_str() != public_legacy); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "basic"); + BOOST_CHECK(r.get_obj().find_value("public").get_str() != public_legacy); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls fromsecret ") + secret_basic + std::string(" 0"))); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "basic"); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "public").get_str(), public_basic); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "basic"); + BOOST_CHECK_EQUAL(r.get_obj().find_value("public").get_str(), public_basic); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls fromsecret ") + secret_basic + std::string(" 1"))); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "legacy"); - BOOST_CHECK(find_value(r.get_obj(), "public").get_str() != public_basic); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "legacy"); + BOOST_CHECK(r.get_obj().find_value("public").get_str() != public_basic); std::string secret = "0b072b1b8b28335b0460aa695ee8ce1f60dc01e6eb12655ece2a877379dfdb51"; BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls fromsecret ") + secret + " 1")); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "legacy"); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "public").get_str(), "9379c28e0f50546906fe733f1222c8f7e39574d513790034f1fec1476286eb652a350c8c0e630cd2cc60d10c26d6f6ee"); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "legacy"); + BOOST_CHECK_EQUAL(r.get_obj().find_value("public").get_str(), "9379c28e0f50546906fe733f1222c8f7e39574d513790034f1fec1476286eb652a350c8c0e630cd2cc60d10c26d6f6ee"); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("bls fromsecret ") + secret)); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "scheme").get_str(), "basic"); - BOOST_CHECK_EQUAL(find_value(r.get_obj(), "public").get_str(), "b379c28e0f50546906fe733f1222c8f7e39574d513790034f1fec1476286eb652a350c8c0e630cd2cc60d10c26d6f6ee"); + BOOST_CHECK_EQUAL(r.get_obj().find_value("scheme").get_str(), "basic"); + BOOST_CHECK_EQUAL(r.get_obj().find_value("public").get_str(), "b379c28e0f50546906fe733f1222c8f7e39574d513790034f1fec1476286eb652a350c8c0e630cd2cc60d10c26d6f6ee"); } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index c5694e79254e..2a62c16c90d4 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -180,8 +180,8 @@ BOOST_AUTO_TEST_CASE(sighash_from_data) // deserialize test data raw_tx = test[0].get_str(); raw_script = test[1].get_str(); - nIn = test[2].get_int(); - nHashType = test[3].get_int(); + nIn = test[2].getInt(); + nHashType = test[3].getInt(); sigHashHex = test[4].get_str(); CDataStream stream(ParseHex(raw_tx), SER_NETWORK, PROTOCOL_VERSION); diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp index 11e67f4dacbb..deef4f12b1b1 100644 --- a/src/test/system_tests.cpp +++ b/src/test/system_tests.cpp @@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(run_command) const UniValue result = RunCommandParseJSON("echo \"{\"success\": true}\""); #endif BOOST_CHECK(result.isObject()); - const UniValue& success = find_value(result, "success"); + const UniValue& success = result.find_value("success"); BOOST_CHECK(!success.isNull()); BOOST_CHECK_EQUAL(success.getBool(), true); } @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(run_command) { const UniValue result = RunCommandParseJSON("cat", "{\"success\": true}"); BOOST_CHECK(result.isObject()); - const UniValue& success = find_value(result, "success"); + const UniValue& success = result.find_value("success"); BOOST_CHECK(!success.isNull()); BOOST_CHECK_EQUAL(success.getBool(), true); } diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index 5db21f086b54..5a61438d9dd0 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(tx_valid) break; } - mapprevOutScriptPubKeys[COutPoint{uint256S(vinput[0].get_str()), uint32_t(vinput[1].get_int())}] = ParseScript(vinput[2].get_str()); + mapprevOutScriptPubKeys[COutPoint{uint256S(vinput[0].get_str()), uint32_t(vinput[1].getInt())}] = ParseScript(vinput[2].get_str()); } if (!fValid) { @@ -263,7 +263,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid) break; } - mapprevOutScriptPubKeys[COutPoint{uint256S(vinput[0].get_str()), uint32_t(vinput[1].get_int())}] = ParseScript(vinput[2].get_str()); + mapprevOutScriptPubKeys[COutPoint{uint256S(vinput[0].get_str()), uint32_t(vinput[1].getInt())}] = ParseScript(vinput[2].get_str()); } if (!fValid) { diff --git a/src/univalue/.cirrus.yml b/src/univalue/.cirrus.yml deleted file mode 100644 index f140fee12bc8..000000000000 --- a/src/univalue/.cirrus.yml +++ /dev/null @@ -1,44 +0,0 @@ -env: - MAKEJOBS: "-j4" - RUN_TESTS: "true" - BASE_OUTDIR: "$CIRRUS_WORKING_DIR/out_dir_base" - DEBIAN_FRONTEND: "noninteractive" - -task: - container: - image: ubuntu:focal - cpu: 1 - memory: 1G - greedy: true # https://medium.com/cirruslabs/introducing-greedy-container-instances-29aad06dc2b4 - - matrix: - - name: "gcc" - env: - CC: "gcc" - CXX: "g++" - APT_PKGS: "gcc" - - name: "clang" - env: - CC: "clang" - CXX: "clang++" - APT_PKGS: "clang" - - name: "mingw" - env: - CC: "" - CXX: "" - UNIVALUE_CONFIG: "--host=x86_64-w64-mingw32" - APT_PKGS: "g++-mingw-w64-x86-64 gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64" - RUN_TESTS: "false" - - install_script: - - apt update - - apt install -y pkg-config build-essential libtool autotools-dev automake bsdmainutils - - apt install -y $APT_PKGS - autogen_script: - - ./autogen.sh - configure_script: - - ./configure --cache-file=config.cache --bindir=$BASE_OUTDIR/bin --libdir=$BASE_OUTDIR/lib $UNIVALUE_CONFIG - make_script: - - make $MAKEJOBS V=1 - test_script: - - if [ "$RUN_TESTS" = "true" ]; then make $MAKEJOBS distcheck; fi diff --git a/src/univalue/COPYING b/src/univalue/COPYING deleted file mode 100644 index 1fb429f3569c..000000000000 --- a/src/univalue/COPYING +++ /dev/null @@ -1,19 +0,0 @@ - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - diff --git a/src/univalue/Makefile.am b/src/univalue/Makefile.am deleted file mode 100644 index 476f14b922eb..000000000000 --- a/src/univalue/Makefile.am +++ /dev/null @@ -1,58 +0,0 @@ -include sources.mk -ACLOCAL_AMFLAGS = -I build-aux/m4 -.PHONY: gen FORCE -.INTERMEDIATE: $(GENBIN) - -include_HEADERS = $(UNIVALUE_DIST_HEADERS_INT) -noinst_HEADERS = $(UNIVALUE_LIB_HEADERS_INT) - -lib_LTLIBRARIES = libunivalue.la - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = pc/libunivalue.pc - -libunivalue_la_SOURCES = $(UNIVALUE_LIB_SOURCES_INT) - -libunivalue_la_LDFLAGS = \ - -version-info $(LIBUNIVALUE_CURRENT):$(LIBUNIVALUE_REVISION):$(LIBUNIVALUE_AGE) \ - -no-undefined -libunivalue_la_CXXFLAGS = -I$(top_srcdir)/include - -TESTS = test/object test/unitester test/no_nul - -GENBIN = gen/gen$(BUILD_EXEEXT) -GEN_SRCS = gen/gen.cpp - -$(GENBIN): $(GEN_SRCS) - @echo Building $@ - $(AM_V_at)c++ -I$(top_srcdir)/include -o $@ $< - -gen: $(GENBIN) FORCE - @echo Updating lib/univalue_escapes.h - $(AM_V_at)$(GENBIN) > lib/univalue_escapes.h - -noinst_PROGRAMS = $(TESTS) test/test_json - -test_unitester_SOURCES = $(UNIVALUE_TEST_UNITESTER_INT) -test_unitester_LDADD = libunivalue.la -test_unitester_CXXFLAGS = -I$(top_srcdir)/include -DJSON_TEST_SRC=\"$(srcdir)/$(UNIVALUE_TEST_DATA_DIR_INT)\" -test_unitester_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS) - -test_test_json_SOURCES = $(UNIVALUE_TEST_JSON_INT) -test_test_json_LDADD = libunivalue.la -test_test_json_CXXFLAGS = -I$(top_srcdir)/include -test_test_json_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS) - -test_no_nul_SOURCES = $(UNIVALUE_TEST_NO_NUL_INT) -test_no_nul_LDADD = libunivalue.la -test_no_nul_CXXFLAGS = -I$(top_srcdir)/include -test_no_nul_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS) - -test_object_SOURCES = $(UNIVALUE_TEST_OBJECT_INT) -test_object_LDADD = libunivalue.la -test_object_CXXFLAGS = -I$(top_srcdir)/include -test_object_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS) - -TEST_FILES = $(UNIVALUE_TEST_FILES_INT) - -EXTRA_DIST=$(UNIVALUE_TEST_FILES_INT) $(GEN_SRCS) diff --git a/src/univalue/README.md b/src/univalue/README.md deleted file mode 100644 index 22fe2d2ad45e..000000000000 --- a/src/univalue/README.md +++ /dev/null @@ -1,21 +0,0 @@ - -# UniValue - -## Summary - -A universal value class, with JSON encoding and decoding. - -UniValue is an abstract data type that may be a null, boolean, string, -number, array container, or a key/value dictionary container, nested to -an arbitrary depth. - -This class is aligned with the JSON standard, [RFC -7159](https://tools.ietf.org/html/rfc7159.html). - -## Library usage - -This is a fork of univalue used by Dash Core. It is not maintained for usage -by other projects. Notably, the API may break in non-backward-compatible ways. - -Other projects looking for a maintained library should use the upstream -univalue at https://github.com/jgarzik/univalue. diff --git a/src/univalue/TODO b/src/univalue/TODO deleted file mode 100644 index 5530048e923e..000000000000 --- a/src/univalue/TODO +++ /dev/null @@ -1,10 +0,0 @@ - -Rearrange tree for easier 'git subtree' style use - -Move towards C++11 etc. - -Namespace support - must come up with useful shorthand, avoiding -long Univalue::Univalue::Univalue usages forced upon library users. - -Improve test suite - diff --git a/src/univalue/autogen.sh b/src/univalue/autogen.sh deleted file mode 100755 index 4b38721faad0..000000000000 --- a/src/univalue/autogen.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -set -e -srcdir="$(dirname $0)" -cd "$srcdir" -if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="`which glibtoolize 2>/dev/null`"; then - LIBTOOLIZE="${GLIBTOOLIZE}" - export LIBTOOLIZE -fi -autoreconf --install --force diff --git a/src/univalue/build-aux/m4/.gitignore b/src/univalue/build-aux/m4/.gitignore deleted file mode 100644 index f063686524ea..000000000000 --- a/src/univalue/build-aux/m4/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/*.m4 diff --git a/src/univalue/build-aux/m4/ax_cxx_compile_stdcxx.m4 b/src/univalue/build-aux/m4/ax_cxx_compile_stdcxx.m4 deleted file mode 100644 index f7e5137003cf..000000000000 --- a/src/univalue/build-aux/m4/ax_cxx_compile_stdcxx.m4 +++ /dev/null @@ -1,962 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) -# -# DESCRIPTION -# -# Check for baseline language coverage in the compiler for the specified -# version of the C++ standard. If necessary, add switches to CXX and -# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard) -# or '14' (for the C++14 standard). -# -# The second argument, if specified, indicates whether you insist on an -# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. -# -std=c++11). If neither is specified, you get whatever works, with -# preference for no added switch, and then for an extended mode. -# -# The third argument, if specified 'mandatory' or if left unspecified, -# indicates that baseline support for the specified C++ standard is -# required and that the macro should error out if no mode with that -# support is found. If specified 'optional', then configuration proceeds -# regardless, after defining HAVE_CXX${VERSION} if and only if a -# supporting mode is found. -# -# LICENSE -# -# Copyright (c) 2008 Benjamin Kosnik -# Copyright (c) 2012 Zack Weinberg -# Copyright (c) 2013 Roy Stogner -# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov -# Copyright (c) 2015 Paul Norman -# Copyright (c) 2015 Moritz Klammler -# Copyright (c) 2016, 2018 Krzesimir Nowak -# Copyright (c) 2019 Enji Cooper -# Copyright (c) 2020 Jason Merrill -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 12 - -dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro -dnl (serial version number 13). - -AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl - m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"], - [$1], [14], [ax_cxx_compile_alternatives="14 1y"], - [$1], [17], [ax_cxx_compile_alternatives="17 1z"], - [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl - m4_if([$2], [], [], - [$2], [ext], [], - [$2], [noext], [], - [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl - m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], - [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], - [$3], [optional], [ax_cxx_compile_cxx$1_required=false], - [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) - AC_LANG_PUSH([C++])dnl - ac_success=no - - m4_if([$2], [], [dnl - AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, - ax_cv_cxx_compile_cxx$1, - [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], - [ax_cv_cxx_compile_cxx$1=yes], - [ax_cv_cxx_compile_cxx$1=no])]) - if test x$ax_cv_cxx_compile_cxx$1 = xyes; then - ac_success=yes - fi]) - - m4_if([$2], [noext], [], [dnl - if test x$ac_success = xno; then - for alternative in ${ax_cxx_compile_alternatives}; do - switch="-std=gnu++${alternative}" - cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) - AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, - $cachevar, - [ac_save_CXX="$CXX" - CXX="$CXX $switch" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], - [eval $cachevar=yes], - [eval $cachevar=no]) - CXX="$ac_save_CXX"]) - if eval test x\$$cachevar = xyes; then - CXX="$CXX $switch" - if test -n "$CXXCPP" ; then - CXXCPP="$CXXCPP $switch" - fi - ac_success=yes - break - fi - done - fi]) - - m4_if([$2], [ext], [], [dnl - if test x$ac_success = xno; then - dnl HP's aCC needs +std=c++11 according to: - dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf - dnl Cray's crayCC needs "-h std=c++11" - for alternative in ${ax_cxx_compile_alternatives}; do - for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do - cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) - AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, - $cachevar, - [ac_save_CXX="$CXX" - CXX="$CXX $switch" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], - [eval $cachevar=yes], - [eval $cachevar=no]) - CXX="$ac_save_CXX"]) - if eval test x\$$cachevar = xyes; then - CXX="$CXX $switch" - if test -n "$CXXCPP" ; then - CXXCPP="$CXXCPP $switch" - fi - ac_success=yes - break - fi - done - if test x$ac_success = xyes; then - break - fi - done - fi]) - AC_LANG_POP([C++]) - if test x$ax_cxx_compile_cxx$1_required = xtrue; then - if test x$ac_success = xno; then - AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) - fi - fi - if test x$ac_success = xno; then - HAVE_CXX$1=0 - AC_MSG_NOTICE([No compiler with C++$1 support was found]) - else - HAVE_CXX$1=1 - AC_DEFINE(HAVE_CXX$1,1, - [define if the compiler supports basic C++$1 syntax]) - fi - AC_SUBST(HAVE_CXX$1) -]) - - -dnl Test body for checking C++11 support - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], - _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 -) - - -dnl Test body for checking C++14 support - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], - _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 - _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 -) - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17], - _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 - _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 - _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 -) - -dnl Tests for new features in C++11 - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ - -// If the compiler admits that it is not ready for C++11, why torture it? -// Hopefully, this will speed up the test. - -#ifndef __cplusplus - -#error "This is not a C++ compiler" - -#elif __cplusplus < 201103L - -#error "This is not a C++11 compiler" - -#else - -namespace cxx11 -{ - - namespace test_static_assert - { - - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - } - - namespace test_final_override - { - - struct Base - { - virtual ~Base() {} - virtual void f() {} - }; - - struct Derived : public Base - { - virtual ~Derived() override {} - virtual void f() override {} - }; - - } - - namespace test_double_right_angle_brackets - { - - template < typename T > - struct check {}; - - typedef check single_type; - typedef check> double_type; - typedef check>> triple_type; - typedef check>>> quadruple_type; - - } - - namespace test_decltype - { - - int - f() - { - int a = 1; - decltype(a) b = 2; - return a + b; - } - - } - - namespace test_type_deduction - { - - template < typename T1, typename T2 > - struct is_same - { - static const bool value = false; - }; - - template < typename T > - struct is_same - { - static const bool value = true; - }; - - template < typename T1, typename T2 > - auto - add(T1 a1, T2 a2) -> decltype(a1 + a2) - { - return a1 + a2; - } - - int - test(const int c, volatile int v) - { - static_assert(is_same::value == true, ""); - static_assert(is_same::value == false, ""); - static_assert(is_same::value == false, ""); - auto ac = c; - auto av = v; - auto sumi = ac + av + 'x'; - auto sumf = ac + av + 1.0; - static_assert(is_same::value == true, ""); - static_assert(is_same::value == true, ""); - static_assert(is_same::value == true, ""); - static_assert(is_same::value == false, ""); - static_assert(is_same::value == true, ""); - return (sumf > 0.0) ? sumi : add(c, v); - } - - } - - namespace test_noexcept - { - - int f() { return 0; } - int g() noexcept { return 0; } - - static_assert(noexcept(f()) == false, ""); - static_assert(noexcept(g()) == true, ""); - - } - - namespace test_constexpr - { - - template < typename CharT > - unsigned long constexpr - strlen_c_r(const CharT *const s, const unsigned long acc) noexcept - { - return *s ? strlen_c_r(s + 1, acc + 1) : acc; - } - - template < typename CharT > - unsigned long constexpr - strlen_c(const CharT *const s) noexcept - { - return strlen_c_r(s, 0UL); - } - - static_assert(strlen_c("") == 0UL, ""); - static_assert(strlen_c("1") == 1UL, ""); - static_assert(strlen_c("example") == 7UL, ""); - static_assert(strlen_c("another\0example") == 7UL, ""); - - } - - namespace test_rvalue_references - { - - template < int N > - struct answer - { - static constexpr int value = N; - }; - - answer<1> f(int&) { return answer<1>(); } - answer<2> f(const int&) { return answer<2>(); } - answer<3> f(int&&) { return answer<3>(); } - - void - test() - { - int i = 0; - const int c = 0; - static_assert(decltype(f(i))::value == 1, ""); - static_assert(decltype(f(c))::value == 2, ""); - static_assert(decltype(f(0))::value == 3, ""); - } - - } - - namespace test_uniform_initialization - { - - struct test - { - static const int zero {}; - static const int one {1}; - }; - - static_assert(test::zero == 0, ""); - static_assert(test::one == 1, ""); - - } - - namespace test_lambdas - { - - void - test1() - { - auto lambda1 = [](){}; - auto lambda2 = lambda1; - lambda1(); - lambda2(); - } - - int - test2() - { - auto a = [](int i, int j){ return i + j; }(1, 2); - auto b = []() -> int { return '0'; }(); - auto c = [=](){ return a + b; }(); - auto d = [&](){ return c; }(); - auto e = [a, &b](int x) mutable { - const auto identity = [](int y){ return y; }; - for (auto i = 0; i < a; ++i) - a += b--; - return x + identity(a + b); - }(0); - return a + b + c + d + e; - } - - int - test3() - { - const auto nullary = [](){ return 0; }; - const auto unary = [](int x){ return x; }; - using nullary_t = decltype(nullary); - using unary_t = decltype(unary); - const auto higher1st = [](nullary_t f){ return f(); }; - const auto higher2nd = [unary](nullary_t f1){ - return [unary, f1](unary_t f2){ return f2(unary(f1())); }; - }; - return higher1st(nullary) + higher2nd(nullary)(unary); - } - - } - - namespace test_variadic_templates - { - - template - struct sum; - - template - struct sum - { - static constexpr auto value = N0 + sum::value; - }; - - template <> - struct sum<> - { - static constexpr auto value = 0; - }; - - static_assert(sum<>::value == 0, ""); - static_assert(sum<1>::value == 1, ""); - static_assert(sum<23>::value == 23, ""); - static_assert(sum<1, 2>::value == 3, ""); - static_assert(sum<5, 5, 11>::value == 21, ""); - static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); - - } - - // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae - // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function - // because of this. - namespace test_template_alias_sfinae - { - - struct foo {}; - - template - using member = typename T::member_type; - - template - void func(...) {} - - template - void func(member*) {} - - void test(); - - void test() { func(0); } - - } - -} // namespace cxx11 - -#endif // __cplusplus >= 201103L - -]]) - - -dnl Tests for new features in C++14 - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ - -// If the compiler admits that it is not ready for C++14, why torture it? -// Hopefully, this will speed up the test. - -#ifndef __cplusplus - -#error "This is not a C++ compiler" - -#elif __cplusplus < 201402L - -#error "This is not a C++14 compiler" - -#else - -namespace cxx14 -{ - - namespace test_polymorphic_lambdas - { - - int - test() - { - const auto lambda = [](auto&&... args){ - const auto istiny = [](auto x){ - return (sizeof(x) == 1UL) ? 1 : 0; - }; - const int aretiny[] = { istiny(args)... }; - return aretiny[0]; - }; - return lambda(1, 1L, 1.0f, '1'); - } - - } - - namespace test_binary_literals - { - - constexpr auto ivii = 0b0000000000101010; - static_assert(ivii == 42, "wrong value"); - - } - - namespace test_generalized_constexpr - { - - template < typename CharT > - constexpr unsigned long - strlen_c(const CharT *const s) noexcept - { - auto length = 0UL; - for (auto p = s; *p; ++p) - ++length; - return length; - } - - static_assert(strlen_c("") == 0UL, ""); - static_assert(strlen_c("x") == 1UL, ""); - static_assert(strlen_c("test") == 4UL, ""); - static_assert(strlen_c("another\0test") == 7UL, ""); - - } - - namespace test_lambda_init_capture - { - - int - test() - { - auto x = 0; - const auto lambda1 = [a = x](int b){ return a + b; }; - const auto lambda2 = [a = lambda1(x)](){ return a; }; - return lambda2(); - } - - } - - namespace test_digit_separators - { - - constexpr auto ten_million = 100'000'000; - static_assert(ten_million == 100000000, ""); - - } - - namespace test_return_type_deduction - { - - auto f(int& x) { return x; } - decltype(auto) g(int& x) { return x; } - - template < typename T1, typename T2 > - struct is_same - { - static constexpr auto value = false; - }; - - template < typename T > - struct is_same - { - static constexpr auto value = true; - }; - - int - test() - { - auto x = 0; - static_assert(is_same::value, ""); - static_assert(is_same::value, ""); - return x; - } - - } - -} // namespace cxx14 - -#endif // __cplusplus >= 201402L - -]]) - - -dnl Tests for new features in C++17 - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[ - -// If the compiler admits that it is not ready for C++17, why torture it? -// Hopefully, this will speed up the test. - -#ifndef __cplusplus - -#error "This is not a C++ compiler" - -#elif __cplusplus < 201703L - -#error "This is not a C++17 compiler" - -#else - -#include -#include -#include - -namespace cxx17 -{ - - namespace test_constexpr_lambdas - { - - constexpr int foo = [](){return 42;}(); - - } - - namespace test::nested_namespace::definitions - { - - } - - namespace test_fold_expression - { - - template - int multiply(Args... args) - { - return (args * ... * 1); - } - - template - bool all(Args... args) - { - return (args && ...); - } - - } - - namespace test_extended_static_assert - { - - static_assert (true); - - } - - namespace test_auto_brace_init_list - { - - auto foo = {5}; - auto bar {5}; - - static_assert(std::is_same, decltype(foo)>::value); - static_assert(std::is_same::value); - } - - namespace test_typename_in_template_template_parameter - { - - template typename X> struct D; - - } - - namespace test_fallthrough_nodiscard_maybe_unused_attributes - { - - int f1() - { - return 42; - } - - [[nodiscard]] int f2() - { - [[maybe_unused]] auto unused = f1(); - - switch (f1()) - { - case 17: - f1(); - [[fallthrough]]; - case 42: - f1(); - } - return f1(); - } - - } - - namespace test_extended_aggregate_initialization - { - - struct base1 - { - int b1, b2 = 42; - }; - - struct base2 - { - base2() { - b3 = 42; - } - int b3; - }; - - struct derived : base1, base2 - { - int d; - }; - - derived d1 {{1, 2}, {}, 4}; // full initialization - derived d2 {{}, {}, 4}; // value-initialized bases - - } - - namespace test_general_range_based_for_loop - { - - struct iter - { - int i; - - int& operator* () - { - return i; - } - - const int& operator* () const - { - return i; - } - - iter& operator++() - { - ++i; - return *this; - } - }; - - struct sentinel - { - int i; - }; - - bool operator== (const iter& i, const sentinel& s) - { - return i.i == s.i; - } - - bool operator!= (const iter& i, const sentinel& s) - { - return !(i == s); - } - - struct range - { - iter begin() const - { - return {0}; - } - - sentinel end() const - { - return {5}; - } - }; - - void f() - { - range r {}; - - for (auto i : r) - { - [[maybe_unused]] auto v = i; - } - } - - } - - namespace test_lambda_capture_asterisk_this_by_value - { - - struct t - { - int i; - int foo() - { - return [*this]() - { - return i; - }(); - } - }; - - } - - namespace test_enum_class_construction - { - - enum class byte : unsigned char - {}; - - byte foo {42}; - - } - - namespace test_constexpr_if - { - - template - int f () - { - if constexpr(cond) - { - return 13; - } - else - { - return 42; - } - } - - } - - namespace test_selection_statement_with_initializer - { - - int f() - { - return 13; - } - - int f2() - { - if (auto i = f(); i > 0) - { - return 3; - } - - switch (auto i = f(); i + 4) - { - case 17: - return 2; - - default: - return 1; - } - } - - } - - namespace test_template_argument_deduction_for_class_templates - { - - template - struct pair - { - pair (T1 p1, T2 p2) - : m1 {p1}, - m2 {p2} - {} - - T1 m1; - T2 m2; - }; - - void f() - { - [[maybe_unused]] auto p = pair{13, 42u}; - } - - } - - namespace test_non_type_auto_template_parameters - { - - template - struct B - {}; - - B<5> b1; - B<'a'> b2; - - } - - namespace test_structured_bindings - { - - int arr[2] = { 1, 2 }; - std::pair pr = { 1, 2 }; - - auto f1() -> int(&)[2] - { - return arr; - } - - auto f2() -> std::pair& - { - return pr; - } - - struct S - { - int x1 : 2; - volatile double y1; - }; - - S f3() - { - return {}; - } - - auto [ x1, y1 ] = f1(); - auto& [ xr1, yr1 ] = f1(); - auto [ x2, y2 ] = f2(); - auto& [ xr2, yr2 ] = f2(); - const auto [ x3, y3 ] = f3(); - - } - - namespace test_exception_spec_type_system - { - - struct Good {}; - struct Bad {}; - - void g1() noexcept; - void g2(); - - template - Bad - f(T*, T*); - - template - Good - f(T1*, T2*); - - static_assert (std::is_same_v); - - } - - namespace test_inline_variables - { - - template void f(T) - {} - - template inline T g(T) - { - return T{}; - } - - template<> inline void f<>(int) - {} - - template<> int g<>(int) - { - return 5; - } - - } - -} // namespace cxx17 - -#endif // __cplusplus < 201703L - -]]) diff --git a/src/univalue/configure.ac b/src/univalue/configure.ac deleted file mode 100644 index 495b25a53d8e..000000000000 --- a/src/univalue/configure.ac +++ /dev/null @@ -1,72 +0,0 @@ -m4_define([libunivalue_major_version], [1]) -m4_define([libunivalue_minor_version], [1]) -m4_define([libunivalue_micro_version], [4]) -m4_define([libunivalue_interface_age], [4]) -# If you need a modifier for the version number. -# Normally empty, but can be used to make "fixup" releases. -m4_define([libunivalue_extraversion], []) - -dnl libtool versioning from libunivalue -m4_define([libunivalue_current], [m4_eval(100 * libunivalue_minor_version + libunivalue_micro_version - libunivalue_interface_age)]) -m4_define([libunivalue_binary_age], [m4_eval(100 * libunivalue_minor_version + libunivalue_micro_version)]) -m4_define([libunivalue_revision], [libunivalue_interface_age]) -m4_define([libunivalue_age], [m4_eval(libunivalue_binary_age - libunivalue_interface_age)]) -m4_define([libunivalue_version], [libunivalue_major_version().libunivalue_minor_version().libunivalue_micro_version()libunivalue_extraversion()]) - - -AC_INIT([univalue], [1.0.4], - [http://github.com/jgarzik/univalue/]) - -dnl make the compilation flags quiet unless V=1 is used -m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) - -AC_PREREQ(2.60) -AC_CONFIG_SRCDIR([lib/univalue.cpp]) -AC_CONFIG_AUX_DIR([build-aux]) -AC_CONFIG_MACRO_DIR([build-aux/m4]) -AC_CONFIG_HEADERS([univalue-config.h]) -AM_INIT_AUTOMAKE([subdir-objects foreign]) - -LIBUNIVALUE_MAJOR_VERSION=libunivalue_major_version -LIBUNIVALUE_MINOR_VERSION=libunivalue_minor_version -LIBUNIVALUE_MICRO_VERSION=libunivalue_micro_version -LIBUNIVALUE_INTERFACE_AGE=libunivalue_interface_age - -# ABI version -# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -LIBUNIVALUE_CURRENT=libunivalue_current -LIBUNIVALUE_REVISION=libunivalue_revision -LIBUNIVALUE_AGE=libunivalue_age - -AC_SUBST(LIBUNIVALUE_CURRENT) -AC_SUBST(LIBUNIVALUE_REVISION) -AC_SUBST(LIBUNIVALUE_AGE) - -LT_INIT -LT_LANG([C++]) - -dnl Require C++11 compiler (no GNU extensions) -AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault]) - -case $host in - *mingw*) - LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static" - ;; -esac - -BUILD_EXEEXT= -case $build in - *mingw*) - BUILD_EXEEXT=".exe" - ;; -esac - -AC_CONFIG_FILES([ - Makefile - pc/libunivalue.pc - pc/libunivalue-uninstalled.pc]) - -AC_SUBST(LIBTOOL_APP_LDFLAGS) -AC_SUBST(BUILD_EXEEXT) -AC_OUTPUT - diff --git a/src/univalue/gen/gen.cpp b/src/univalue/gen/gen.cpp deleted file mode 100644 index b8a6c73f4ec4..000000000000 --- a/src/univalue/gen/gen.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2014 BitPay Inc. -// Distributed under the MIT software license, see the accompanying -// file COPYING or https://opensource.org/licenses/mit-license.php. - -// -// To re-create univalue_escapes.h: -// $ g++ -o gen gen.cpp -// $ ./gen > univalue_escapes.h -// - -#include -#include -#include "univalue.h" - -static bool initEscapes; -static std::string escapes[256]; - -static void initJsonEscape() -{ - // Escape all lower control characters (some get overridden with smaller sequences below) - for (int ch=0x00; ch<0x20; ++ch) { - char tmpbuf[20]; - snprintf(tmpbuf, sizeof(tmpbuf), "\\u%04x", ch); - escapes[ch] = std::string(tmpbuf); - } - - escapes[(int)'"'] = "\\\""; - escapes[(int)'\\'] = "\\\\"; - escapes[(int)'\b'] = "\\b"; - escapes[(int)'\f'] = "\\f"; - escapes[(int)'\n'] = "\\n"; - escapes[(int)'\r'] = "\\r"; - escapes[(int)'\t'] = "\\t"; - escapes[(int)'\x7f'] = "\\u007f"; // U+007F DELETE - - initEscapes = true; -} - -static void outputEscape() -{ - printf( "// Automatically generated file. Do not modify.\n" - "#ifndef BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n" - "#define BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n" - "static const char *escapes[256] = {\n"); - - for (unsigned int i = 0; i < 256; i++) { - if (escapes[i].empty()) { - printf("\tnullptr,\n"); - } else { - printf("\t\""); - - unsigned int si; - for (si = 0; si < escapes[i].size(); si++) { - char ch = escapes[i][si]; - switch (ch) { - case '"': - printf("\\\""); - break; - case '\\': - printf("\\\\"); - break; - default: - printf("%c", escapes[i][si]); - break; - } - } - - printf("\",\n"); - } - } - - printf( "};\n" - "#endif // BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n"); -} - -int main (int argc, char *argv[]) -{ - initJsonEscape(); - outputEscape(); - return 0; -} - diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h index 0742f9fcb157..ec4a1aae64b8 100644 --- a/src/univalue/include/univalue.h +++ b/src/univalue/include/univalue.h @@ -3,61 +3,58 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. -#ifndef __UNIVALUE_H__ -#define __UNIVALUE_H__ - -#include -#include +#ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H +#define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H +#include +#include +#include +#include +#include #include +#include +#include #include -#include -#include class UniValue { public: enum VType { VNULL, VOBJ, VARR, VSTR, VNUM, VBOOL, }; UniValue() { typ = VNULL; } - UniValue(UniValue::VType initialType, const std::string& initialStr = "") { - typ = initialType; - val = initialStr; - } - UniValue(uint64_t val_) { - setInt(val_); - } - UniValue(int64_t val_) { - setInt(val_); - } - UniValue(bool val_) { - setBool(val_); - } - UniValue(int val_) { - setInt(val_); - } - UniValue(double val_) { - setFloat(val_); - } - UniValue(const std::string& val_) { - setStr(val_); - } - UniValue(const char *val_) { - std::string s(val_); - setStr(s); + UniValue(UniValue::VType type, std::string str = {}) : typ{type}, val{std::move(str)} {} + template >, + std::enable_if_t || // setFloat + std::is_same_v || // setBool + std::is_signed_v || std::is_unsigned_v || // setInt + std::is_constructible_v, // setStr + bool> = true> + UniValue(Ref&& val) + { + if constexpr (std::is_floating_point_v) { + setFloat(val); + } else if constexpr (std::is_same_v) { + setBool(val); + } else if constexpr (std::is_signed_v) { + setInt(int64_t{val}); + } else if constexpr (std::is_unsigned_v) { + setInt(uint64_t{val}); + } else { + setStr(std::string{std::forward(val)}); + } } void clear(); - bool setNull(); - bool setBool(bool val); - bool setNumStr(const std::string& val); - bool setInt(uint64_t val); - bool setInt(int64_t val); - bool setInt(int val_) { return setInt((int64_t)val_); } - bool setFloat(double val); - bool setStr(const std::string& val); - bool setArray(); - bool setObject(); + void setNull(); + void setBool(bool val); + void setNumStr(std::string str); + void setInt(uint64_t val); + void setInt(int64_t val); + void setInt(int val_) { return setInt(int64_t{val_}); } + void setFloat(double val); + void setStr(std::string str); + void setArray(); + void setObject(); enum VType getType() const { return typ; } const std::string& getValStr() const { return val; } @@ -81,79 +78,21 @@ class UniValue { bool isArray() const { return (typ == VARR); } bool isObject() const { return (typ == VOBJ); } - bool push_back(const UniValue& val); - bool push_back(const std::string& val_) { - UniValue tmpVal(VSTR, val_); - return push_back(tmpVal); - } - bool push_back(const char *val_) { - std::string s(val_); - return push_back(s); - } - bool push_back(uint64_t val_) { - UniValue tmpVal(val_); - return push_back(tmpVal); - } - bool push_back(int64_t val_) { - UniValue tmpVal(val_); - return push_back(tmpVal); - } - bool push_back(bool val_) { - UniValue tmpVal(val_); - return push_back(tmpVal); - } - bool push_back(int val_) { - UniValue tmpVal(val_); - return push_back(tmpVal); - } - bool push_back(double val_) { - UniValue tmpVal(val_); - return push_back(tmpVal); - } - bool push_backV(const std::vector& vec); + void push_back(const UniValue& val); + void push_backV(const std::vector& vec); template - bool push_backV(It first, It last); + void push_backV(It first, It last); void __pushKV(const std::string& key, const UniValue& val); - bool pushKV(const std::string& key, const UniValue& val); - bool pushKV(const std::string& key, const std::string& val_) { - UniValue tmpVal(VSTR, val_); - return pushKV(key, tmpVal); - } - bool pushKV(const std::string& key, const char *val_) { - std::string _val(val_); - return pushKV(key, _val); - } - bool pushKV(const std::string& key, int64_t val_) { - UniValue tmpVal(val_); - return pushKV(key, tmpVal); - } - bool pushKV(const std::string& key, uint64_t val_) { - UniValue tmpVal(val_); - return pushKV(key, tmpVal); - } - bool pushKV(const std::string& key, bool val_) { - UniValue tmpVal(val_); - return pushKV(key, tmpVal); - } - bool pushKV(const std::string& key, int val_) { - UniValue tmpVal((int64_t)val_); - return pushKV(key, tmpVal); - } - bool pushKV(const std::string& key, double val_) { - UniValue tmpVal(val_); - return pushKV(key, tmpVal); - } - bool pushKVs(const UniValue& obj); + void pushKV(const std::string& key, const UniValue& val); + void pushKVs(const UniValue& obj); std::string write(unsigned int prettyIndent = 0, unsigned int indentLevel = 0) const; bool read(const char *raw, size_t len); bool read(const char *raw) { return read(raw, strlen(raw)); } - bool read(const std::string& rawStr) { - return read(rawStr.data(), rawStr.size()); - } + bool read(std::string_view raw) { return read(raw.data(), raw.size()); } private: UniValue::VType typ; @@ -170,24 +109,35 @@ class UniValue { // value is of unexpected type const std::vector& getKeys() const; const std::vector& getValues() const; + template + auto getInt() const + { + static_assert(std::is_integral::value); + if (typ != VNUM) { + throw std::runtime_error("JSON value is not an integer as expected"); + } + Int result; + const auto [first_nonmatching, error_condition] = std::from_chars(val.data(), val.data() + val.size(), result); + if (first_nonmatching != val.data() + val.size() || error_condition != std::errc{}) { + throw std::runtime_error("JSON integer out of range"); + } + return result; + } bool get_bool() const; const std::string& get_str() const; - int get_int() const; - int64_t get_int64() const; double get_real() const; const UniValue& get_obj() const; const UniValue& get_array() const; enum VType type() const { return getType(); } - friend const UniValue& find_value( const UniValue& obj, const std::string& name); + const UniValue& find_value(std::string_view key) const; }; template -bool UniValue::push_backV(It first, It last) +void UniValue::push_backV(It first, It last) { - if (typ != VARR) return false; + if (typ != VARR) throw std::runtime_error{"JSON value is not an array as expected"}; values.insert(values.end(), first, last); - return true; } enum jtokentype { @@ -245,6 +195,4 @@ static inline bool json_isspace(int ch) extern const UniValue NullUniValue; -const UniValue& find_value( const UniValue& obj, const std::string& name); - -#endif // __UNIVALUE_H__ +#endif // BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H diff --git a/src/univalue/lib/univalue_escapes.h b/src/univalue/include/univalue_escapes.h similarity index 93% rename from src/univalue/lib/univalue_escapes.h rename to src/univalue/include/univalue_escapes.h index 3f714f8e5bc4..83767e8ac5d8 100644 --- a/src/univalue/lib/univalue_escapes.h +++ b/src/univalue/include/univalue_escapes.h @@ -1,6 +1,5 @@ -// Automatically generated file. Do not modify. -#ifndef BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H -#define BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H +#ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_ESCAPES_H +#define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_ESCAPES_H static const char *escapes[256] = { "\\u0000", "\\u0001", @@ -259,4 +258,4 @@ static const char *escapes[256] = { nullptr, nullptr, }; -#endif // BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H +#endif // BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_ESCAPES_H diff --git a/src/univalue/lib/univalue_utffilter.h b/src/univalue/include/univalue_utffilter.h similarity index 87% rename from src/univalue/lib/univalue_utffilter.h rename to src/univalue/include/univalue_utffilter.h index 95b97b29b756..f688eaaa30f9 100644 --- a/src/univalue/lib/univalue_utffilter.h +++ b/src/univalue/include/univalue_utffilter.h @@ -1,11 +1,15 @@ // Copyright 2016 Wladimir J. van der Laan // Distributed under the MIT software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. -#ifndef UNIVALUE_UTFFILTER_H -#define UNIVALUE_UTFFILTER_H +#ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_UTFFILTER_H +#define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_UTFFILTER_H #include +/** + * Filter that generates and validates UTF-8, as well as collates UTF-16 + * surrogate pairs as specified in RFC4627. + */ class JSONUTF8StringFilter { public: @@ -44,8 +48,7 @@ class JSONUTF8StringFilter // Write codepoint directly, possibly collating surrogate pairs void push_back_u(unsigned int codepoint_) { - // Only accept full codepoints in open state - if (state) + if (state) // Only accept full codepoints in open state is_valid = false; if (codepoint_ >= 0xD800 && codepoint_ < 0xDC00) { // First half of surrogate pair if (surpair) // Two subsequent surrogate pair openers - fail @@ -57,10 +60,10 @@ class JSONUTF8StringFilter // Compute code point from UTF-16 surrogate pair append_codepoint(0x10000 | ((surpair - 0xD800)<<10) | (codepoint_ - 0xDC00)); surpair = 0; - } else // First half of surrogate pair not followed by second + } else // Second half doesn't follow a first half - fail is_valid = false; } else { - if (surpair) // First half of surrogate pair not followed by second + if (surpair) // First half of surrogate pair not followed by second - fail is_valid = false; else append_codepoint(codepoint_); @@ -80,7 +83,9 @@ class JSONUTF8StringFilter // Current UTF-8 decoding state unsigned int codepoint; int state; // Top bit to be filled in for next UTF-8 byte, or 0 - // Keep track of this state to handle the following section of RFC4627: + + // Keep track of the following state to handle the following section of + // RFC4627: // // To escape an extended character that is not in the Basic Multilingual // Plane, the character is represented as a twelve-character sequence, @@ -89,7 +94,7 @@ class JSONUTF8StringFilter // "\uD834\uDD1E". // // Two subsequent \u.... may have to be replaced with one actual codepoint. - unsigned int surpair; // First of UTF-16 surrogate pair + unsigned int surpair; // First half of open UTF-16 surrogate pair, or 0 void append_codepoint(unsigned int codepoint_) { @@ -111,4 +116,4 @@ class JSONUTF8StringFilter } }; -#endif +#endif // BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_UTFFILTER_H diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp index c4e59fae744b..a00c9f348146 100644 --- a/src/univalue/lib/univalue.cpp +++ b/src/univalue/lib/univalue.cpp @@ -3,12 +3,15 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. -#include +#include + #include +#include +#include #include -#include - -#include "univalue.h" +#include +#include +#include const UniValue NullUniValue; @@ -20,19 +23,17 @@ void UniValue::clear() values.clear(); } -bool UniValue::setNull() +void UniValue::setNull() { clear(); - return true; } -bool UniValue::setBool(bool val_) +void UniValue::setBool(bool val_) { clear(); typ = VBOOL; if (val_) val = "1"; - return true; } static bool validNumStr(const std::string& s) @@ -43,18 +44,18 @@ static bool validNumStr(const std::string& s) return (tt == JTOK_NUMBER); } -bool UniValue::setNumStr(const std::string& val_) +void UniValue::setNumStr(std::string str) { - if (!validNumStr(val_)) - return false; + if (!validNumStr(str)) { + throw std::runtime_error{"The string '" + str + "' is not a valid JSON number"}; + } clear(); typ = VNUM; - val = val_; - return true; + val = std::move(str); } -bool UniValue::setInt(uint64_t val_) +void UniValue::setInt(uint64_t val_) { std::ostringstream oss; @@ -63,7 +64,7 @@ bool UniValue::setInt(uint64_t val_) return setNumStr(oss.str()); } -bool UniValue::setInt(int64_t val_) +void UniValue::setInt(int64_t val_) { std::ostringstream oss; @@ -72,86 +73,73 @@ bool UniValue::setInt(int64_t val_) return setNumStr(oss.str()); } -bool UniValue::setFloat(double val_) +void UniValue::setFloat(double val_) { std::ostringstream oss; oss << std::setprecision(16) << val_; - bool ret = setNumStr(oss.str()); - typ = VNUM; - return ret; + return setNumStr(oss.str()); } -bool UniValue::setStr(const std::string& val_) +void UniValue::setStr(std::string str) { clear(); typ = VSTR; - val = val_; - return true; + val = std::move(str); } -bool UniValue::setArray() +void UniValue::setArray() { clear(); typ = VARR; - return true; } -bool UniValue::setObject() +void UniValue::setObject() { clear(); typ = VOBJ; - return true; } -bool UniValue::push_back(const UniValue& val_) +void UniValue::push_back(const UniValue& val_) { - if (typ != VARR) - return false; + if (typ != VARR) throw std::runtime_error{"JSON value is not an array as expected"}; values.push_back(val_); - return true; } -bool UniValue::push_backV(const std::vector& vec) +void UniValue::push_backV(const std::vector& vec) { - if (typ != VARR) - return false; + if (typ != VARR) throw std::runtime_error{"JSON value is not an array as expected"}; values.insert(values.end(), vec.begin(), vec.end()); - - return true; } void UniValue::__pushKV(const std::string& key, const UniValue& val_) { + if (typ != VOBJ) throw std::runtime_error{"JSON value is not an object as expected"}; + keys.push_back(key); values.push_back(val_); } -bool UniValue::pushKV(const std::string& key, const UniValue& val_) +void UniValue::pushKV(const std::string& key, const UniValue& val_) { - if (typ != VOBJ) - return false; + if (typ != VOBJ) throw std::runtime_error{"JSON value is not an object as expected"}; size_t idx; if (findKey(key, idx)) values[idx] = val_; else __pushKV(key, val_); - return true; } -bool UniValue::pushKVs(const UniValue& obj) +void UniValue::pushKVs(const UniValue& obj) { - if (typ != VOBJ || obj.typ != VOBJ) - return false; + if (typ != VOBJ || obj.typ != VOBJ) throw std::runtime_error{"JSON value is not an object as expected"}; for (size_t i = 0; i < obj.keys.size(); i++) __pushKV(obj.keys[i], obj.values.at(i)); - - return true; } void UniValue::getObjMap(std::map& kv) const @@ -233,12 +221,13 @@ const char *uvTypeName(UniValue::VType t) return nullptr; } -const UniValue& find_value(const UniValue& obj, const std::string& name) +const UniValue& UniValue::find_value(std::string_view key) const { - for (unsigned int i = 0; i < obj.keys.size(); i++) - if (obj.keys[i] == name) - return obj.values.at(i); - + for (unsigned int i = 0; i < keys.size(); ++i) { + if (keys[i] == key) { + return values.at(i); + } + } return NullUniValue; } diff --git a/src/univalue/lib/univalue_get.cpp b/src/univalue/lib/univalue_get.cpp index 5af89a3561c1..9bbdb1fe69b9 100644 --- a/src/univalue/lib/univalue_get.cpp +++ b/src/univalue/lib/univalue_get.cpp @@ -3,17 +3,18 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include #include -#include +#include #include - -#include "univalue.h" +#include +#include +#include namespace { @@ -28,37 +29,6 @@ static bool ParsePrechecks(const std::string& str) return true; } -bool ParseInt32(const std::string& str, int32_t *out) -{ - if (!ParsePrechecks(str)) - return false; - char *endp = nullptr; - errno = 0; // strtol will not set errno if valid - long int n = strtol(str.c_str(), &endp, 10); - if(out) *out = (int32_t)n; - // Note that strtol returns a *long int*, so even if strtol doesn't report an over/underflow - // we still have to check that the returned value is within the range of an *int32_t*. On 64-bit - // platforms the size of these types may be different. - return endp && *endp == 0 && !errno && - n >= std::numeric_limits::min() && - n <= std::numeric_limits::max(); -} - -bool ParseInt64(const std::string& str, int64_t *out) -{ - if (!ParsePrechecks(str)) - return false; - char *endp = nullptr; - errno = 0; // strtoll will not set errno if valid - long long int n = strtoll(str.c_str(), &endp, 10); - if(out) *out = (int64_t)n; - // Note that strtoll returns a *long long int*, so even if strtol doesn't report a over/underflow - // we still have to check that the returned value is within the range of an *int64_t*. - return endp && *endp == 0 && !errno && - n >= std::numeric_limits::min() && - n <= std::numeric_limits::max(); -} - bool ParseDouble(const std::string& str, double *out) { if (!ParsePrechecks(str)) @@ -102,26 +72,6 @@ const std::string& UniValue::get_str() const return getValStr(); } -int UniValue::get_int() const -{ - if (typ != VNUM) - throw std::runtime_error("JSON value is not an integer as expected"); - int32_t retval; - if (!ParseInt32(getValStr(), &retval)) - throw std::runtime_error("JSON integer out of range"); - return retval; -} - -int64_t UniValue::get_int64() const -{ - if (typ != VNUM) - throw std::runtime_error("JSON value is not an integer as expected"); - int64_t retval; - if (!ParseInt64(getValStr(), &retval)) - throw std::runtime_error("JSON integer out of range"); - return retval; -} - double UniValue::get_real() const { if (typ != VNUM) diff --git a/src/univalue/lib/univalue_read.cpp b/src/univalue/lib/univalue_read.cpp index be39bfe57a7a..2f2385383c14 100644 --- a/src/univalue/lib/univalue_read.cpp +++ b/src/univalue/lib/univalue_read.cpp @@ -2,11 +2,14 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. -#include +#include +#include + +#include +#include +#include +#include #include -#include -#include "univalue.h" -#include "univalue_utffilter.h" /* * According to stackexchange, the original json test suite wanted @@ -14,7 +17,7 @@ * so we will follow PHP's lead, which should be more than sufficient * (further stackexchange comments indicate depth > 32 rarely occurs). */ -static const size_t MAX_JSON_DEPTH = 512; +static constexpr size_t MAX_JSON_DEPTH = 512; static bool json_isdigit(int ch) { diff --git a/src/univalue/lib/univalue_write.cpp b/src/univalue/lib/univalue_write.cpp index 3a2c580c7f69..4a3cbba20fda 100644 --- a/src/univalue/lib/univalue_write.cpp +++ b/src/univalue/lib/univalue_write.cpp @@ -2,10 +2,12 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. -#include -#include -#include "univalue.h" -#include "univalue_escapes.h" +#include +#include + +#include +#include +#include static std::string json_escape(const std::string& inS) { diff --git a/src/univalue/pc/libunivalue-uninstalled.pc.in b/src/univalue/pc/libunivalue-uninstalled.pc.in deleted file mode 100644 index b7f53e875e6e..000000000000 --- a/src/univalue/pc/libunivalue-uninstalled.pc.in +++ /dev/null @@ -1,9 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: libunivalue -Description: libunivalue, C++ universal value object and JSON library -Version: @VERSION@ -Libs: ${pc_top_builddir}/${pcfiledir}/libunivalue.la diff --git a/src/univalue/pc/libunivalue.pc.in b/src/univalue/pc/libunivalue.pc.in deleted file mode 100644 index 358a2d5f7321..000000000000 --- a/src/univalue/pc/libunivalue.pc.in +++ /dev/null @@ -1,10 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: libunivalue -Description: libunivalue, C++ universal value object and JSON library -Version: @VERSION@ -Libs: -L${libdir} -lunivalue -Cflags: -I${includedir} diff --git a/src/univalue/sources.mk b/src/univalue/sources.mk index efab6d277f93..5e4d9c383199 100644 --- a/src/univalue/sources.mk +++ b/src/univalue/sources.mk @@ -1,21 +1,15 @@ -# - All variables are namespaced with UNIVALUE_ to avoid colliding with -# downstream makefiles. # - All Variables ending in _HEADERS or _SOURCES confuse automake, so the # _INT postfix is applied. # - Convenience variables, for example a UNIVALUE_TEST_DIR should not be used # as they interfere with automatic dependency generation -# - The %reldir% is the relative path from the Makefile.am. This allows -# downstreams to use these variables without having to manually account for -# the path change. +# - The %reldir% is the relative path from the Makefile.am. UNIVALUE_INCLUDE_DIR_INT = %reldir%/include UNIVALUE_DIST_HEADERS_INT = UNIVALUE_DIST_HEADERS_INT += %reldir%/include/univalue.h - -UNIVALUE_LIB_HEADERS_INT = -UNIVALUE_LIB_HEADERS_INT += %reldir%/lib/univalue_utffilter.h -UNIVALUE_LIB_HEADERS_INT += %reldir%/lib/univalue_escapes.h +UNIVALUE_DIST_HEADERS_INT += %reldir%/include/univalue_utffilter.h +UNIVALUE_DIST_HEADERS_INT += %reldir%/include/univalue_escapes.h UNIVALUE_LIB_SOURCES_INT = UNIVALUE_LIB_SOURCES_INT += %reldir%/lib/univalue.cpp @@ -31,9 +25,6 @@ UNIVALUE_TEST_UNITESTER_INT += %reldir%/test/unitester.cpp UNIVALUE_TEST_JSON_INT = UNIVALUE_TEST_JSON_INT += %reldir%/test/test_json.cpp -UNIVALUE_TEST_NO_NUL_INT = -UNIVALUE_TEST_NO_NUL_INT += %reldir%/test/no_nul.cpp - UNIVALUE_TEST_OBJECT_INT = UNIVALUE_TEST_OBJECT_INT += %reldir%/test/object.cpp diff --git a/src/univalue/test/.gitignore b/src/univalue/test/.gitignore index 7b27cf0da290..5812c96b1434 100644 --- a/src/univalue/test/.gitignore +++ b/src/univalue/test/.gitignore @@ -2,7 +2,6 @@ object unitester test_json -no_nul *.trs *.log diff --git a/src/univalue/test/no_nul.cpp b/src/univalue/test/no_nul.cpp deleted file mode 100644 index 83d292200bf8..000000000000 --- a/src/univalue/test/no_nul.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "univalue.h" - -int main (int argc, char *argv[]) -{ - char buf[] = "___[1,2,3]___"; - UniValue val; - return val.read(buf + 3, 7) ? 0 : 1; -} diff --git a/src/univalue/test/object.cpp b/src/univalue/test/object.cpp index 55510f0e0ea4..ccb5024a1eca 100644 --- a/src/univalue/test/object.cpp +++ b/src/univalue/test/object.cpp @@ -3,17 +3,17 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. -#include -#include -#include -#include +#include + #include +#include +#include +#include #include -#include +#include +#include +#include -#define BOOST_FIXTURE_TEST_SUITE(a, b) -#define BOOST_AUTO_TEST_CASE(funcName) void funcName() -#define BOOST_AUTO_TEST_SUITE_END() #define BOOST_CHECK(expr) assert(expr) #define BOOST_CHECK_EQUAL(v1, v2) assert((v1) == (v2)) #define BOOST_CHECK_THROW(stmt, excMatch) { \ @@ -33,9 +33,7 @@ } \ } -BOOST_FIXTURE_TEST_SUITE(univalue_tests, BasicTestingSetup) - -BOOST_AUTO_TEST_CASE(univalue_constructor) +void univalue_constructor() { UniValue v1; BOOST_CHECK(v1.isNull()); @@ -48,7 +46,7 @@ BOOST_AUTO_TEST_CASE(univalue_constructor) BOOST_CHECK_EQUAL(v3.getValStr(), "foo"); UniValue numTest; - BOOST_CHECK(numTest.setNumStr("82")); + numTest.setNumStr("82"); BOOST_CHECK(numTest.isNum()); BOOST_CHECK_EQUAL(numTest.getValStr(), "82"); @@ -83,30 +81,47 @@ BOOST_AUTO_TEST_CASE(univalue_constructor) BOOST_CHECK_EQUAL(v9.getValStr(), "zappa"); } -BOOST_AUTO_TEST_CASE(univalue_typecheck) +void univalue_push_throw() +{ + UniValue j; + BOOST_CHECK_THROW(j.push_back(1), std::runtime_error); + BOOST_CHECK_THROW(j.push_backV({1}), std::runtime_error); + BOOST_CHECK_THROW(j.__pushKV("k", 1), std::runtime_error); + BOOST_CHECK_THROW(j.pushKV("k", 1), std::runtime_error); + BOOST_CHECK_THROW(j.pushKVs({}), std::runtime_error); +} + +void univalue_typecheck() { UniValue v1; - BOOST_CHECK(v1.setNumStr("1")); + v1.setNumStr("1"); BOOST_CHECK(v1.isNum()); BOOST_CHECK_THROW(v1.get_bool(), std::runtime_error); + { + UniValue v_negative; + v_negative.setNumStr("-1"); + BOOST_CHECK_THROW(v_negative.getInt(), std::runtime_error); + BOOST_CHECK_EQUAL(v_negative.getInt(), -1); + } + UniValue v2; - BOOST_CHECK(v2.setBool(true)); + v2.setBool(true); BOOST_CHECK_EQUAL(v2.get_bool(), true); - BOOST_CHECK_THROW(v2.get_int(), std::runtime_error); + BOOST_CHECK_THROW(v2.getInt(), std::runtime_error); UniValue v3; - BOOST_CHECK(v3.setNumStr("32482348723847471234")); - BOOST_CHECK_THROW(v3.get_int64(), std::runtime_error); - BOOST_CHECK(v3.setNumStr("1000")); - BOOST_CHECK_EQUAL(v3.get_int64(), 1000); + v3.setNumStr("32482348723847471234"); + BOOST_CHECK_THROW(v3.getInt(), std::runtime_error); + v3.setNumStr("1000"); + BOOST_CHECK_EQUAL(v3.getInt(), 1000); UniValue v4; - BOOST_CHECK(v4.setNumStr("2147483648")); - BOOST_CHECK_EQUAL(v4.get_int64(), 2147483648); - BOOST_CHECK_THROW(v4.get_int(), std::runtime_error); - BOOST_CHECK(v4.setNumStr("1000")); - BOOST_CHECK_EQUAL(v4.get_int(), 1000); + v4.setNumStr("2147483648"); + BOOST_CHECK_EQUAL(v4.getInt(), 2147483648); + BOOST_CHECK_THROW(v4.getInt(), std::runtime_error); + v4.setNumStr("1000"); + BOOST_CHECK_EQUAL(v4.getInt(), 1000); BOOST_CHECK_THROW(v4.get_str(), std::runtime_error); BOOST_CHECK_EQUAL(v4.get_real(), 1000); BOOST_CHECK_THROW(v4.get_array(), std::runtime_error); @@ -118,84 +133,92 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck) BOOST_CHECK(v5.read("[true, 10]")); BOOST_CHECK_NO_THROW(v5.get_array()); std::vector vals = v5.getValues(); - BOOST_CHECK_THROW(vals[0].get_int(), std::runtime_error); + BOOST_CHECK_THROW(vals[0].getInt(), std::runtime_error); BOOST_CHECK_EQUAL(vals[0].get_bool(), true); - BOOST_CHECK_EQUAL(vals[1].get_int(), 10); + BOOST_CHECK_EQUAL(vals[1].getInt(), 10); BOOST_CHECK_THROW(vals[1].get_bool(), std::runtime_error); } -BOOST_AUTO_TEST_CASE(univalue_set) +void univalue_set() { UniValue v(UniValue::VSTR, "foo"); v.clear(); BOOST_CHECK(v.isNull()); BOOST_CHECK_EQUAL(v.getValStr(), ""); - BOOST_CHECK(v.setObject()); + v.setObject(); BOOST_CHECK(v.isObject()); BOOST_CHECK_EQUAL(v.size(), 0); BOOST_CHECK_EQUAL(v.getType(), UniValue::VOBJ); BOOST_CHECK(v.empty()); - BOOST_CHECK(v.setArray()); + v.setArray(); BOOST_CHECK(v.isArray()); BOOST_CHECK_EQUAL(v.size(), 0); - BOOST_CHECK(v.setStr("zum")); + v.setStr("zum"); BOOST_CHECK(v.isStr()); BOOST_CHECK_EQUAL(v.getValStr(), "zum"); - BOOST_CHECK(v.setFloat(-1.01)); + { + std::string_view sv{"ab\0c", 4}; + UniValue j{sv}; + BOOST_CHECK(j.isStr()); + BOOST_CHECK_EQUAL(j.getValStr(), sv); + BOOST_CHECK_EQUAL(j.write(), "\"ab\\u0000c\""); + } + + v.setFloat(-1.01); BOOST_CHECK(v.isNum()); BOOST_CHECK_EQUAL(v.getValStr(), "-1.01"); - BOOST_CHECK(v.setInt((int)1023)); + v.setInt(int{1023}); BOOST_CHECK(v.isNum()); BOOST_CHECK_EQUAL(v.getValStr(), "1023"); - BOOST_CHECK(v.setInt((int64_t)-1023LL)); + v.setInt(int64_t{-1023LL}); BOOST_CHECK(v.isNum()); BOOST_CHECK_EQUAL(v.getValStr(), "-1023"); - BOOST_CHECK(v.setInt((uint64_t)1023ULL)); + v.setInt(uint64_t{1023ULL}); BOOST_CHECK(v.isNum()); BOOST_CHECK_EQUAL(v.getValStr(), "1023"); - BOOST_CHECK(v.setNumStr("-688")); + v.setNumStr("-688"); BOOST_CHECK(v.isNum()); BOOST_CHECK_EQUAL(v.getValStr(), "-688"); - BOOST_CHECK(v.setBool(false)); + v.setBool(false); BOOST_CHECK_EQUAL(v.isBool(), true); BOOST_CHECK_EQUAL(v.isTrue(), false); BOOST_CHECK_EQUAL(v.isFalse(), true); BOOST_CHECK_EQUAL(v.getBool(), false); - BOOST_CHECK(v.setBool(true)); + v.setBool(true); BOOST_CHECK_EQUAL(v.isBool(), true); BOOST_CHECK_EQUAL(v.isTrue(), true); BOOST_CHECK_EQUAL(v.isFalse(), false); BOOST_CHECK_EQUAL(v.getBool(), true); - BOOST_CHECK(!v.setNumStr("zombocom")); + BOOST_CHECK_THROW(v.setNumStr("zombocom"), std::runtime_error); - BOOST_CHECK(v.setNull()); + v.setNull(); BOOST_CHECK(v.isNull()); } -BOOST_AUTO_TEST_CASE(univalue_array) +void univalue_array() { UniValue arr(UniValue::VARR); UniValue v((int64_t)1023LL); - BOOST_CHECK(arr.push_back(v)); + arr.push_back(v); std::string vStr("zippy"); - BOOST_CHECK(arr.push_back(vStr)); + arr.push_back(vStr); const char *s = "pippy"; - BOOST_CHECK(arr.push_back(s)); + arr.push_back(s); std::vector vec; v.setStr("boing"); @@ -204,13 +227,13 @@ BOOST_AUTO_TEST_CASE(univalue_array) v.setStr("going"); vec.push_back(v); - BOOST_CHECK(arr.push_backV(vec)); + arr.push_backV(vec); - BOOST_CHECK(arr.push_back((uint64_t) 400ULL)); - BOOST_CHECK(arr.push_back((int64_t) -400LL)); - BOOST_CHECK(arr.push_back((int) -401)); - BOOST_CHECK(arr.push_back(-40.1)); - BOOST_CHECK(arr.push_back(true)); + arr.push_back(uint64_t{400ULL}); + arr.push_back(int64_t{-400LL}); + arr.push_back(int{-401}); + arr.push_back(-40.1); + arr.push_back(true); BOOST_CHECK_EQUAL(arr.empty(), false); BOOST_CHECK_EQUAL(arr.size(), 10); @@ -243,7 +266,7 @@ BOOST_AUTO_TEST_CASE(univalue_array) BOOST_CHECK_EQUAL(arr.size(), 0); } -BOOST_AUTO_TEST_CASE(univalue_object) +void univalue_object() { UniValue obj(UniValue::VOBJ); std::string strKey, strVal; @@ -251,39 +274,39 @@ BOOST_AUTO_TEST_CASE(univalue_object) strKey = "age"; v.setInt(100); - BOOST_CHECK(obj.pushKV(strKey, v)); + obj.pushKV(strKey, v); strKey = "first"; strVal = "John"; - BOOST_CHECK(obj.pushKV(strKey, strVal)); + obj.pushKV(strKey, strVal); strKey = "last"; - const char *cVal = "Smith"; - BOOST_CHECK(obj.pushKV(strKey, cVal)); + const char* cVal = "Smith"; + obj.pushKV(strKey, cVal); strKey = "distance"; - BOOST_CHECK(obj.pushKV(strKey, (int64_t) 25)); + obj.pushKV(strKey, int64_t{25}); strKey = "time"; - BOOST_CHECK(obj.pushKV(strKey, (uint64_t) 3600)); + obj.pushKV(strKey, uint64_t{3600}); strKey = "calories"; - BOOST_CHECK(obj.pushKV(strKey, (int) 12)); + obj.pushKV(strKey, int{12}); strKey = "temperature"; - BOOST_CHECK(obj.pushKV(strKey, (double) 90.012)); + obj.pushKV(strKey, double{90.012}); strKey = "moon"; - BOOST_CHECK(obj.pushKV(strKey, true)); + obj.pushKV(strKey, true); strKey = "spoon"; - BOOST_CHECK(obj.pushKV(strKey, false)); + obj.pushKV(strKey, false); UniValue obj2(UniValue::VOBJ); - BOOST_CHECK(obj2.pushKV("cat1", 9000)); - BOOST_CHECK(obj2.pushKV("cat2", 12345)); + obj2.pushKV("cat1", 9000); + obj2.pushKV("cat2", 12345); - BOOST_CHECK(obj.pushKVs(obj2)); + obj.pushKVs(obj2); BOOST_CHECK_EQUAL(obj.empty(), false); BOOST_CHECK_EQUAL(obj.size(), 11); @@ -338,7 +361,7 @@ BOOST_AUTO_TEST_CASE(univalue_object) BOOST_CHECK_EQUAL(obj.size(), 0); BOOST_CHECK_EQUAL(obj.getType(), UniValue::VNULL); - BOOST_CHECK_EQUAL(obj.setObject(), true); + obj.setObject(); UniValue uv; uv.setInt(42); obj.__pushKV("age", uv); @@ -362,7 +385,7 @@ BOOST_AUTO_TEST_CASE(univalue_object) static const char *json1 = "[1.10000000,{\"key1\":\"str\\u0000\",\"key2\":800,\"key3\":{\"name\":\"martian http://test.com\"}}]"; -BOOST_AUTO_TEST_CASE(univalue_readwrite) +void univalue_readwrite() { UniValue v; BOOST_CHECK(v.read(json1)); @@ -405,11 +428,10 @@ BOOST_AUTO_TEST_CASE(univalue_readwrite) BOOST_CHECK(!v.read("{} 42")); } -BOOST_AUTO_TEST_SUITE_END() - -int main (int argc, char *argv[]) +int main(int argc, char* argv[]) { univalue_constructor(); + univalue_push_throw(); univalue_typecheck(); univalue_set(); univalue_array(); @@ -417,4 +439,3 @@ int main (int argc, char *argv[]) univalue_readwrite(); return 0; } - diff --git a/src/univalue/test/test_json.cpp b/src/univalue/test/test_json.cpp index 2943bae2b15e..f8c10238d4db 100644 --- a/src/univalue/test/test_json.cpp +++ b/src/univalue/test/test_json.cpp @@ -4,9 +4,11 @@ // It reads JSON input from stdin and exits with code 0 if it can be parsed // successfully. It also pretty prints the parsed JSON value to stdout. +#include + #include +#include #include -#include "univalue.h" using namespace std; diff --git a/src/univalue/test/unitester.cpp b/src/univalue/test/unitester.cpp index 02e1a83c6dff..6344a5a0ab8a 100644 --- a/src/univalue/test/unitester.cpp +++ b/src/univalue/test/unitester.cpp @@ -2,26 +2,17 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or https://opensource.org/licenses/mit-license.php. -#include -#include -#include +#include + #include +#include #include -#include "univalue.h" #ifndef JSON_TEST_SRC #error JSON_TEST_SRC must point to test source directory #endif -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -#endif - std::string srcdir(JSON_TEST_SRC); -static bool test_failed = false; - -#define d_assert(expr) { if (!(expr)) { test_failed = true; fprintf(stderr, "%s failed\n", filename.c_str()); } } -#define f_assert(expr) { if (!(expr)) { test_failed = true; fprintf(stderr, "%s failed\n", __func__); } } static std::string rtrim(std::string s) { @@ -42,9 +33,9 @@ static void runtest(std::string filename, const std::string& jdata) bool testResult = val.read(jdata); if (wantPass) { - d_assert(testResult == true); + assert(testResult == true); } else { - d_assert(testResult == false); + assert(testResult == false); } if (wantRoundTrip) { @@ -142,30 +133,38 @@ void unescape_unicode_test() bool testResult; // Escaped ASCII (quote) testResult = val.read("[\"\\u0022\"]"); - f_assert(testResult); - f_assert(val[0].get_str() == "\""); + assert(testResult); + assert(val[0].get_str() == "\""); // Escaped Basic Plane character, two-byte UTF-8 testResult = val.read("[\"\\u0191\"]"); - f_assert(testResult); - f_assert(val[0].get_str() == "\xc6\x91"); + assert(testResult); + assert(val[0].get_str() == "\xc6\x91"); // Escaped Basic Plane character, three-byte UTF-8 testResult = val.read("[\"\\u2191\"]"); - f_assert(testResult); - f_assert(val[0].get_str() == "\xe2\x86\x91"); + assert(testResult); + assert(val[0].get_str() == "\xe2\x86\x91"); // Escaped Supplementary Plane character U+1d161 testResult = val.read("[\"\\ud834\\udd61\"]"); - f_assert(testResult); - f_assert(val[0].get_str() == "\xf0\x9d\x85\xa1"); + assert(testResult); + assert(val[0].get_str() == "\xf0\x9d\x85\xa1"); +} + +void no_nul_test() +{ + char buf[] = "___[1,2,3]___"; + UniValue val; + assert(val.read(buf + 3, 7)); } int main (int argc, char *argv[]) { - for (unsigned int fidx = 0; fidx < ARRAY_SIZE(filenames); fidx++) { - runtest_file(filenames[fidx]); + for (const auto& f: filenames) { + runtest_file(f); } unescape_unicode_test(); + no_nul_test(); - return test_failed ? 1 : 0; + return 0; } diff --git a/src/util/settings.h b/src/util/settings.h index ed3634923212..261a0a032f5e 100644 --- a/src/util/settings.h +++ b/src/util/settings.h @@ -20,7 +20,7 @@ namespace util { //! @note UniValue is used here for convenience and because it can be easily //! serialized in a readable format. But any other variant type that can //! be assigned strings, int64_t, and bool values and has get_str(), -//! get_int64(), get_bool(), isNum(), isBool(), isFalse(), isTrue() and +//! getInt(), get_bool(), isNum(), isBool(), isFalse(), isTrue() and //! isNull() methods can be substituted if there's a need to move away //! from UniValue. (An implementation with boost::variant was posted at //! https://github.com/bitcoin/bitcoin/pull/15934/files#r337691812) diff --git a/src/util/system.cpp b/src/util/system.cpp index 7cc212a53d51..5fa6fcc08ca5 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -626,7 +626,7 @@ std::string ArgsManager::GetArg(const std::string& strArg, const std::string& st int64_t ArgsManager::GetIntArg(const std::string& strArg, int64_t nDefault) const { const util::SettingsValue value = GetSetting(strArg); - return value.isNull() ? nDefault : value.isFalse() ? 0 : value.isTrue() ? 1 : value.isNum() ? value.get_int64() : LocaleIndependentAtoi(value.get_str()); + return value.isNull() ? nDefault : value.isFalse() ? 0 : value.isTrue() ? 1 : value.isNum() ? value.getInt() : LocaleIndependentAtoi(value.get_str()); } bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index ed19e2499500..a23ba9e7c0cc 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -232,7 +232,7 @@ RPCHelpMan addmultisigaddress() if (!request.params[2].isNull()) label = LabelFromValue(request.params[2]); - int required = request.params[0].get_int(); + int required = request.params[0].getInt(); // Get the public keys const UniValue& keys_or_addrs = request.params[1].get_array(); @@ -289,9 +289,9 @@ RPCHelpMan keypoolrefill() // 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool unsigned int kpSize = 0; if (!request.params[0].isNull()) { - if (request.params[0].get_int() < 0) + if (request.params[0].getInt() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size."); - kpSize = (unsigned int)request.params[0].get_int(); + kpSize = (unsigned int)request.params[0].getInt(); } EnsureWalletIsUnlocked(*pwallet); diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 3d6465a89ce1..af293c83b3d7 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -797,7 +797,7 @@ RPCHelpMan importelectrumwallet() // Whether to perform rescan after import int nStartHeight = 0; if (!request.params[1].isNull()) - nStartHeight = request.params[1].get_int(); + nStartHeight = request.params[1].getInt(); if (tip_height < nStartHeight) nStartHeight = tip_height; @@ -1043,7 +1043,7 @@ RPCHelpMan dumpwallet() file << "# WARNING: ACCOUNT " << i << " IS MISSING!" << "\n\n"; } } - obj.pushKV("hdaccounts", int(hdChainCurrent.CountAccounts())); + obj.pushKV("hdaccounts", hdChainCurrent.CountAccounts()); } for (std::vector >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) { @@ -1087,7 +1087,7 @@ RPCHelpMan dumpwallet() file.close(); std::string strWarning = strprintf(_("%s file contains all private keys from this wallet. Do not share it with anyone!").translated, request.params[0].get_str()); - obj.pushKV("keys", int(vKeyBirth.size())); + obj.pushKV("keys", vKeyBirth.size()); obj.pushKV("filename", filepath.utf8string()); obj.pushKV("warning", strWarning); @@ -1459,7 +1459,7 @@ static int64_t GetImportTimestamp(const UniValue& data, int64_t now) if (data.exists("timestamp")) { const UniValue& timestamp = data["timestamp"]; if (timestamp.isNum()) { - return timestamp.get_int64(); + return timestamp.getInt(); } else if (timestamp.isStr() && timestamp.get_str() == "now") { return now; } @@ -1700,7 +1700,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c next_index = range_start; if (data.exists("next_index")) { - next_index = data["next_index"].get_int64(); + next_index = data["next_index"].getInt(); // bound checks if (next_index < range_start || next_index >= range_end) { throw JSONRPCError(RPC_INVALID_PARAMETER, "next_index is out of range"); diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp index b9132d42b8a1..ffc0ad8f0c8a 100644 --- a/src/wallet/rpc/coins.cpp +++ b/src/wallet/rpc/coins.cpp @@ -39,7 +39,7 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b // Minimum confirmations int min_depth = 1; if (!params[1].isNull()) - min_depth = params[1].get_int(); + min_depth = params[1].getInt(); bool fAddLocked = (!params[2].isNull() && params[2].get_bool()); const bool include_immature_coinbase{params[3].isNull() ? false : params[3].get_bool()}; @@ -200,7 +200,7 @@ RPCHelpMan getbalance() int min_depth = 0; if (!request.params[1].isNull()) { - min_depth = request.params[1].get_int(); + min_depth = request.params[1].getInt(); } const UniValue& addlocked = request.params[2]; @@ -329,7 +329,7 @@ RPCHelpMan lockunspent() }); const uint256 txid(ParseHashO(o, "txid")); - const int nOutput = find_value(o, "vout").get_int(); + const int nOutput{o.find_value("vout").getInt()}; if (nOutput < 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative"); } @@ -568,13 +568,13 @@ RPCHelpMan listunspent() int nMinDepth = 1; if (!request.params[0].isNull()) { RPCTypeCheckArgument(request.params[0], UniValue::VNUM); - nMinDepth = request.params[0].get_int(); + nMinDepth = request.params[0].getInt(); } int nMaxDepth = 9999999; if (!request.params[1].isNull()) { RPCTypeCheckArgument(request.params[1], UniValue::VNUM); - nMaxDepth = request.params[1].get_int(); + nMaxDepth = request.params[1].getInt(); } std::set destinations; @@ -633,10 +633,10 @@ RPCHelpMan listunspent() nMinimumSumAmount = AmountFromValue(options["minimumSumAmount"]); if (options.exists("maximumCount")) - nMaximumCount = options["maximumCount"].get_int64(); + nMaximumCount = options["maximumCount"].getInt(); if (options.exists("coinType")) { - int64_t nCoinType = options["coinType"].get_int64(); + int64_t nCoinType = options["coinType"].getInt(); if (nCoinType < static_cast(CoinType::MIN_COIN_TYPE) || nCoinType > static_cast(CoinType::MAX_COIN_TYPE)) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid coinType selected. Available range: %d - %d", static_cast(CoinType::MIN_COIN_TYPE), static_cast(CoinType::MAX_COIN_TYPE))); diff --git a/src/wallet/rpc/encrypt.cpp b/src/wallet/rpc/encrypt.cpp index 56969202aeff..13cdef3d3317 100644 --- a/src/wallet/rpc/encrypt.cpp +++ b/src/wallet/rpc/encrypt.cpp @@ -56,7 +56,7 @@ RPCHelpMan walletpassphrase() strWalletPass = request.params[0].get_str().c_str(); // Get the timeout - nSleepTime = request.params[1].get_int64(); + 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."); diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index bb182f3aa90d..ef1012689961 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -417,7 +417,7 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out, } if (options.exists("changePosition") || options.exists("change_position")) { - change_position = (options.exists("change_position") ? options["change_position"] : options["changePosition"]).get_int(); + change_position = (options.exists("change_position") ? options["change_position"] : options["changePosition"]).getInt(); } const UniValue include_watching_option = options.exists("include_watching") ? options["include_watching"] : options["includeWatching"]; @@ -510,7 +510,7 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out, throw JSONRPCError(RPC_INVALID_PARAMETER, "changePosition out of bounds"); for (unsigned int idx = 0; idx < subtractFeeFromOutputs.size(); idx++) { - int pos = subtractFeeFromOutputs[idx].get_int(); + int pos = subtractFeeFromOutputs[idx].getInt(); if (setSubtractFeeFromOutputs.count(pos)) throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, duplicated position: %d", pos)); if (pos < 0) diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index 254498425d55..75588ecf8c00 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -73,7 +73,7 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons // Minimum confirmations int nMinDepth = 1; if (!params[0].isNull()) - nMinDepth = params[0].get_int(); + nMinDepth = params[0].getInt(); bool fAddLocked = false; if (!params[1].isNull()) fAddLocked = params[1].get_bool(); @@ -506,10 +506,10 @@ RPCHelpMan listtransactions() } int nCount = 10; if (!request.params[1].isNull()) - nCount = request.params[1].get_int(); + nCount = request.params[1].getInt(); int nFrom = 0; if (!request.params[2].isNull()) - nFrom = request.params[2].get_int(); + nFrom = request.params[2].getInt(); isminefilter filter = ISMINE_SPENDABLE; if (ParseIncludeWatchonly(request.params[3], *pwallet)) { @@ -632,7 +632,7 @@ RPCHelpMan listsinceblock() } if (!request.params[1].isNull()) { - target_confirms = request.params[1].get_int(); + target_confirms = request.params[1].getInt(); if (target_confirms < 1) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter"); @@ -885,14 +885,14 @@ RPCHelpMan rescanblockchain() int tip_height = pwallet->GetLastBlockHeight(); if (!request.params[0].isNull()) { - start_height = request.params[0].get_int(); + start_height = request.params[0].getInt(); if (start_height < 0 || start_height > tip_height) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid start_height"); } } if (!request.params[1].isNull()) { - stop_height = request.params[1].get_int(); + stop_height = request.params[1].getInt(); if (*stop_height < 0 || *stop_height > tip_height) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid stop_height"); } else if (*stop_height < start_height) { diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index 719b4975d829..38597ef270d3 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -107,7 +107,7 @@ static RPCHelpMan setcoinjoinrounds() const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; - int nRounds = request.params[0].get_int(); + int nRounds = request.params[0].getInt(); if (nRounds > MAX_COINJOIN_ROUNDS || nRounds < MIN_COINJOIN_ROUNDS) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid number of rounds"); @@ -138,7 +138,7 @@ static RPCHelpMan setcoinjoinamount() const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; - int nAmount = request.params[0].get_int(); + int nAmount = request.params[0].getInt(); if (nAmount > MAX_COINJOIN_AMOUNT || nAmount < MIN_COINJOIN_AMOUNT) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount of " + CURRENCY_UNIT + " as mixing goal amount"); @@ -232,24 +232,25 @@ static RPCHelpMan getwalletinfo() obj.pushKV("keypoololdest", kp_oldest.value()); } size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); - obj.pushKV("keypoolsize", (int64_t)kpExternalSize); - obj.pushKV("keypoolsize_hd_internal", (int64_t)(pwallet->GetKeyPoolSize() - kpExternalSize)); - obj.pushKV("keys_left", pwallet->nKeysLeftSinceAutoBackup); - if (pwallet->IsCrypted()) + obj.pushKV("keypoolsize", kpExternalSize); + obj.pushKV("keypoolsize_hd_internal", pwallet->GetKeyPoolSize() - kpExternalSize); + obj.pushKV("keys_left", pwallet->nKeysLeftSinceAutoBackup); + if (pwallet->IsCrypted()) { obj.pushKV("unlocked_until", pwallet->nRelockTime); - obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())); + } + obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())); if (fHDEnabled) { obj.pushKV("hdchainid", hdChainCurrent.GetID().GetHex()); - obj.pushKV("hdaccountcount", (int64_t)hdChainCurrent.CountAccounts()); + obj.pushKV("hdaccountcount", hdChainCurrent.CountAccounts()); UniValue accounts(UniValue::VARR); for (size_t i = 0; i < hdChainCurrent.CountAccounts(); ++i) { CHDAccount acc; UniValue account(UniValue::VOBJ); - account.pushKV("hdaccountindex", (int64_t)i); + account.pushKV("hdaccountindex", i); if(hdChainCurrent.GetAccount(i, acc)) { - account.pushKV("hdexternalkeyindex", (int64_t)acc.nExternalChainCounter); - account.pushKV("hdinternalkeyindex", (int64_t)acc.nInternalChainCounter); + account.pushKV("hdexternalkeyindex", acc.nExternalChainCounter); + account.pushKV("hdinternalkeyindex", acc.nInternalChainCounter); } else { account.pushKV("error", strprintf("account %d is missing", i)); } @@ -858,7 +859,7 @@ static RPCHelpMan upgradewallet() "\nUpgrade the wallet. Upgrades to the latest version if no version number is specified.\n" "New keys may be generated and a new wallet backup will need to be made.", { - {"version", RPCArg::Type::NUM, RPCArg::Default{FEATURE_LATEST}, "The version number to upgrade to. Default is the latest wallet version."} + {"version", RPCArg::Type::NUM, RPCArg::Default{int{FEATURE_LATEST}}, "The version number to upgrade to. Default is the latest wallet version."} }, RPCResult{ RPCResult::Type::OBJ, "", "", @@ -885,7 +886,7 @@ static RPCHelpMan upgradewallet() int version = 0; if (!request.params[0].isNull()) { - version = request.params[0].get_int(); + version = request.params[0].getInt(); } bilingual_str error; const int previous_version{pwallet->GetVersion()}; diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index bd73767e7405..7f6cea0186be 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -919,15 +919,15 @@ BOOST_FIXTURE_TEST_CASE(rpc_getaddressinfo, TestChain100Setup) request.params.push_back(addr); BOOST_CHECK_NO_THROW(response = wallet::getaddressinfo().HandleRequest(request).get_obj()); - BOOST_CHECK_EQUAL(find_value(response, "ismine").get_bool(), true); - BOOST_CHECK_EQUAL(find_value(response, "solvable").get_bool(), true); - BOOST_CHECK_EQUAL(find_value(response, "iswatchonly").get_bool(), false); - BOOST_CHECK_EQUAL(find_value(response, "isscript").get_bool(), false); - BOOST_CHECK_EQUAL(find_value(response, "ischange").get_bool(), true); - BOOST_CHECK(find_value(response, "pubkeys").isNull()); - BOOST_CHECK(find_value(response, "addresses").isNull()); - BOOST_CHECK(find_value(response, "sigsrequired").isNull()); - BOOST_CHECK(find_value(response, "label").isNull()); + BOOST_CHECK_EQUAL(response.find_value("ismine").get_bool(), true); + BOOST_CHECK_EQUAL(response.find_value("solvable").get_bool(), true); + BOOST_CHECK_EQUAL(response.find_value("iswatchonly").get_bool(), false); + BOOST_CHECK_EQUAL(response.find_value("isscript").get_bool(), false); + BOOST_CHECK_EQUAL(response.find_value("ischange").get_bool(), true); + BOOST_CHECK(response.find_value("pubkeys").isNull()); + BOOST_CHECK(response.find_value("addresses").isNull()); + BOOST_CHECK(response.find_value("sigsrequired").isNull()); + BOOST_CHECK(response.find_value("label").isNull()); // test p2sh/multisig std::string addr1; @@ -947,24 +947,24 @@ BOOST_FIXTURE_TEST_CASE(rpc_getaddressinfo, TestChain100Setup) BOOST_CHECK_NO_THROW(response = wallet::addmultisigaddress().HandleRequest(request)); - std::string multisig = find_value(response.get_obj(), "address").get_str(); + std::string multisig = response.get_obj().find_value("address").get_str(); request.params.clear(); request.params.setArray(); request.params.push_back(multisig); BOOST_CHECK_NO_THROW(response = wallet::getaddressinfo().HandleRequest(request).get_obj()); - BOOST_CHECK_EQUAL(find_value(response, "ismine").get_bool(), true); - BOOST_CHECK_EQUAL(find_value(response, "solvable").get_bool(), true); - BOOST_CHECK_EQUAL(find_value(response, "iswatchonly").get_bool(), false); - BOOST_CHECK_EQUAL(find_value(response, "isscript").get_bool(), true); - BOOST_CHECK_EQUAL(find_value(response, "ischange").get_bool(), false); - BOOST_CHECK_EQUAL(find_value(response, "sigsrequired").get_int(), 2); - BOOST_CHECK(find_value(response, "label").isNull()); - - UniValue labels = find_value(response, "labels").get_array(); - UniValue pubkeys = find_value(response, "pubkeys").get_array(); - UniValue addresses = find_value(response, "addresses").get_array(); + BOOST_CHECK_EQUAL(response.find_value("ismine").get_bool(), true); + BOOST_CHECK_EQUAL(response.find_value("solvable").get_bool(), true); + BOOST_CHECK_EQUAL(response.find_value("iswatchonly").get_bool(), false); + BOOST_CHECK_EQUAL(response.find_value("isscript").get_bool(), true); + BOOST_CHECK_EQUAL(response.find_value("ischange").get_bool(), false); + BOOST_CHECK_EQUAL(response.find_value("sigsrequired").getInt(), 2); + BOOST_CHECK(response.find_value("label").isNull()); + + UniValue labels = response.find_value("labels").get_array(); + UniValue pubkeys = response.find_value("pubkeys").get_array(); + UniValue addresses = response.find_value("addresses").get_array(); BOOST_CHECK_EQUAL(labels.size(), 1); BOOST_CHECK_EQUAL(labels[0].get_str(), ""); diff --git a/test/lint/README.md b/test/lint/README.md index 38e7e102c63d..704922d7abe3 100644 --- a/test/lint/README.md +++ b/test/lint/README.md @@ -46,7 +46,6 @@ To do a full check with `-r`, make sure that you have fetched the upstream repos maintained: * for `src/secp256k1`: https://github.com/bitcoin-core/secp256k1.git (branch master) * for `src/leveldb`: https://github.com/bitcoin-core/leveldb-subtree.git (branch bitcoin-fork) -* for `src/univalue`: https://github.com/bitcoin-core/univalue-subtree.git (branch master) * for `src/crypto/ctaes`: https://github.com/bitcoin-core/ctaes.git (branch master) * for `src/crc32c`: https://github.com/bitcoin-core/crc32c-subtree.git (branch bitcoin-fork) * for `src/minisketch`: https://github.com/sipa/minisketch.git (branch master) diff --git a/test/lint/lint-files.py b/test/lint/lint-files.py index 4a537501a281..ee09cea93235 100755 --- a/test/lint/lint-files.py +++ b/test/lint/lint-files.py @@ -21,7 +21,7 @@ ALLOWED_FILENAME_REGEXP = "^[a-zA-Z0-9/_.@][a-zA-Z0-9/_.@-]*$" ALLOWED_SOURCE_FILENAME_REGEXP = "^[a-z0-9_./-]+$" ALLOWED_SOURCE_FILENAME_EXCEPTION_REGEXP = ( - "^src/(dashbls/|immer/|secp256k1/|minisketch/|univalue/|test/fuzz/FuzzedDataProvider.h)" + "^src/(dashbls/|immer/|secp256k1/|minisketch/|test/fuzz/FuzzedDataProvider.h)" ) ALLOWED_PERMISSION_NON_EXECUTABLES = 0o644 ALLOWED_PERMISSION_EXECUTABLES = 0o755 diff --git a/test/lint/lint-format-strings.py b/test/lint/lint-format-strings.py index 333327e519a1..a1bd91407e48 100755 --- a/test/lint/lint-format-strings.py +++ b/test/lint/lint-format-strings.py @@ -77,7 +77,7 @@ def main(): matching_files_filtered = [] for matching_file in matching_files: - if not re.search('^src/(dashbls|leveldb|secp256k1|minisketch|tinyformat|univalue|test/fuzz/strprintf.cpp)', matching_file): + if not re.search('^src/(dashbls|leveldb|secp256k1|minisketch|tinyformat|test/fuzz/strprintf.cpp)', matching_file): matching_files_filtered.append(matching_file) matching_files_filtered.sort() diff --git a/test/lint/lint-include-guards.py b/test/lint/lint-include-guards.py index 8fd4c7d63682..e8a287cf2a15 100755 --- a/test/lint/lint-include-guards.py +++ b/test/lint/lint-include-guards.py @@ -22,7 +22,6 @@ 'src/crc32c', 'src/secp256k1', 'src/minisketch', - 'src/univalue', 'src/tinyformat.h', 'src/bench/nanobench.h', 'src/test/fuzz/FuzzedDataProvider.h', diff --git a/test/lint/lint-includes.py b/test/lint/lint-includes.py index ee897c7ed165..4a2ef0a88fad 100755 --- a/test/lint/lint-includes.py +++ b/test/lint/lint-includes.py @@ -19,7 +19,6 @@ "src/crc32c/", "src/secp256k1/", "src/minisketch/", - "src/univalue/", "src/dashbls/", "src/immer/", "src/crypto/x11/"] diff --git a/test/lint/lint-locale-dependence.py b/test/lint/lint-locale-dependence.py index ec27b620bb3b..405c346e6971 100755 --- a/test/lint/lint-locale-dependence.py +++ b/test/lint/lint-locale-dependence.py @@ -62,7 +62,6 @@ "src/secp256k1/", "src/minisketch/", "src/tinyformat.h", - "src/univalue/", "src/dashbls/", "src/immer/" ] diff --git a/test/lint/lint-shell-locale.py b/test/lint/lint-shell-locale.py index 52928041cb0b..77f6d79f3529 100755 --- a/test/lint/lint-shell-locale.py +++ b/test/lint/lint-shell-locale.py @@ -41,7 +41,7 @@ def main(): exit_code = 0 shell_files = get_shell_files_list() for file_path in shell_files: - if re.search('src/(dashbls|secp256k1|minisketch|univalue)/', file_path): + if re.search('src/(dashbls|secp256k1|minisketch)/', file_path): continue with open(file_path, 'r', encoding='utf-8') as file_obj: diff --git a/test/lint/lint-shell.py b/test/lint/lint-shell.py index 569276cb0d58..c1acd618c120 100755 --- a/test/lint/lint-shell.py +++ b/test/lint/lint-shell.py @@ -68,7 +68,7 @@ def main(): ] files = get_files(files_cmd) # remove everything that doesn't match this regex - reg = re.compile(r'src/[dashbls,immer,leveldb,secp256k1,minisketch,univalue]') + reg = re.compile(r'src/[dashbls,immer,leveldb,secp256k1,minisketch]') files[:] = [file for file in files if not reg.match(file)] # build the `shellcheck` command diff --git a/test/lint/lint-spelling.py b/test/lint/lint-spelling.py index e462d9c59d70..533bf8d63122 100755 --- a/test/lint/lint-spelling.py +++ b/test/lint/lint-spelling.py @@ -12,7 +12,7 @@ from subprocess import check_output, STDOUT, CalledProcessError IGNORE_WORDS_FILE = 'test/lint/spelling.ignore-words.txt' -FILES_ARGS = ['git', 'ls-files', '--', ":(exclude)build-aux/m4/", ":(exclude)contrib/seeds/*.txt", ":(exclude)depends/", ":(exclude)doc/release-notes/", ":(exclude)src/bip39_english.h", ":(exclude)src/dashbls/", ":(exclude)src/crc32c/", ":(exclude)src/crypto/", ":(exclude)src/ctpl_stl.h", ":(exclude)src/cxxtimer.hpp", ":(exclude)src/util/expected.h", ":(exclude)src/immer/", ":(exclude)src/leveldb/", ":(exclude)src/qt/locale/", ":(exclude)src/qt/*.qrc", ":(exclude)src/secp256k1/", ":(exclude)src/minisketch/", ":(exclude)src/univalue/", ":(exclude)contrib/builder-keys/", ":(exclude)contrib/guix/patches"] +FILES_ARGS = ['git', 'ls-files', '--', ":(exclude)build-aux/m4/", ":(exclude)contrib/seeds/*.txt", ":(exclude)depends/", ":(exclude)doc/release-notes/", ":(exclude)src/bip39_english.h", ":(exclude)src/dashbls/", ":(exclude)src/crc32c/", ":(exclude)src/crypto/", ":(exclude)src/ctpl_stl.h", ":(exclude)src/cxxtimer.hpp", ":(exclude)src/util/expected.h", ":(exclude)src/immer/", ":(exclude)src/leveldb/", ":(exclude)src/qt/locale/", ":(exclude)src/qt/*.qrc", ":(exclude)src/secp256k1/", ":(exclude)src/minisketch/", ":(exclude)contrib/builder-keys/", ":(exclude)contrib/guix/patches"] def check_codespell_install(): diff --git a/test/lint/lint-whitespace.py b/test/lint/lint-whitespace.py index a674ef514408..a0e1f0636a2b 100755 --- a/test/lint/lint-whitespace.py +++ b/test/lint/lint-whitespace.py @@ -22,7 +22,6 @@ "src/crc32c/", "src/secp256k1/", "src/minisketch/", - "src/univalue/", "src/dashbls/", "src/immer/", "src/util/expected.h",