Skip to content

Commit 006aa49

Browse files
authored
Merge pull request #2144 from div72/change-nTimeSmart
wallet: simplify nTimeSmart calculation
2 parents 052113a + 16dca01 commit 006aa49

File tree

1 file changed

+7
-42
lines changed

1 file changed

+7
-42
lines changed

src/wallet/wallet.cpp

+7-42
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,11 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
480480
LOCK(cs_wallet);
481481
// Inserts only if not already there, returns tx inserted or tx found
482482
pair<map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(make_pair(hash, wtxIn));
483-
CWalletTx& wtx = (*ret.first).second;
483+
CWalletTx& wtx = ret.first->second;
484484
wtx.BindWallet(this);
485485
bool fInsertedNew = ret.second;
486+
bool fUpdated = false;
487+
486488
if (fInsertedNew)
487489
{
488490
wtx.nTimeReceived = GetAdjustedTime();
@@ -494,53 +496,16 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
494496
auto mapItem = mapBlockIndex.find(wtxIn.hashBlock);
495497
if (mapItem != mapBlockIndex.end())
496498
{
497-
unsigned int latestNow = wtx.nTimeReceived;
498-
unsigned int latestEntry = 0;
499-
{
500-
// Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future
501-
int64_t latestTolerated = latestNow + 300;
502-
std::list<CAccountingEntry> acentries;
503-
TxItems txOrdered = OrderedTxItems(acentries);
504-
for (TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
505-
{
506-
CWalletTx *const pwtx = (*it).second.first;
507-
if (pwtx == &wtx)
508-
continue;
509-
CAccountingEntry *const pacentry = (*it).second.second;
510-
int64_t nSmartTime;
511-
if (pwtx)
512-
{
513-
nSmartTime = pwtx->nTimeSmart;
514-
if (!nSmartTime)
515-
nSmartTime = pwtx->nTimeReceived;
516-
}
517-
else
518-
nSmartTime = pacentry->nTime;
519-
if (nSmartTime <= latestTolerated)
520-
{
521-
latestEntry = nSmartTime;
522-
if (nSmartTime > latestNow)
523-
latestNow = nSmartTime;
524-
break;
525-
}
526-
}
527-
}
528-
529-
unsigned int& blocktime = mapItem->second->nTime;
530-
wtx.nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow));
499+
wtx.nTimeSmart = mapItem->second->nTime;
531500
}
532501
else
533502
{
534503
LogPrint(BCLog::LogFlags::VERBOSE, "AddToWallet() : found %s in block %s not in index",
535-
wtxIn.GetHash().ToString().substr(0,10),
504+
hash.ToString().substr(0,10),
536505
wtxIn.hashBlock.ToString());
537506
}
538507
}
539-
}
540-
541-
bool fUpdated = false;
542-
if (!fInsertedNew)
543-
{
508+
} else {
544509
// Merge
545510
if (!wtxIn.hashBlock.IsNull() && wtxIn.hashBlock != wtx.hashBlock)
546511
{
@@ -594,7 +559,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
594559
std::string strCmd = gArgs.GetArg("-walletnotify", "");
595560
if (!strCmd.empty())
596561
{
597-
boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
562+
boost::replace_all(strCmd, "%s", hash.GetHex());
598563
boost::thread t(runCommand, strCmd); // thread runs free
599564
}
600565

0 commit comments

Comments
 (0)