10 static const std::string
DUMP_MAGIC =
"BITCOIN_CORE_WALLET_DUMP";
16 std::string dump_filename =
gArgs.
GetArg(
"-dumpfile",
"");
17 if (dump_filename.empty()) {
18 error =
_(
"No dump file provided. To use dump, -dumpfile=<filename> must be provided.");
22 fs::path path = dump_filename;
23 path = fs::absolute(path);
24 if (fs::exists(path)) {
25 error =
strprintf(
_(
"File %s already exists. If you are sure this is what you want, move it out of the way first."), path.string());
30 if (dump_file.fail()) {
38 std::unique_ptr<DatabaseBatch> batch = db.
MakeBatch();
41 if (!batch->StartCursor()) {
42 error =
_(
"Error: Couldn't create cursor into database");
48 dump_file.write(line.data(), line.size());
49 hasher.
write(line.data(), line.size());
53 dump_file.write(line.data(), line.size());
54 hasher.
write(line.data(), line.size());
63 ret = batch->ReadAtCursor(ss_key, ss_value, complete);
68 error =
_(
"Error reading next record from wallet database");
71 std::string key_str =
HexStr(ss_key);
72 std::string value_str =
HexStr(ss_value);
73 line =
strprintf(
"%s,%s\n", key_str, value_str);
74 dump_file.write(line.data(), line.size());
75 hasher.
write(line.data(), line.size());
103 wallet->WalletLogPrintf(
"Releasing wallet\n");
111 std::string dump_filename =
gArgs.
GetArg(
"-dumpfile",
"");
112 if (dump_filename.empty()) {
113 error =
_(
"No dump file provided. To use createfromdump, -dumpfile=<filename> must be provided.");
117 fs::path dump_path = dump_filename;
118 dump_path = fs::absolute(dump_path);
119 if (!fs::exists(dump_path)) {
120 error =
strprintf(
_(
"Dump file %s does not exist."), dump_path.string());
130 std::string magic_key;
131 std::getline(dump_file, magic_key,
',');
132 std::string version_value;
133 std::getline(dump_file, version_value,
'\n');
135 error =
strprintf(
_(
"Error: Dumpfile identifier record is incorrect. Got \"%s\", expected \"%s\"."), magic_key,
DUMP_MAGIC);
142 error =
strprintf(
_(
"Error: Unable to parse version %u as a uint32_t"), version_value);
147 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);
151 std::string magic_hasher_line =
strprintf(
"%s,%s\n", magic_key, version_value);
152 hasher.
write(magic_hasher_line.data(), magic_hasher_line.size());
155 std::string format_key;
156 std::getline(dump_file, format_key,
',');
157 std::string format_value;
158 std::getline(dump_file, format_value,
'\n');
159 if (format_key !=
"format") {
160 error =
strprintf(
_(
"Error: Dumpfile format record is incorrect. Got \"%s\", expected \"format\"."), format_key);
165 std::string file_format =
gArgs.
GetArg(
"-format", format_value);
166 if (file_format.empty()) {
167 error =
_(
"No wallet file format provided. To use createfromdump, -format=<format> must be provided.");
171 if (file_format ==
"bdb") {
173 }
else if (file_format ==
"sqlite") {
176 error =
strprintf(
_(
"Unknown wallet file format \"%s\" provided. Please provide one of \"bdb\" or \"sqlite\"."), file_format);
179 if (file_format != format_value) {
180 warnings.push_back(
strprintf(
_(
"Warning: Dumpfile wallet format \"%s\" does not match command line specified format \"%s\"."), format_value, file_format));
182 std::string format_hasher_line =
strprintf(
"%s,%s\n", format_key, format_value);
183 hasher.
write(format_hasher_line.data(), format_hasher_line.size());
189 std::unique_ptr<WalletDatabase> database =
MakeDatabase(wallet_path, options, status,
error);
190 if (!database)
return false;
197 bool first_run =
true;
206 std::unique_ptr<DatabaseBatch> batch = db.
MakeBatch();
210 while (dump_file.good()) {
212 std::getline(dump_file, key,
',');
214 std::getline(dump_file, value,
'\n');
216 if (key ==
"checksum") {
217 std::vector<unsigned char> parsed_checksum =
ParseHex(value);
218 std::copy(parsed_checksum.begin(), parsed_checksum.end(), checksum.
begin());
222 std::string line =
strprintf(
"%s,%s\n", key, value);
223 hasher.
write(line.data(), line.size());
225 if (key.empty() || value.empty()) {
240 std::vector<unsigned char> k =
ParseHex(key);
241 std::vector<unsigned char> v =
ParseHex(value);
246 if (!batch->Write(ss_key, ss_value)) {
256 error =
_(
"Error: Missing checksum");
258 }
else if (checksum != comp_checksum) {
259 error =
strprintf(
_(
"Error: Dumpfile checksum does not match. Computed %s, expected %s"),
HexStr(comp_checksum),
HexStr(checksum));
278 fs::remove_all(wallet_path);