From f653dc3359ea3c1e6da16a2849107aef549cd3b6 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 25 Jan 2014 00:07:48 +0400 Subject: [PATCH] Update only if there are any mismatched coins --- src/main.cpp | 2 +- src/wallet.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dc9a84b..ccfd0aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1677,7 +1677,7 @@ bool CBlock::DisconnectBlock(CBlockIndex *pindex, CCoinsViewCache &view) } // clean up wallet after disconnecting coinstake - SyncWithWallets(vtx[i].GetHash(), vtx[i], this, true, false); + SyncWithWallets(vtx[i].GetHash(), vtx[i], this, false, false); } // move best block pointer to prevout block diff --git a/src/wallet.cpp b/src/wallet.cpp index a7663fa..4fadcf7 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -446,7 +446,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) } else printf("AddToWallet() : found %s in block %s not in index\n", - wtxIn.GetHash().ToString().substr(0,10).c_str(), + hash.ToString().substr(0,10).c_str(), wtxIn.hashBlock.ToString().c_str()); } } @@ -475,7 +475,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) } //// debug print - printf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString().substr(0,10).c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : "")); + printf("AddToWallet %s %s%s\n", hash.ToString().substr(0,10).c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : "")); // Write to disk if (fInsertedNew || fUpdated) @@ -509,7 +509,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) if ( !strCmd.empty()) { - boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex()); + boost::replace_all(strCmd, "%s", hash.GetHex()); boost::thread t(runCommand, strCmd); // thread runs free } @@ -2239,6 +2239,7 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion, bool for (unsigned int n=0; n < pcoin->vout.size(); n++) { + bool fUpdated = false; if (IsMine(pcoin->vout[n])) { if (pcoin->IsSpent(n) && coins.IsAvailable(n)) @@ -2249,6 +2250,7 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion, bool nBalanceInQuestion += pcoin->vout[n].nValue; if (!fCheckOnly) { + fUpdated = true; pcoin->MarkUnspent(n); pcoin->WriteToDisk(); } @@ -2261,22 +2263,26 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion, bool nBalanceInQuestion += pcoin->vout[n].nValue; if (!fCheckOnly) { + fUpdated = true; pcoin->MarkSpent(n); pcoin->WriteToDisk(); } } - NotifyTransactionChanged(this, hash, CT_UPDATED); + if (fUpdated) + NotifyTransactionChanged(this, hash, CT_UPDATED); } } if((pcoin->IsCoinBase() || pcoin->IsCoinStake()) && pcoin->GetDepthInMainChain() == 0) { - printf("FixSpentCoins %s orphaned generation tx %s\n", fCheckOnly ? "found" : "removed", hash.ToString().c_str()); if (!fCheckOnly) { EraseFromWallet(hash); + NotifyTransactionChanged(this, hash, CT_DELETED); } + + printf("FixSpentCoins %s orphaned generation tx %s\n", fCheckOnly ? "found" : "removed", hash.ToString().c_str()); } } } -- 1.7.1