21static const std::string
DUMP_MAGIC =
"BITCOIN_CORE_WALLET_DUMP";
29 error =
_(
"No dump file provided. To use dump, -dumpfile=<filename> must be provided.");
36 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));
48 std::unique_ptr<DatabaseBatch> batch =
db.MakeBatch();
51 std::unique_ptr<DatabaseCursor>
cursor = batch->GetNewCursor();
53 error =
_(
"Error: Couldn't create cursor into database");
59 dump_file.write(line.data(), line.size());
63 std::string format =
db.Format();
66 if (format ==
"bdb_ro") {
69 line =
strprintf(
"%s,%s\n",
"format", format);
70 dump_file.write(line.data(), line.size());
84 error =
_(
"Error reading next record from wallet database");
91 dump_file.write(line.data(), line.size());
117 wallet->WalletLogPrintf(
"Releasing wallet\n");
125 tfm::format(std::cerr,
"Wallet name cannot be empty\n");
132 error =
_(
"No dump file provided. To use createfromdump, -dumpfile=<filename> must be provided.");
166 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);
179 error =
strprintf(
_(
"Error: Dumpfile format record is incorrect. Got \"%s\", expected \"format\"."),
format_key);
188 error =
strprintf(
_(
"Error: Dumpfile specifies an unsupported database format (%s). Only sqlite database dumps are supported"),
format_value);
208 std::unique_ptr<DatabaseBatch> batch =
db.MakeBatch();
218 if (key ==
"checksum") {
221 error =
Untranslated(
"Error: Checksum is not the correct size");
229 std::string line =
strprintf(
"%s,%s\n", key, value);
230 hasher << std::span{line};
232 if (key.empty() || value.empty()) {
237 error =
strprintf(
_(
"Error: Got key that was not hex: %s"), key);
242 error =
strprintf(
_(
"Error: Got value that was not hex: %s"), value);
247 std::vector<unsigned char>
k =
ParseHex(key);
248 std::vector<unsigned char> v =
ParseHex(value);
249 if (!batch->Write(std::span{k}, std::span{v})) {
250 error =
strprintf(
_(
"Error: Unable to write record to new wallet"));
259 error =
_(
"Error: Missing checksum");
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
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.
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
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, std::vector< bilingual_str > &warnings)
bool DumpWallet(const ArgsManager &args, WalletDatabase &db, bilingual_str &error)
static const std::string DUMP_MAGIC
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.