MCPcopy Create free account
hub / github.com/bcndev/bytecoin / load

Method load

src/Core/WalletLegacy.cpp:223–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223void WalletLegacy::load() {
224 try {
225 m_file = std::make_unique<platform::FileStream>(m_path, platform::O_OPEN_EXISTING);
226 } catch (const StreamError &) { // Read-only media?
227 m_file = std::make_unique<platform::FileStream>(m_path, platform::O_READ_EXISTING);
228 }
229 uint8_t version = 0;
230 m_file->read(&version, 1);
231 if (version > SERIALIZATION_VERSION_V2)
232 throw Exception(api::WALLET_FILE_UNKNOWN_VERSION, "Unknown version");
233 m_file->seek(0, SEEK_SET);
234 if (version < SERIALIZATION_VERSION_V2) {
235 try {
236 load_legacy_wallet_file();
237 } catch (const StreamError &ex) {
238 std::throw_with_nested(
239 Exception(api::WALLET_FILE_READ_ERROR, std::string("Error reading wallet file ") + common::what(ex)));
240 } catch (const std::exception &ex) {
241 std::throw_with_nested(Exception(
242 api::WALLET_FILE_DECRYPT_ERROR, std::string("Error decrypting wallet file ") + common::what(ex)));
243 }
244 m_file.reset(); // Indicates legacy format
245 try {
246 save_and_check(); // We try to overwrite legacy format with new format
247 m_log(logging::WARNING) << "Overwritten legacy wallet file with new data format";
248 } catch (const std::exception &) { // probably read only, ignore
249 }
250 } else {
251 load_container_storage();
252 }
253 if (m_wallet_records.empty())
254 throw Exception(api::WALLET_FILE_DECRYPT_ERROR, "Error reading wallet file");
255
256 m_inv_view_secret_key = sc_invert(m_view_secret_key);
257 if (!is_view_only()) {
258 BinaryArray seed_data = m_view_secret_key.as_binary_array();
259 seed_data |= m_wallet_records.at(0).spend_secret_key.as_binary_array();
260 m_seed = cn_fast_hash(seed_data);
261 m_view_seed = derive_from_seed_legacy(m_seed, "tx_derivation");
262 m_history_filename_seed = derive_from_seed_legacy(m_seed, "history_filename");
263 m_history_key = chacha_key{derive_from_seed_legacy(m_seed, "history")};
264 }
265}
266
267void WalletLegacy::save(
268 const std::string &export_path, const chacha_key &wallet_key, bool view_only, platform::OpenMode open_mode) const {

Callers 1

Calls 10

cn_fast_hashFunction · 0.85
derive_from_seed_legacyFunction · 0.85
seekMethod · 0.80
atMethod · 0.80
ExceptionClass · 0.70
sc_invertFunction · 0.50
readMethod · 0.45
resetMethod · 0.45
emptyMethod · 0.45
as_binary_arrayMethod · 0.45

Tested by

no test coverage detected