mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-08 10:58:22 -03:00
Remove wallet::ParseISO8601DateTime, use ParseISO8601DateTime instead
This commit is contained in:
parent
2222aecd5f
commit
faf70cc994
10 changed files with 11 additions and 79 deletions
|
@ -76,6 +76,7 @@ add_executable(fuzz
|
|||
p2p_transport_serialization.cpp
|
||||
package_eval.cpp
|
||||
parse_hd_keypath.cpp
|
||||
parse_iso8601.cpp
|
||||
parse_numbers.cpp
|
||||
parse_script.cpp
|
||||
parse_univalue.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 <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <util/time.h>
|
||||
#include <wallet/rpc/util.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
|
@ -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);
|
||||
}
|
|
@ -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<unsigned char> 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);
|
||||
}
|
||||
|
|
|
@ -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 <string_view>
|
||||
#include <univalue.h>
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
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();
|
||||
|
|
|
@ -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<CWallet> 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
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ target_sources(test_bitcoin
|
|||
init_tests.cpp
|
||||
ismine_tests.cpp
|
||||
psbt_wallet_tests.cpp
|
||||
rpc_util_tests.cpp
|
||||
scriptpubkeyman_tests.cpp
|
||||
spend_tests.cpp
|
||||
wallet_crypto_tests.cpp
|
||||
|
|
|
@ -9,7 +9,6 @@ target_sources(fuzz
|
|||
crypter.cpp
|
||||
fees.cpp
|
||||
$<$<BOOL:${USE_SQLITE}>:${CMAKE_CURRENT_LIST_DIR}/notifications.cpp>
|
||||
parse_iso8601.cpp
|
||||
$<$<BOOL:${USE_SQLITE}>:${CMAKE_CURRENT_LIST_DIR}/scriptpubkeyman.cpp>
|
||||
spend.cpp
|
||||
wallet_bdb_parser.cpp
|
||||
|
|
|
@ -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 <wallet/rpc/util.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
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
|
|
@ -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",
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
|
||||
"builtin-baseline": "c82f74667287d3dc386bce81e44964370c91a289",
|
||||
"dependencies": [
|
||||
"boost-date-time",
|
||||
"boost-multi-index",
|
||||
"boost-signals2",
|
||||
"libevent"
|
||||
|
|
Loading…
Reference in a new issue