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

Method load_wallets

src/Core/WalletSerializationV1.cpp:297–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

295}*/
296
297void WalletSerializerV1::load_wallets(common::IInputStream &source, CryptoContext &crypto_ctx) {
298 auto &index = m_wallets_container;
299
300 uint64_t count = 0;
301 deserialize_encrypted(count, "wallets_count", crypto_ctx, source);
302 crypto_ctx.inc_iv();
303
304 bool is_tracking_mode = false; // init not required, but prevents warning
305
306 for (uint64_t i = 0; i < count; ++i) {
307 WalletRecordDto dto;
308 deserialize_encrypted(dto, "", crypto_ctx, source);
309 crypto_ctx.inc_iv();
310
311 if (i == 0) {
312 is_tracking_mode = dto.spend_secret_key == SecretKey{};
313 } else if ((is_tracking_mode && dto.spend_secret_key != SecretKey{}) ||
314 (!is_tracking_mode && dto.spend_secret_key == SecretKey{})) {
315 throw std::runtime_error("BAD_ADDRESS - All addresses must be whether tracking or not");
316 }
317
318 if (dto.spend_secret_key != SecretKey{}) {
319 if (!keys_match(dto.spend_secret_key, dto.spend_public_key))
320 throw std::runtime_error("Restored spend public key doesn't correspond to secret key");
321 } else {
322 if (!crypto::key_in_main_subgroup(dto.spend_public_key)) {
323 throw std::runtime_error("WRONG_PASSWORD - Public spend key is incorrect");
324 }
325 }
326
327 WalletRecord wallet;
328 wallet.spend_public_key = dto.spend_public_key;
329 wallet.spend_secret_key = dto.spend_secret_key;
330 wallet.creation_timestamp = static_cast<Timestamp>(dto.creation_timestamp);
331
332 index.push_back(wallet);
333 }
334}
335
336} // namespace cn

Callers

nothing calls this directly

Calls 4

deserialize_encryptedFunction · 0.85
keys_matchFunction · 0.85
key_in_main_subgroupFunction · 0.85
inc_ivMethod · 0.80

Tested by

no test coverage detected