MCPcopy Create free account
hub / github.com/ElementsProject/elements / CreateFromDump

Function CreateFromDump

src/wallet/dump.cpp:117–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117bool CreateFromDump(const std::string& name, const fs::path& wallet_path, bilingual_str& error, std::vector<bilingual_str>& warnings)
118{
119 // Get the dumpfile
120 std::string dump_filename = gArgs.GetArg("-dumpfile", "");
121 if (dump_filename.empty()) {
122 error = _("No dump file provided. To use createfromdump, -dumpfile=<filename> must be provided.");
123 return false;
124 }
125
126 fs::path dump_path = fs::PathFromString(dump_filename);
127 dump_path = fs::absolute(dump_path);
128 if (!fs::exists(dump_path)) {
129 error = strprintf(_("Dump file %s does not exist."), fs::PathToString(dump_path));
130 return false;
131 }
132 std::ifstream dump_file{dump_path};
133
134 // Compute the checksum
135 CHashWriter hasher(0, 0);
136 uint256 checksum;
137
138 // Check the magic and version
139 std::string magic_key;
140 std::getline(dump_file, magic_key, ',');
141 std::string version_value;
142 std::getline(dump_file, version_value, '\n');
143 if (magic_key != DUMP_MAGIC) {
144 error = strprintf(_("Error: Dumpfile identifier record is incorrect. Got \"%s\", expected \"%s\"."), magic_key, DUMP_MAGIC);
145 dump_file.close();
146 return false;
147 }
148 // Check the version number (value of first record)
149 uint32_t ver;
150 if (!ParseUInt32(version_value, &ver)) {
151 error =strprintf(_("Error: Unable to parse version %u as a uint32_t"), version_value);
152 dump_file.close();
153 return false;
154 }
155 if (ver != DUMP_VERSION) {
156 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);
157 dump_file.close();
158 return false;
159 }
160 std::string magic_hasher_line = strprintf("%s,%s\n", magic_key, version_value);
161 hasher.write(MakeByteSpan(magic_hasher_line));
162
163 // Get the stored file format
164 std::string format_key;
165 std::getline(dump_file, format_key, ',');
166 std::string format_value;
167 std::getline(dump_file, format_value, '\n');
168 if (format_key != "format") {
169 error = strprintf(_("Error: Dumpfile format record is incorrect. Got \"%s\", expected \"format\"."), format_key);
170 dump_file.close();
171 return false;
172 }
173 // Get the data file format with format_value as the default
174 std::string file_format = gArgs.GetArg("-format", format_value);

Callers 1

ExecuteWalletToolFuncFunction · 0.85

Calls 15

_Function · 0.85
PathFromStringFunction · 0.85
absoluteFunction · 0.85
existsFunction · 0.85
PathToStringFunction · 0.85
ParseUInt32Function · 0.85
MakeByteSpanFunction · 0.85
MakeDatabaseFunction · 0.85
ParseHexFunction · 0.85
UntranslatedFunction · 0.85
IsHexFunction · 0.85
GetArgMethod · 0.80

Tested by

no test coverage detected