/* Query entire wallet anew from core.
  */
 void refreshWallet()
 {
     cachedWallet.clear();
     {
         LOG_PRINT_L4("LOCK2(cs_main, wallet->cs_wallet) refreshWallet");
         LOCK2(cs_main, wallet->cs_wallet);
         LOG_PRINT_L4("LOCK2(cs_main, wallet->cs_wallet) refreshWallet acquired");
         for(auto it = wallet->mapWallet.begin(); it != wallet->mapWallet.end(); ++it)
         {
             if(TransactionRecord::showTransaction(it->second))
                 cachedWallet.append(TransactionRecord::decomposeTransaction(wallet, it->second));
         }
     }
 }
예제 #2
0
    bool Currency::getBlockReward(size_t medianSize, size_t currentBlockSize, uint64_t alreadyGeneratedCoins,
                                uint64_t fee, uint64_t& reward, int64_t& emissionChange) const {
      assert(alreadyGeneratedCoins <= m_moneySupply);
      assert(m_emissionSpeedFactor > 0 && m_emissionSpeedFactor <= 8 * sizeof(uint64_t));

      uint64_t baseReward = (m_moneySupply - alreadyGeneratedCoins) >> m_emissionSpeedFactor;

      medianSize = std::max(medianSize, m_blockGrantedFullRewardZone);
      if (currentBlockSize > UINT64_C(2) * medianSize) {
        LOG_PRINT_L4("Block cumulative size is too big: " << currentBlockSize << ", expected less than " << 2 * medianSize);
        return false;
      }

      uint64_t penalizedBaseReward = getPenalizedAmount(baseReward, medianSize, currentBlockSize);
      uint64_t penalizedFee = getPenalizedAmount(fee, medianSize, currentBlockSize);

      emissionChange = penalizedBaseReward - (fee - penalizedFee);
      reward = penalizedBaseReward + penalizedFee;

      return true;
  }
    /* Update our model of the wallet incrementally, to synchronize our model of the wallet
       with that of the core.

       Call with transaction that was added, removed or changed.
     */
    void updateWallet(const std::string &hash, int status)
    {
        LOG_PRINT_L2("TransactionTablePriv::updateWallet : " << hash << " " << status);
        {
            LOG_PRINT_L4("LOCK2(cs_main, wallet->cs_wallet) updateWallet");
            LOCK2(cs_main, wallet->cs_wallet);
            LOG_PRINT_L4("LOCK2(cs_main, wallet->cs_wallet) updateWallet acquired");

            // Find transaction in wallet
            auto mi = wallet->mapWallet.find(GetCryptoHash(hash));
            bool inWallet = mi != wallet->mapWallet.end();

            // Find bounds of this transaction in model
            QList<TransactionRecord>::iterator lower = qLowerBound(
                cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
            QList<TransactionRecord>::iterator upper = qUpperBound(
                cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
            int lowerIndex = (lower - cachedWallet.begin());
            int upperIndex = (upper - cachedWallet.begin());
            bool inModel = (lower != upper);

            // Determine whether to show transaction or not
            bool showTransaction = (inWallet && TransactionRecord::showTransaction(mi->second));

            if(status == CT_UPDATED)
            {
                if(showTransaction && !inModel)
                    status = CT_NEW; /* Not in model, but want to show, treat as new */
                if(!showTransaction && inModel)
                    status = CT_DELETED; /* In model, but want to hide, treat as deleted */
            }

            //qDebug() << "   inWallet=" + QString::number(inWallet) + " inModel=" + QString::number(inModel) +
            //            " Index=" + QString::number(lowerIndex) + "-" + QString::number(upperIndex) +
            //            " showTransaction=" + QString::number(showTransaction) + " derivedStatus=" + QString::number(status);

            switch(status)
            {
            case CT_NEW:
                if(inModel)
                {
                    LOG_PRINT_L1("TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is already in model");
                    break;
                }
                if(!inWallet)
                {
                    LOG_PRINT_L1("TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is not in wallet");
                    break;
                }
                if(showTransaction)
                {
                    // Added -- insert at the right position
                    QList<TransactionRecord> toInsert =
                            TransactionRecord::decomposeTransaction(wallet, mi->second);
                    if(!toInsert.isEmpty()) // only if something to insert
                    {
                        parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
                        int insert_idx = lowerIndex;
                        foreach(const TransactionRecord &rec, toInsert)
                        {
                            cachedWallet.insert(insert_idx, rec);
                            insert_idx += 1;
                        }
                        parent->endInsertRows();
                    }
                }
                break;
            case CT_DELETED:
                if(!inModel)
                {
                    LOG_PRINT_L1("TransactionTablePriv::updateWallet : Warning: Got CT_DELETED, but transaction is not in model");
                    break;
                }
                // Removed -- remove entire transaction from table
                parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
                cachedWallet.erase(lower, upper);
                parent->endRemoveRows();
                break;
            case CT_UPDATED:
                // Miscellaneous updates -- nothing to do, status update will take care of this, and is only computed for
                // visible transactions.
                break;
            }