23static const std::string
DUMP_MAGIC =
"BITCOIN_CORE_WALLET_DUMP";
31 error =
_(
"No dump file provided. To use dump, -dumpfile=<filename> must be provided.");
38 error =
strprintf(
_(
"File %s already exists. If you are sure this is what you want, move it out of the way first."),
fs::PathToString(path));
49 std::unique_ptr<DatabaseBatch> batch =
db.MakeBatch();
60 auto write = [&](
const std::string& line) {
63 }
catch (
const std::ios_base::failure&) {
73 std::unique_ptr<DatabaseCursor>
cursor = batch->GetNewCursor();
75 throw_error(
_(
"Error: Couldn't create cursor into database"));
83 std::string format =
db.Format();
86 if (format ==
"bdb_ro") {
89 line =
strprintf(
"%s,%s\n",
"format", format);
100 throw_error(
_(
"Error reading next record from wallet database"));
130 wallet->WalletLogPrintf(
"Releasing wallet");
138 tfm::format(std::cerr,
"Wallet name cannot be empty\n");
145 error =
_(
"No dump file provided. To use createfromdump, -dumpfile=<filename> must be provided.");
179 error =
strprintf(
_(
"Error: Dumpfile version is not supported. This version of bitcoin-wallet only supports version 1 dumpfiles. Got dumpfile with version %s"),
version_value);
192 error =
strprintf(
_(
"Error: Dumpfile format record is incorrect. Got \"%s\", expected \"format\"."),
format_key);
201 error =
strprintf(
_(
"Error: Dumpfile specifies an unsupported database format (%s). Only sqlite database dumps are supported"),
format_value);
221 std::unique_ptr<DatabaseBatch> batch =
db.MakeBatch();
231 if (key ==
"checksum") {
234 error =
Untranslated(
"Error: Checksum is not the correct size");
242 std::string line =
strprintf(
"%s,%s\n", key, value);
243 hasher << std::span{line};
245 if (key.empty() || value.empty()) {
250 error =
strprintf(
_(
"Error: Got key that was not hex: %s"), key);
255 error =
strprintf(
_(
"Error: Got value that was not hex: %s"), value);
260 std::vector<unsigned char>
k =
ParseHex(key);
261 std::vector<unsigned char> v =
ParseHex(value);
262 if (!batch->Write(std::span{k}, std::span{v})) {
263 error =
strprintf(
_(
"Error: Unable to write record to new wallet"));
272 error =
_(
"Error: Missing checksum");
std::string GetArg(const std::string &strArg, const std::string &strDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return string argument or default value.
Non-refcounted RAII wrapper for FILE*.
Double ended buffer combining vector and stream-like interfaces.
A writer stream (for serialization) that computes a 256-bit hash.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
An instance of this class represents one database.
static path absolute(const path &p)
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
FILE * fopen(const fs::path &p, const char *mode)
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
static void WalletToolReleaseWallet(CWallet *wallet)
std::unique_ptr< WalletDatabase > MakeDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
bool CreateFromDump(const ArgsManager &args, const std::string &name, const fs::path &wallet_path, bilingual_str &error)
bool DumpWallet(const ArgsManager &args, WalletDatabase &db, bilingual_str &error)
static const std::string DUMP_MAGIC
auto MakeByteSpan(const V &v) noexcept
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
std::optional< DatabaseFormat > require_format
consteval auto _(util::TranslatedLiteral str)
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
bool IsHex(std::string_view str)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.