Skip to content

Commit faf70cc

Browse files
author
MarcoFalke
committed
Remove wallet::ParseISO8601DateTime, use ParseISO8601DateTime instead
1 parent 2222aec commit faf70cc

10 files changed

+11
-79
lines changed

src/test/fuzz/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ add_executable(fuzz
7676
p2p_transport_serialization.cpp
7777
package_eval.cpp
7878
parse_hd_keypath.cpp
79+
parse_iso8601.cpp
7980
parse_numbers.cpp
8081
parse_script.cpp
8182
parse_univalue.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// Copyright (c) 2019-2022 The Bitcoin Core developers
1+
// Copyright (c) 2019-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <test/fuzz/FuzzedDataProvider.h>
66
#include <test/fuzz/fuzz.h>
77
#include <util/time.h>
8-
#include <wallet/rpc/util.h>
98

109
#include <cassert>
1110
#include <cstdint>
@@ -21,14 +20,8 @@ FUZZ_TARGET(parse_iso8601)
2120

2221
const std::string iso8601_datetime = FormatISO8601DateTime(random_time);
2322
(void)FormatISO8601Date(random_time);
24-
const int64_t parsed_time_1 = wallet::ParseISO8601DateTime(iso8601_datetime);
25-
if (random_time >= 0) {
26-
assert(parsed_time_1 >= 0);
27-
if (iso8601_datetime.length() == 20) {
28-
assert(parsed_time_1 == random_time);
29-
}
30-
}
23+
const int64_t parsed_time_1{ParseISO8601DateTime(iso8601_datetime).value()};
24+
assert(parsed_time_1 == random_time);
3125

32-
const int64_t parsed_time_2 = wallet::ParseISO8601DateTime(random_string);
33-
assert(parsed_time_2 >= 0);
26+
(void)ParseISO8601DateTime(random_string);
3427
}

src/wallet/rpc/backup.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2009-2022 The Bitcoin Core developers
1+
// Copyright (c) 2009-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -549,7 +549,7 @@ RPCHelpMan importwallet()
549549
continue;
550550
CKey key = DecodeSecret(vstr[0]);
551551
if (key.IsValid()) {
552-
int64_t nTime = ParseISO8601DateTime(vstr[1]);
552+
int64_t nTime{ParseISO8601DateTime(vstr[1]).value_or(0)};
553553
std::string strLabel;
554554
bool fLabel = true;
555555
for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
@@ -569,7 +569,7 @@ RPCHelpMan importwallet()
569569
} else if(IsHex(vstr[0])) {
570570
std::vector<unsigned char> vData(ParseHex(vstr[0]));
571571
CScript script = CScript(vData.begin(), vData.end());
572-
int64_t birth_time = ParseISO8601DateTime(vstr[1]);
572+
int64_t birth_time{ParseISO8601DateTime(vstr[1]).value_or(0)};
573573
if (birth_time > 0) nTimeBegin = std::min(nTimeBegin, birth_time);
574574
scripts.emplace_back(script, birth_time);
575575
}

src/wallet/rpc/util.cpp

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2011-2022 The Bitcoin Core developers
1+
// Copyright (c) 2011-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -14,26 +14,10 @@
1414
#include <string_view>
1515
#include <univalue.h>
1616

17-
#include <boost/date_time/posix_time/posix_time.hpp>
18-
1917
namespace wallet {
2018
static const std::string WALLET_ENDPOINT_BASE = "/wallet/";
2119
const std::string HELP_REQUIRING_PASSPHRASE{"\nRequires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.\n"};
2220

23-
int64_t ParseISO8601DateTime(const std::string& str)
24-
{
25-
static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
26-
static const std::locale loc(std::locale::classic(),
27-
new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ"));
28-
std::istringstream iss(str);
29-
iss.imbue(loc);
30-
boost::posix_time::ptime ptime(boost::date_time::not_a_date_time);
31-
iss >> ptime;
32-
if (ptime.is_not_a_date_time() || epoch > ptime)
33-
return 0;
34-
return (ptime - epoch).total_seconds();
35-
}
36-
3721
bool GetAvoidReuseFlag(const CWallet& wallet, const UniValue& param) {
3822
bool can_avoid_reuse = wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE);
3923
bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool();

src/wallet/rpc/util.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2022 The Bitcoin Core developers
1+
// Copyright (c) 2017-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -51,7 +51,6 @@ std::string LabelFromValue(const UniValue& value);
5151
void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, UniValue& entry);
5252

5353
void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& status, bilingual_str& error);
54-
int64_t ParseISO8601DateTime(const std::string& str);
5554
void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
5655
} // namespace wallet
5756

src/wallet/test/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ target_sources(test_bitcoin
1414
init_tests.cpp
1515
ismine_tests.cpp
1616
psbt_wallet_tests.cpp
17-
rpc_util_tests.cpp
1817
scriptpubkeyman_tests.cpp
1918
spend_tests.cpp
2019
wallet_crypto_tests.cpp

src/wallet/test/fuzz/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ target_sources(fuzz
99
crypter.cpp
1010
fees.cpp
1111
$<$<BOOL:${USE_SQLITE}>:${CMAKE_CURRENT_LIST_DIR}/notifications.cpp>
12-
parse_iso8601.cpp
1312
$<$<BOOL:${USE_SQLITE}>:${CMAKE_CURRENT_LIST_DIR}/scriptpubkeyman.cpp>
1413
spend.cpp
1514
wallet_bdb_parser.cpp

src/wallet/test/rpc_util_tests.cpp

-42
This file was deleted.

test/lint/lint-includes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
EXCLUDED_DIRS = ["contrib/devtools/bitcoin-tidy/",
2121
] + SHARED_EXCLUDED_SUBTREES
2222

23-
EXPECTED_BOOST_INCLUDES = ["boost/date_time/posix_time/posix_time.hpp",
23+
EXPECTED_BOOST_INCLUDES = [
2424
"boost/multi_index/detail/hash_index_iterator.hpp",
2525
"boost/multi_index/hashed_index.hpp",
2626
"boost/multi_index/identity.hpp",

vcpkg.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
44
"builtin-baseline": "c82f74667287d3dc386bce81e44964370c91a289",
55
"dependencies": [
6-
"boost-date-time",
76
"boost-multi-index",
87
"boost-signals2",
98
"libevent"

0 commit comments

Comments
 (0)