Example #1
0
void WalletService::transactionUpdated(CryptoNote::TransactionId transactionId) {
  CryptoNote::TransactionInfo tx;
  if (!wallet->getTransaction(transactionId, tx)) {
    return;
  }

  if (tx.totalAmount < 0) {
    return;
  }

  if (tx.blockHeight != CryptoNote::UNCONFIRMED_TRANSACTION_HEIGHT) {
    auto it = txIdIndex.find(transactionId);
    if (it != txIdIndex.end()) {
      return;
    }

    //insert confirmed transaction
    std::vector<uint8_t> extraVector(tx.extra.begin(), tx.extra.end());
    crypto::hash paymentId;
    if (!CryptoNote::getPaymentIdFromTxExtra(extraVector, paymentId)) {
      logger(Logging::DEBUGGING) << "transaction " << transactionId << " has no payment id";
      return;
    }

    insertTransaction(transactionId, paymentId);
    logger(Logging::DEBUGGING) << "transaction " << transactionId << " has been inserted to payments cache";
  } else {
    auto it = txIdIndex.find(transactionId);
    if (it != txIdIndex.end()) {
      txIdIndex.erase(it);
      logger(Logging::DEBUGGING) << "transaction " << transactionId << " has been erased from payments cache";
    }
  }
}
Example #2
0
void WalletService::loadPaymentsCache() {
  size_t txCount = wallet->getTransactionCount();

  logger(Logging::DEBUGGING) << "seeking for payments among " << txCount << " transactions";

  for (size_t id = 0; id < txCount; ++id) {
    CryptoNote::TransactionInfo tx;
    if (!wallet->getTransaction(id, tx)) {
      logger(Logging::DEBUGGING) << "tx " << id << " doesn't exist";
      continue;
    }

    if (tx.totalAmount < 0) {
      logger(Logging::DEBUGGING) << "tx " << id << " has negative amount";
      continue;
    }

    std::vector<uint8_t> extraVector(tx.extra.begin(), tx.extra.end());

    crypto::hash paymentId;
    if (!CryptoNote::getPaymentIdFromTxExtra(extraVector, paymentId)) {
      logger(Logging::DEBUGGING) << "tx " << id << " has no payment id";
      continue;
    }

    logger(Logging::DEBUGGING) << "transaction " << id << " has been inserted with payment id " << paymentId;
    insertTransaction(id, paymentId);
  }
}
TransactionId WalletUserTransactionsCache::addNewTransaction(
  uint64_t amount, uint64_t fee, const std::string& extra, const std::vector<WalletLegacyTransfer>& transfers, uint64_t unlockTime) {
  
  WalletLegacyTransaction transaction;

  transaction.firstTransferId = insertTransfers(transfers);
  transaction.transferCount = transfers.size();
  transaction.totalAmount = -static_cast<int64_t>(amount);
  transaction.fee = fee;
  transaction.sentTime = time(nullptr);
  transaction.isCoinbase = false;
  transaction.timestamp = 0;
  transaction.extra = extra;
  transaction.blockHeight = WALLET_LEGACY_UNCONFIRMED_TRANSACTION_HEIGHT;
  transaction.state = WalletLegacyTransactionState::Sending;
  transaction.unlockTime = unlockTime;

  return insertTransaction(std::move(transaction));
}
std::shared_ptr<WalletEvent> WalletUserTransactionsCache::onTransactionUpdated(const TransactionInformation& txInfo,
                                                                               int64_t txBalance) {
  std::shared_ptr<WalletEvent> event;

  TransactionId id = CryptoNote::INVALID_TRANSACTION_ID;

  if (!m_unconfirmedTransactions.findTransactionId(txInfo.transactionHash, id)) {
    id = findTransactionByHash(txInfo.transactionHash);
  } else {
    m_unconfirmedTransactions.erase(txInfo.transactionHash);
  }

  bool isCoinbase = txInfo.totalAmountIn == 0;

  if (id == CryptoNote::INVALID_TRANSACTION_ID) {
    TransactionInfo transaction;
    transaction.firstTransferId = INVALID_TRANSFER_ID;
    transaction.transferCount = 0;
    transaction.totalAmount = txBalance;
    transaction.fee = isCoinbase ? 0 : txInfo.totalAmountIn - txInfo.totalAmountOut;
    transaction.sentTime = 0;
    transaction.hash = txInfo.transactionHash;
    transaction.blockHeight = txInfo.blockHeight;
    transaction.isCoinbase = isCoinbase;
    transaction.timestamp = txInfo.timestamp;
    transaction.extra.assign(txInfo.extra.begin(), txInfo.extra.end());
    transaction.state = TransactionState::Active;
    transaction.unlockTime = txInfo.unlockTime;

    id = insertTransaction(std::move(transaction));
    // notification event
    event = std::make_shared<WalletExternalTransactionCreatedEvent>(id);
  } else {
    TransactionInfo& tr = getTransaction(id);
    tr.blockHeight = txInfo.blockHeight;
    tr.timestamp = txInfo.timestamp;
    tr.state = TransactionState::Active;
    // notification event
    event = std::make_shared<WalletTransactionUpdatedEvent>(id);
  }

  return event;
}
Example #5
0
void WalletService::externalTransactionCreated(CryptoNote::TransactionId transactionId) {
  logger(Logging::DEBUGGING) << "external transaction created " << transactionId;
  CryptoNote::TransactionInfo tx;
  if (!wallet->getTransaction(transactionId, tx)) {
    return;
  }

  if (tx.totalAmount < 0) {
    return;
  }

  logger(Logging::DEBUGGING) << "external transaction created " << transactionId << " extra size: " << tx.extra.size();
  std::vector<uint8_t> extraVector(tx.extra.begin(), tx.extra.end());
  crypto::hash paymentId;
  if (!CryptoNote::getPaymentIdFromTxExtra(extraVector, paymentId)) {
    logger(Logging::DEBUGGING) << "transaction " << transactionId << " has no payment id";
    return;
  }

  insertTransaction(transactionId, paymentId);

  logger(Logging::DEBUGGING) << "transaction " << transactionId << " has been added to payments cache";
}