Пример #1
0
void WalletSerializer::loadWalletV1(Common::IInputStream& source, const std::string& password) {
  CryptoNote::CryptoContext cryptoContext;

  CryptoNote::BinaryInputStreamSerializer encrypted(source);

  encrypted(cryptoContext.iv, "iv");
  generateKey(password, cryptoContext.key);

  std::string cipher;
  encrypted(cipher, "data");

  std::string plain = decrypt(cipher, cryptoContext);

  MemoryInputStream decryptedStream(plain.data(), plain.size());
  CryptoNote::BinaryInputStreamSerializer serializer(decryptedStream);

  loadWalletV1Keys(serializer);
  checkKeys();

  subscribeWallets();

  bool detailsSaved;
  serializer(detailsSaved, "has_details");

  if (detailsSaved) {
    loadWalletV1Details(serializer);
  }
}
Пример #2
0
void WalletSerializer::loadCurrentVersion(Common::IInputStream& source, const std::string& password) {
  CryptoNote::CryptoContext cryptoContext;

  bool details = false;
  bool cache = false;

  loadIv(source, cryptoContext.iv);
  generateKey(password, cryptoContext.key);

  loadKeys(source, cryptoContext);
  checkKeys();

  loadWallets(source, cryptoContext);
  subscribeWallets();

  loadFlags(details, cache, source, cryptoContext);

  if (details) {
    loadTransactions(source, cryptoContext);
    loadTransfers(source, cryptoContext);
  }

  if (cache) {
    loadBalances(source, cryptoContext);
    loadTransfersSynchronizer(source, cryptoContext);
    loadSpentOutputs(source, cryptoContext);
    loadUnlockTransactionsJobs(source, cryptoContext);
    loadChange(source, cryptoContext);
  }

  if (details && cache) {
    updateTransactionsBaseStatus();
  }
}
void WalletSerializerV1::loadWallet(Common::IInputStream& source, const Crypto::chacha8_key& key, uint32_t version) {
  CryptoContext cryptoContext;

  bool details = false;
  bool cache = false;

  loadIv(source, cryptoContext.iv);
  cryptoContext.key = key;

  loadKeys(source, cryptoContext);
  checkKeys();

  loadWallets(source, cryptoContext);
  subscribeWallets();

  loadFlags(details, cache, source, cryptoContext);

  if (details) {
    loadTransactions(source, cryptoContext);
    loadTransfers(source, cryptoContext, version);
  }

  if (version < 5) {
    updateTransfersSign();
    cache = false;
  }

  if (cache) {
    loadBalances(source, cryptoContext);
    loadTransfersSynchronizer(source, cryptoContext);
    if (version < 5) {
      loadObsoleteSpentOutputs(source, cryptoContext);
    }

    loadUnlockTransactionsJobs(source, cryptoContext);

    if (version < 5) {
      loadObsoleteChange(source, cryptoContext);
    }

    if (version > 3) {
      loadUncommitedTransactions(source, cryptoContext);
    }
  } else {
    resetCachedBalance();
  }

  if (details && cache) {
    updateTransactionsBaseStatus();
  }
}
void WalletSerializerV1::loadWalletV1(Common::IInputStream& source, const Crypto::chacha8_key& key) {
  CryptoContext cryptoContext;

  CryptoNote::BinaryInputStreamSerializer encrypted(source);

  encrypted(cryptoContext.iv, "iv");
  cryptoContext.key = key;

  std::string cipher;
  encrypted(cipher, "data");

  std::string plain = decrypt(cipher, cryptoContext);

  MemoryInputStream decryptedStream(plain.data(), plain.size());
  CryptoNote::BinaryInputStreamSerializer serializer(decryptedStream);

  loadWalletV1Keys(serializer);

  try
  {
    checkKeys();
  }
  /* Remove the partially (incorrectly) parsed wallet, pass is wrong */
  catch (const std::system_error &e)
  {
    m_walletsContainer.clear();
    throw(e);
  }

  subscribeWallets();

  bool detailsSaved;
  serializer(detailsSaved, "has_details");

  if (detailsSaved) {
    loadWalletV1Details(serializer);
  }
}