From d834bfda342ff7e9b151e97ea4009f09aeaeb959 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 28 Nov 2024 13:41:54 +0100 Subject: [PATCH] Remove wallet::ParseISO8601DateTime, use ParseISO8601DateTime instead Github-Pull: #31391 Rebased-From: faf70cc9941ce2b0ce4fd48ecfdbe28194adb8ba --- build_msvc/vcpkg.json | 1 - src/Makefile.test.include | 3 +- src/{wallet => }/test/fuzz/parse_iso8601.cpp | 15 ++----- src/wallet/rpc/backup.cpp | 6 +-- src/wallet/rpc/util.cpp | 18 +-------- src/wallet/rpc/util.h | 3 +- src/wallet/test/rpc_util_tests.cpp | 42 -------------------- test/lint/lint-includes.py | 2 +- 8 files changed, 11 insertions(+), 79 deletions(-) rename src/{wallet => }/test/fuzz/parse_iso8601.cpp (60%) delete mode 100644 src/wallet/test/rpc_util_tests.cpp diff --git a/build_msvc/vcpkg.json b/build_msvc/vcpkg.json index b2c406ae12..c1e783b285 100644 --- a/build_msvc/vcpkg.json +++ b/build_msvc/vcpkg.json @@ -3,7 +3,6 @@ "version-string": "1", "dependencies": [ "berkeleydb", - "boost-date-time", "boost-multi-index", "boost-signals2", "boost-test", diff --git a/src/Makefile.test.include b/src/Makefile.test.include index c396cc2ebf..a2d194c4ff 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -189,7 +189,6 @@ BITCOIN_TESTS += \ wallet/test/coinselector_tests.cpp \ wallet/test/init_tests.cpp \ wallet/test/ismine_tests.cpp \ - wallet/test/rpc_util_tests.cpp \ wallet/test/scriptpubkeyman_tests.cpp \ wallet/test/walletload_tests.cpp \ wallet/test/group_outputs_tests.cpp @@ -207,7 +206,6 @@ FUZZ_WALLET_SRC = \ wallet/test/fuzz/coinselection.cpp \ wallet/test/fuzz/crypter.cpp \ wallet/test/fuzz/fees.cpp \ - wallet/test/fuzz/parse_iso8601.cpp \ wallet/test/fuzz/wallet_bdb_parser.cpp if USE_SQLITE @@ -356,6 +354,7 @@ test_fuzz_fuzz_SOURCES = \ test/fuzz/p2p_transport_serialization.cpp \ test/fuzz/package_eval.cpp \ test/fuzz/parse_hd_keypath.cpp \ + test/fuzz/parse_iso8601.cpp \ test/fuzz/parse_numbers.cpp \ test/fuzz/parse_script.cpp \ test/fuzz/parse_univalue.cpp \ diff --git a/src/wallet/test/fuzz/parse_iso8601.cpp b/src/test/fuzz/parse_iso8601.cpp similarity index 60% rename from src/wallet/test/fuzz/parse_iso8601.cpp rename to src/test/fuzz/parse_iso8601.cpp index c1bafc1073..7e51f57905 100644 --- a/src/wallet/test/fuzz/parse_iso8601.cpp +++ b/src/test/fuzz/parse_iso8601.cpp @@ -1,11 +1,10 @@ -// Copyright (c) 2019-2022 The Bitcoin Core developers +// Copyright (c) 2019-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include -#include #include #include @@ -21,14 +20,8 @@ FUZZ_TARGET(parse_iso8601) const std::string iso8601_datetime = FormatISO8601DateTime(random_time); (void)FormatISO8601Date(random_time); - const int64_t parsed_time_1 = wallet::ParseISO8601DateTime(iso8601_datetime); - if (random_time >= 0) { - assert(parsed_time_1 >= 0); - if (iso8601_datetime.length() == 20) { - assert(parsed_time_1 == random_time); - } - } + const int64_t parsed_time_1{ParseISO8601DateTime(iso8601_datetime).value()}; + assert(parsed_time_1 == random_time); - const int64_t parsed_time_2 = wallet::ParseISO8601DateTime(random_string); - assert(parsed_time_2 >= 0); + (void)ParseISO8601DateTime(random_string); } diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 0d0e86ed24..8b7a244175 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2009-2022 The Bitcoin Core developers +// Copyright (c) 2009-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -549,7 +549,7 @@ RPCHelpMan importwallet() continue; CKey key = DecodeSecret(vstr[0]); if (key.IsValid()) { - int64_t nTime = ParseISO8601DateTime(vstr[1]); + int64_t nTime{ParseISO8601DateTime(vstr[1]).value_or(0)}; std::string strLabel; bool fLabel = true; for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) { @@ -569,7 +569,7 @@ RPCHelpMan importwallet() } else if(IsHex(vstr[0])) { std::vector vData(ParseHex(vstr[0])); CScript script = CScript(vData.begin(), vData.end()); - int64_t birth_time = ParseISO8601DateTime(vstr[1]); + int64_t birth_time{ParseISO8601DateTime(vstr[1]).value_or(0)}; if (birth_time > 0) nTimeBegin = std::min(nTimeBegin, birth_time); scripts.emplace_back(script, birth_time); } diff --git a/src/wallet/rpc/util.cpp b/src/wallet/rpc/util.cpp index 67b5ae0fe2..b499acaed8 100644 --- a/src/wallet/rpc/util.cpp +++ b/src/wallet/rpc/util.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2022 The Bitcoin Core developers +// Copyright (c) 2011-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -14,26 +14,10 @@ #include #include -#include - namespace wallet { static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; const std::string HELP_REQUIRING_PASSPHRASE{"\nRequires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.\n"}; -int64_t ParseISO8601DateTime(const std::string& str) -{ - static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0); - static const std::locale loc(std::locale::classic(), - new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ")); - std::istringstream iss(str); - iss.imbue(loc); - boost::posix_time::ptime ptime(boost::date_time::not_a_date_time); - iss >> ptime; - if (ptime.is_not_a_date_time() || epoch > ptime) - return 0; - return (ptime - epoch).total_seconds(); -} - bool GetAvoidReuseFlag(const CWallet& wallet, const UniValue& param) { bool can_avoid_reuse = wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool(); diff --git a/src/wallet/rpc/util.h b/src/wallet/rpc/util.h index 2fdba04352..002d0355e5 100644 --- a/src/wallet/rpc/util.h +++ b/src/wallet/rpc/util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022 The Bitcoin Core developers +// Copyright (c) 2017-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -51,7 +51,6 @@ std::string LabelFromValue(const UniValue& value); void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, UniValue& entry); void HandleWalletError(const std::shared_ptr wallet, DatabaseStatus& status, bilingual_str& error); -int64_t ParseISO8601DateTime(const std::string& str); void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); } // namespace wallet diff --git a/src/wallet/test/rpc_util_tests.cpp b/src/wallet/test/rpc_util_tests.cpp deleted file mode 100644 index 6541323b4b..0000000000 --- a/src/wallet/test/rpc_util_tests.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2022 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include - -#include - -namespace wallet { - -BOOST_AUTO_TEST_SUITE(wallet_util_tests) - -BOOST_AUTO_TEST_CASE(util_ParseISO8601DateTime) -{ - BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:00Z"), 0); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("1960-01-01T00:00:00Z"), 0); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:01Z"), 1); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T00:00:01Z"), 946684801); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2011-09-30T23:36:17Z"), 1317425777); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2100-12-31T23:59:59Z"), 4133980799); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("9999-12-31T23:59:59Z"), 253402300799); - - // Accept edge-cases, where the time overflows. - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T99:00:00Z"), 947041200); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T00:99:00Z"), 946690740); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T00:00:99Z"), 946684899); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T99:99:99Z"), 947047239); - - // Reject date overflows. - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-99-01T00:00:00Z"), 0); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-99T00:00:00Z"), 0); - - // Reject out-of-range years - BOOST_CHECK_EQUAL(ParseISO8601DateTime("32768-12-31T23:59:59Z"), 0); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("32767-12-31T23:59:59Z"), 0); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("32767-12-31T00:00:00Z"), 0); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("999-12-31T00:00:00Z"), 0); -} - -BOOST_AUTO_TEST_SUITE_END() - -} // namespace wallet diff --git a/test/lint/lint-includes.py b/test/lint/lint-includes.py index 90884299d5..05780c3074 100755 --- a/test/lint/lint-includes.py +++ b/test/lint/lint-includes.py @@ -20,7 +20,7 @@ from lint_ignore_dirs import SHARED_EXCLUDED_SUBTREES EXCLUDED_DIRS = ["contrib/devtools/bitcoin-tidy/", ] + SHARED_EXCLUDED_SUBTREES -EXPECTED_BOOST_INCLUDES = ["boost/date_time/posix_time/posix_time.hpp", +EXPECTED_BOOST_INCLUDES = [ "boost/multi_index/detail/hash_index_iterator.hpp", "boost/multi_index/hashed_index.hpp", "boost/multi_index/identity.hpp",