6#include <chainparams.h>
16#include <system_error>
25 std::vector<std::pair<fs::path, std::string>> paths;
28 for (
auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
30 if (fs::is_directory(*it)) {
31 it.disable_recursion_pending();
40 const fs::path path{it->
path().lexically_relative(wallet_dir)};
42 if (it->status().type() == fs::file_type::directory) {
45 paths.emplace_back(path,
"bdb");
48 paths.emplace_back(path,
"sqlite");
50 }
else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular && it->path().extension() !=
".bak") {
51 if (it->path().filename() ==
"wallet.dat") {
55 paths.emplace_back(
fs::path(),
"bdb");
57 paths.emplace_back(
fs::path(),
"sqlite");
64 paths.emplace_back(path,
"bdb");
67 }
catch (
const std::exception& e) {
69 it.disable_recursion_pending();
78 if (fs::is_regular_file(wallet_path)) {
86 return wallet_path /
"wallet.dat";
92 return path /
"wallet.dat";
102 auto size = fs::file_size(path, ec);
104 if (size < 4096)
return false;
106 std::ifstream file{path, std::ios::binary};
107 if (!file.is_open())
return false;
109 file.seekg(12, std::ios::beg);
111 file.read((
char*) &
data,
sizeof(
data));
117 return data == 0x00053162 ||
data == 0x62310500;
126 auto size = fs::file_size(path, ec);
128 if (size < 512)
return false;
130 std::ifstream file{path, std::ios::binary};
131 if (!file.is_open())
return false;
135 file.read(magic, 16);
138 file.seekg(68, std::ios::beg);
140 file.read(app_id, 4);
145 std::string magic_str(magic, 16);
146 if (magic_str != std::string{
"SQLite format 3\000", 16}) {
151 return memcmp(
Params().MessageStart().
data(), app_id, 4) == 0;
const CChainParams & Params()
Return the currently selected parameters.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
constexpr std::size_t size() const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
path(std::filesystem::path path)
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
fs::path SQLiteDataFile(const fs::path &path)
bool IsBDBFile(const fs::path &path)
fs::path BDBDataFile(const fs::path &wallet_path)
bool operator<(BytePrefix a, Span< const std::byte > b)
bool IsSQLiteFile(const fs::path &path)
std::vector< std::pair< fs::path, std::string > > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
Span< const std::byte > prefix
bool use_shared_memory
Let other processes access the database.
bool use_unsafe_sync
Disable file sync for faster performance.
int64_t max_log_mb
Max log size to allow before consolidating.