void WalletSerializerV1::loadTransfers(Common::IInputStream& source, CryptoContext& cryptoContext, uint32_t version) {
  uint64_t count = 0;
  deserializeEncrypted(count, "transfers_count", cryptoContext, source);
  cryptoContext.incIv();

  m_transfers.reserve(count);

  for (uint64_t i = 0; i < count; ++i) {
    uint64_t txId = 0;
    deserializeEncrypted(txId, "transaction_id", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransferDto dto(version);
    deserializeEncrypted(dto, "transfer", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransfer tr;
    tr.address = dto.address;
    tr.amount = dto.amount;

    if (version > 2) {
      tr.type = static_cast<WalletTransferType>(dto.type);
    } else {
      tr.type = WalletTransferType::USUAL;
    }

    m_transfers.push_back(std::make_pair(txId, tr));
  }
}
void WalletSerializerV1::loadUnlockTransactionsJobs(Common::IInputStream& source, CryptoContext& cryptoContext) {
  auto& index = m_unlockTransactions.get<TransactionHashIndex>();
  auto& walletsIndex = m_walletsContainer.get<RandomAccessIndex>();
  const uint64_t walletsSize = walletsIndex.size();
  if (walletsSize) {}

  uint64_t jobsCount = 0;
  deserializeEncrypted(jobsCount, "unlock_transactions_jobs_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < jobsCount; ++i) {
    UnlockTransactionJobDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    assert(dto.walletIndex < walletsSize);

    UnlockTransactionJob job;
    job.blockHeight = dto.blockHeight;
    job.transactionHash = dto.transactionHash;
    job.container = walletsIndex[dto.walletIndex].container;

    index.insert(std::move(job));
  }
}
void WalletSerializerV1::loadTransactions(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "transactions_count", cryptoContext, source);
  cryptoContext.incIv();

  m_transactions.get<RandomAccessIndex>().reserve(count);

  for (uint64_t i = 0; i < count; ++i) {
    WalletTransactionDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransaction tx;
    tx.state = dto.state;
    tx.timestamp = dto.timestamp;
    tx.blockHeight = dto.blockHeight;
    tx.hash = dto.hash;
    tx.totalAmount = dto.totalAmount;
    tx.fee = dto.fee;
    tx.creationTime = dto.creationTime;
    tx.unlockTime = dto.unlockTime;
    tx.extra = dto.extra;
    tx.isBase = false;

    m_transactions.get<RandomAccessIndex>().push_back(std::move(tx));
  }
}
void WalletSerializerV1::loadFlags(bool& details, bool& cache, Common::IInputStream& source, CryptoContext& cryptoContext) {
  deserializeEncrypted(details, "details", cryptoContext, source);
  cryptoContext.incIv();

  deserializeEncrypted(cache, "cache", cryptoContext, source);
  cryptoContext.incIv();
}
void WalletSerializerV1::loadBalances(Common::IInputStream& source, CryptoContext& cryptoContext) {
  deserializeEncrypted(m_actualBalance, "actual_balance", cryptoContext, source);
  cryptoContext.incIv();

  deserializeEncrypted(m_pendingBalance, "pending_balance", cryptoContext, source);
  cryptoContext.incIv();
}
Exemplo n.º 6
0
void WalletSerializer::loadSpentOutputs(Common::IInputStream& source, CryptoContext& cryptoContext) {
  auto& index = m_spentOutputs.get<WalletIndex>();
  auto& walletsIndex = m_walletsContainer.get<RandomAccessIndex>();
  const uint64_t walletsSize = walletsIndex.size();

  uint64_t count = 0;
  deserializeEncrypted(count, "spent_outputs_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; ++i) {
    SpentOutputDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    assert(dto.walletIndex < walletsSize);

    SpentOutput output;
    output.amount = dto.amount;
    output.transactionHash = dto.transactionHash;
    output.outputInTransaction = dto.outputInTransaction;
    output.spendingTransactionHash = dto.spendingTransactionHash;
    output.wallet = &walletsIndex[dto.walletIndex];

    index.insert(std::move(output));
  }
}
void WalletSerializerV1::loadObsoleteChange(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "changes_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; i++) {
    ObsoleteChangeDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();
  }
}
void WalletSerializerV1::loadObsoleteSpentOutputs(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "spent_outputs_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; ++i) {
    ObsoleteSpentOutputDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();
  }
}
Exemplo n.º 9
0
void WalletSerializer::loadChange(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "changes_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; i++) {
    ChangeDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    m_change[dto.txHash] = dto.amount;
  }
}
Exemplo n.º 10
0
void WalletSerializer::loadWallets(Common::IInputStream& source, CryptoContext& cryptoContext) {
  auto& index = m_walletsContainer.get<RandomAccessIndex>();

  uint64_t count = 0;
  deserializeEncrypted(count, "wallets_count", cryptoContext, source);
  cryptoContext.incIv();

  bool isTrackingMode;

  for (uint64_t i = 0; i < count; ++i) {
    WalletRecordDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    if (i == 0) {
      isTrackingMode = dto.spendSecretKey == NULL_SECRET_KEY;
    } else if ((isTrackingMode && dto.spendSecretKey != NULL_SECRET_KEY) || (!isTrackingMode && dto.spendSecretKey == NULL_SECRET_KEY)) {
      throw std::system_error(make_error_code(error::BAD_ADDRESS), "All addresses must be whether tracking or not");
    }

    if (dto.spendSecretKey != NULL_SECRET_KEY) {
      Crypto::PublicKey restoredPublicKey;
      bool r = Crypto::secret_key_to_public_key(dto.spendSecretKey, restoredPublicKey);

      if (!r || dto.spendPublicKey != restoredPublicKey) {
        throw std::system_error(make_error_code(error::WRONG_PASSWORD), "Restored spend public key doesn't correspond to secret key");
      }
    } else {
      if (!Crypto::check_key(dto.spendPublicKey)) {
        throw std::system_error(make_error_code(error::WRONG_PASSWORD), "Public spend key is incorrect");
      }
    }

    WalletRecord wallet;
    wallet.spendPublicKey = dto.spendPublicKey;
    wallet.spendSecretKey = dto.spendSecretKey;
    wallet.actualBalance = dto.actualBalance;
    wallet.pendingBalance = dto.pendingBalance;
    wallet.creationTimestamp = static_cast<time_t>(dto.creationTimestamp);
    wallet.container = reinterpret_cast<CryptoNote::ITransfersContainer*>(i); //dirty hack. container field must be unique

    index.push_back(wallet);
  }
}
void WalletSerializerV1::loadTransfersSynchronizer(Common::IInputStream& source, CryptoContext& cryptoContext) {
  std::string deciphered;
  deserializeEncrypted(deciphered, "transfers_synchronizer", cryptoContext, source);
  cryptoContext.incIv();

  std::stringstream stream(deciphered);
  deciphered.clear();

  m_synchronizer.load(stream);
}
Exemplo n.º 12
0
void WalletSerializer::loadTransfers(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "transfers_count", cryptoContext, source);
  cryptoContext.incIv();

  m_transfers.reserve(count);

  for (uint64_t i = 0; i < count; ++i) {
    uint64_t txId = 0;
    deserializeEncrypted(txId, "transaction_id", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransferDto dto;
    deserializeEncrypted(dto, "transfer", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransfer tr;
    tr.address = dto.address;
    tr.amount = dto.amount;

    m_transfers.push_back(std::make_pair(txId, tr));
  }
}
Exemplo n.º 13
0
void WalletSerializer::loadWallets(Common::IInputStream& source, CryptoContext& cryptoContext) {
  auto& index = m_walletsContainer.get<RandomAccessIndex>();

  uint64_t count = 0;
  deserializeEncrypted(count, "wallets_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; ++i) {
    WalletRecordDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    WalletRecord wallet;
    wallet.spendPublicKey = dto.spendPublicKey;
    wallet.spendSecretKey = dto.spendSecretKey;
    wallet.actualBalance = dto.actualBalance;
    wallet.pendingBalance = dto.pendingBalance;
    wallet.creationTimestamp = static_cast<time_t>(dto.creationTimestamp);
    wallet.container = reinterpret_cast<CryptoNote::ITransfersContainer*>(i); //dirty hack. container field must be unique

    index.push_back(wallet);
  }
}
void WalletSerializerV1::loadUncommitedTransactions(Common::IInputStream& source, CryptoContext& cryptoContext) {
  deserializeEncrypted(m_uncommitedTransactions, "uncommited_transactions", cryptoContext, source);
}
void WalletSerializerV1::loadSecretKey(Common::IInputStream& source, CryptoContext& cryptoContext) {
  deserializeEncrypted(m_viewSecretKey, "secret_key", cryptoContext, source);
  cryptoContext.incIv();
}
void WalletSerializerV1::loadPublicKey(Common::IInputStream& source, CryptoContext& cryptoContext) {
  deserializeEncrypted(m_viewPublicKey, "public_key", cryptoContext, source);
  cryptoContext.incIv();
}