@@ -896,51 +896,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
896896 wtx.nTimeReceived = GetAdjustedTime ();
897897 wtx.nOrderPos = IncOrderPosNext (&walletdb);
898898 wtxOrdered.insert (make_pair (wtx.nOrderPos , TxPair (&wtx, (CAccountingEntry*)0 )));
899-
900- wtx.nTimeSmart = wtx.nTimeReceived ;
901- if (!wtxIn.hashUnset ())
902- {
903- if (mapBlockIndex.count (wtxIn.hashBlock ))
904- {
905- int64_t latestNow = wtx.nTimeReceived ;
906- int64_t latestEntry = 0 ;
907- {
908- // Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future
909- int64_t latestTolerated = latestNow + 300 ;
910- const TxItems & txOrdered = wtxOrdered;
911- for (TxItems::const_reverse_iterator it = txOrdered.rbegin (); it != txOrdered.rend (); ++it)
912- {
913- CWalletTx *const pwtx = (*it).second .first ;
914- if (pwtx == &wtx)
915- continue ;
916- CAccountingEntry *const pacentry = (*it).second .second ;
917- int64_t nSmartTime;
918- if (pwtx)
919- {
920- nSmartTime = pwtx->nTimeSmart ;
921- if (!nSmartTime)
922- nSmartTime = pwtx->nTimeReceived ;
923- }
924- else
925- nSmartTime = pacentry->nTime ;
926- if (nSmartTime <= latestTolerated)
927- {
928- latestEntry = nSmartTime;
929- if (nSmartTime > latestNow)
930- latestNow = nSmartTime;
931- break ;
932- }
933- }
934- }
935-
936- int64_t blocktime = mapBlockIndex[wtxIn.hashBlock ]->GetBlockTime ();
937- wtx.nTimeSmart = std::max (latestEntry, std::min (blocktime, latestNow));
938- }
939- else
940- LogPrintf (" AddToWallet(): found %s in block %s not in index\n " ,
941- wtxIn.GetHash ().ToString (),
942- wtxIn.hashBlock .ToString ());
943- }
899+ wtx.nTimeSmart = ComputeTimeSmart (wtx);
944900 AddToSpends (hash);
945901 }
946902
@@ -3498,6 +3454,55 @@ void CWallet::GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) c
34983454 mapKeyBirth[it->first ] = it->second ->GetBlockTime () - 7200 ; // block times can be 2h off
34993455}
35003456
3457+ unsigned int CWallet::ComputeTimeSmart (const CWalletTx& wtx) const
3458+ {
3459+ unsigned int nTimeSmart = wtx.nTimeReceived ;
3460+ if (!wtx.hashUnset ())
3461+ {
3462+ if (mapBlockIndex.count (wtx.hashBlock ))
3463+ {
3464+ int64_t latestNow = wtx.nTimeReceived ;
3465+ int64_t latestEntry = 0 ;
3466+ {
3467+ // Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future
3468+ int64_t latestTolerated = latestNow + 300 ;
3469+ const TxItems & txOrdered = wtxOrdered;
3470+ for (TxItems::const_reverse_iterator it = txOrdered.rbegin (); it != txOrdered.rend (); ++it)
3471+ {
3472+ CWalletTx *const pwtx = (*it).second .first ;
3473+ if (pwtx == &wtx)
3474+ continue ;
3475+ CAccountingEntry *const pacentry = (*it).second .second ;
3476+ int64_t nSmartTime;
3477+ if (pwtx)
3478+ {
3479+ nSmartTime = pwtx->nTimeSmart ;
3480+ if (!nSmartTime)
3481+ nSmartTime = pwtx->nTimeReceived ;
3482+ }
3483+ else
3484+ nSmartTime = pacentry->nTime ;
3485+ if (nSmartTime <= latestTolerated)
3486+ {
3487+ latestEntry = nSmartTime;
3488+ if (nSmartTime > latestNow)
3489+ latestNow = nSmartTime;
3490+ break ;
3491+ }
3492+ }
3493+ }
3494+
3495+ int64_t blocktime = mapBlockIndex[wtx.hashBlock ]->GetBlockTime ();
3496+ nTimeSmart = std::max (latestEntry, std::min (blocktime, latestNow));
3497+ }
3498+ else
3499+ LogPrintf (" AddToWallet(): found %s in block %s not in index\n " ,
3500+ wtx.GetHash ().ToString (),
3501+ wtx.hashBlock .ToString ());
3502+ }
3503+ return nTimeSmart;
3504+ }
3505+
35013506bool CWallet::AddDestData (const CTxDestination &dest, const std::string &key, const std::string &value)
35023507{
35033508 if (boost::get<CNoDestination>(&dest))
0 commit comments