mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Merge 0577b4d9de
into ad7a373529
This commit is contained in:
commit
4770e9c24c
@ -556,7 +556,7 @@ public:
|
||||
peer.is_outbound ? "out" : "in",
|
||||
ConnectionTypeForNetinfo(peer.conn_type),
|
||||
peer.network,
|
||||
peer.transport_protocol_type.rfind('v', 0) == 0 ? peer.transport_protocol_type[1] : ' ',
|
||||
peer.transport_protocol_type.starts_with('v') == 0 ? peer.transport_protocol_type[1] : ' ',
|
||||
PingTimeToString(peer.min_ping),
|
||||
PingTimeToString(peer.ping),
|
||||
peer.last_send ? ToString(time_now - peer.last_send) : "",
|
||||
|
13
src/net.cpp
13
src/net.cpp
@ -1120,16 +1120,9 @@ constexpr std::array<std::string_view, 256> V2ShortIDs() {
|
||||
static_assert(std::size(V2_DASH_IDS) <= 128);
|
||||
|
||||
std::array<std::string_view, 256> ret{};
|
||||
for (size_t idx{0}; idx < std::size(ret); idx++) {
|
||||
if (idx < 128 && idx < std::size(V2_BITCOIN_IDS)) {
|
||||
ret[idx] = V2_BITCOIN_IDS[idx];
|
||||
} else if (idx >= 128 && idx - 128 < std::size(V2_DASH_IDS)) {
|
||||
ret[idx] = V2_DASH_IDS[idx - 128];
|
||||
} else {
|
||||
ret[idx] = "";
|
||||
}
|
||||
}
|
||||
|
||||
std::fill(ret.begin(), ret.end(), "");
|
||||
std::copy(V2_BITCOIN_IDS.begin(), V2_BITCOIN_IDS.end(), ret.begin());
|
||||
std::copy(V2_DASH_IDS.begin(), V2_DASH_IDS.end(), ret.begin() + 128);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -357,9 +357,7 @@ FUZZ_TARGET_INIT(rpc, initialize_rpc)
|
||||
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()};
|
||||
// Once c++20 is allowed, starts_with can be used.
|
||||
// if (error_msg.starts_with("Internal bug detected")) {
|
||||
if (0 == error_msg.rfind("Internal bug detected", 0)) {
|
||||
if (error_msg.starts_with("Internal bug detected")) {
|
||||
// Only allow the intentional internal bug
|
||||
assert(error_msg.find("trigger_internal_bug") != std::string::npos);
|
||||
}
|
||||
|
@ -5,40 +5,20 @@
|
||||
#ifndef BITCOIN_UTIL_RANGES_H
|
||||
#define BITCOIN_UTIL_RANGES_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
#include <optional>
|
||||
|
||||
//#if __cplusplus > 201703L // C++20 compiler
|
||||
//namespace ranges = std::ranges;
|
||||
//#else
|
||||
|
||||
#define MK_RANGE(FUN) \
|
||||
template <typename X, typename Z> \
|
||||
inline auto FUN(const X& ds, const Z& fn) { \
|
||||
return std::FUN(cbegin(ds), cend(ds), fn); \
|
||||
} \
|
||||
template <typename X, typename Z> \
|
||||
inline auto FUN(X& ds, const Z& fn) { \
|
||||
return std::FUN(begin(ds), end(ds), fn); \
|
||||
}
|
||||
|
||||
|
||||
namespace ranges {
|
||||
MK_RANGE(all_of)
|
||||
MK_RANGE(any_of)
|
||||
MK_RANGE(count_if)
|
||||
MK_RANGE(find_if)
|
||||
using namespace std::ranges;
|
||||
|
||||
template <typename X, typename Z>
|
||||
constexpr inline auto find_if_opt(const X& ds, const Z& fn) {
|
||||
const auto it = ranges::find_if(ds, fn);
|
||||
if (it != end(ds)) {
|
||||
return std::make_optional(*it);
|
||||
}
|
||||
return std::optional<std::decay_t<decltype(*it)>>{};
|
||||
template <typename X, typename Z>
|
||||
constexpr inline auto find_if_opt(const X& ds, const Z& fn) {
|
||||
const auto it = std::ranges::find_if(ds, fn);
|
||||
if (it != std::end(ds)) {
|
||||
return std::make_optional(*it);
|
||||
}
|
||||
|
||||
return std::optional<std::decay_t<decltype(*it)>>{};
|
||||
}
|
||||
}
|
||||
|
||||
//#endif // C++20 compiler
|
||||
#endif // BITCOIN_UTIL_RANGES_H
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <policy/settings.h>
|
||||
#include <primitives/block.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <reverse_iterator.h>
|
||||
#include <script/descriptor.h>
|
||||
#include <script/script.h>
|
||||
#include <script/sign.h>
|
||||
@ -5324,44 +5325,29 @@ bool CWallet::AutoBackupWallet(const fs::path& wallet_path, bilingual_str& error
|
||||
}
|
||||
|
||||
// Keep only the last 10 backups, including the new one of course
|
||||
typedef std::multimap<std::time_t, fs::path> folder_set_t;
|
||||
folder_set_t folder_set;
|
||||
fs::directory_iterator end_iter;
|
||||
std::multimap<fs::file_time_type, fs::path> folder_set;
|
||||
// Build map of backup files for current(!) wallet sorted by last write time
|
||||
fs::path currentFile;
|
||||
for (fs::directory_iterator dir_iter(backupsDir); dir_iter != end_iter; ++dir_iter)
|
||||
{
|
||||
for (const auto& entry : fs::directory_iterator(backupsDir)) {
|
||||
// Only check regular files
|
||||
if ( fs::is_regular_file(dir_iter->status()))
|
||||
{
|
||||
currentFile = dir_iter->path().filename();
|
||||
if (entry.is_regular_file()) {
|
||||
currentFile = entry.path().filename();
|
||||
// Only add the backups for the current wallet, e.g. wallet.dat.*
|
||||
if (fs::PathToString(dir_iter->path().stem()) == strWalletName) {
|
||||
folder_set.insert(folder_set_t::value_type(
|
||||
// TODO: C++17 compliant time conversion code is abominable, switch to C++20
|
||||
// compliant code when C++17 support is dropped
|
||||
std::chrono::system_clock::to_time_t(
|
||||
std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
||||
fs::last_write_time(dir_iter->path()) - fs::file_time_type::clock::now() + std::chrono::system_clock::now()
|
||||
)
|
||||
),
|
||||
*dir_iter
|
||||
));
|
||||
if (fs::PathToString(entry.path().stem()) == strWalletName) {
|
||||
folder_set.insert(decltype(folder_set)::value_type(fs::last_write_time(entry.path()), entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loop backward through backup files and keep the N newest ones (1 <= N <= 10)
|
||||
int counter = 0;
|
||||
for(auto it = folder_set.rbegin(); it != folder_set.rend(); ++it) {
|
||||
std::pair<const std::time_t, fs::path> file = *it;
|
||||
int counter{0};
|
||||
for (const auto& [entry_time, entry] : reverse_iterate(folder_set)) {
|
||||
counter++;
|
||||
if (counter > nWalletBackups)
|
||||
{
|
||||
if (counter > nWalletBackups) {
|
||||
// More than nWalletBackups backups: delete oldest one(s)
|
||||
try {
|
||||
fs::remove(file.second);
|
||||
WalletLogPrintf("Old backup deleted: %s\n", fs::PathToString(file.second));
|
||||
fs::remove(entry);
|
||||
WalletLogPrintf("Old backup deleted: %s\n", fs::PathToString(entry));
|
||||
} catch(fs::filesystem_error &error) {
|
||||
warnings.push_back(strprintf(_("Failed to delete backup, error: %s"), fsbridge::get_filesystem_error_message(error)));
|
||||
WalletLogPrintf("%s\n", Join(warnings, Untranslated("\n")).original);
|
||||
|
Loading…
Reference in New Issue
Block a user