X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fwallet.cpp;h=96dbdeb7f4702fd08a88d19acb6f14c87ce9a93f;hb=5467a4509d8303226a816edd6ee32db69d37f923;hp=dc1000c0bc3454d60f6cc3f38e143327e834ed4f;hpb=9958f531a04f41133dfb10ff14c1422164ec1080;p=novacoin.git diff --git a/src/wallet.cpp b/src/wallet.cpp index dc1000c..96dbdeb 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -393,6 +393,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock) wtx.MarkSpent(txin.prevout.n); wtx.WriteToDisk(); NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED); + vMintingWalletUpdated.push_back(txin.prevout.hash); } } } @@ -410,6 +411,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock) wtx.MarkUnspent(&txout - &tx.vout[0]); wtx.WriteToDisk(); NotifyTransactionChanged(this, hash, CT_UPDATED); + vMintingWalletUpdated.push_back(hash); } } } @@ -540,7 +542,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) // Notify UI of new or updated transaction NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED); - + vMintingWalletUpdated.push_back(hash); // notify an external script when a wallet transaction comes in or is updated std::string strCmd = GetArg("-walletnotify", ""); @@ -1679,7 +1681,7 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint } if (fDebug) - printf("Get stake weight: %zu meta items loaded for %zu coins\n", mapMeta.size(), setCoins.size()); + printf("Get stake weight: %d meta items loaded for %d coins\n", mapMeta.size(), setCoins.size()); fCoinsDataActual = true; } @@ -1912,7 +1914,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int } if (fDebug) - printf("Stake miner: %zu meta items loaded for %zu coins\n", mapMeta.size(), setCoins.size()); + printf("Stake miner: %d meta items loaded for %d coins\n", mapMeta.size(), setCoins.size()); fCoinsDataActual = true; } @@ -2041,7 +2043,13 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int CTxDB txdb("r"); if (!txNew.GetCoinAge(txdb, nCoinAge)) return error("CreateCoinStake : failed to calculate coin age"); - nCredit += GetProofOfStakeReward(nCoinAge, nBits, txNew.nTime); + + int64 nReward = GetProofOfStakeReward(nCoinAge, nBits, txNew.nTime); + // Refuse to create mint that has zero or negative reward + if(nReward <= 0) + return false; + + nCredit += nReward; } int64 nMinFee = 0; @@ -2116,6 +2124,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) coin.MarkSpent(txin.prevout.n); coin.WriteToDisk(); NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED); + vMintingWalletUpdated.push_back(coin.GetHash()); } if (fFileBacked) @@ -2721,7 +2730,10 @@ void CWallet::UpdatedTransaction(const uint256 &hashTx) // Only notify UI if this transaction is in this wallet map::const_iterator mi = mapWallet.find(hashTx); if (mi != mapWallet.end()) + { NotifyTransactionChanged(this, hashTx, CT_UPDATED); + vMintingWalletUpdated.push_back(hashTx); + } } } @@ -2775,3 +2787,21 @@ void CWallet::GetKeyBirthTimes(std::map &mapKeyBirth) const { for (std::map::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++) mapKeyBirth[it->first] = it->second->nTime - 7200; // block times can be 2h off } + +void CWallet::ClearOrphans() +{ + list orphans; + + LOCK(cs_wallet); + for(map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + { + const CWalletTx *wtx = &(*it).second; + if((wtx->IsCoinBase() || wtx->IsCoinStake()) && !wtx->IsInMainChain()) + { + orphans.push_back(wtx->GetHash()); + } + } + + for(list::const_iterator it = orphans.begin(); it != orphans.end(); ++it) + EraseFromWallet(*it); +}