* Compute smart timestamp for a transaction being added to the wallet. * * Logic: * - If sending a transaction, assign its timestamp to the current time. * - If receiving a transaction outside a block, assign its timestamp to the * current time. * - If receiving a block with a future timestamp, assign all its (not already * known) transactions' timestamps to the current time. * - If re
| 3857 | * https://github.com/bitcoin/bitcoin/pull/1393. |
| 3858 | */ |
| 3859 | unsigned int CWallet::ComputeTimeSmart(const CWalletTx& wtx) const |
| 3860 | { |
| 3861 | unsigned int nTimeSmart = wtx.nTimeReceived; |
| 3862 | if (!wtx.hashUnset()) { |
| 3863 | if (const CBlockIndex* pindex = LookupBlockIndex(wtx.hashBlock)) { |
| 3864 | int64_t latestNow = wtx.nTimeReceived; |
| 3865 | int64_t latestEntry = 0; |
| 3866 | |
| 3867 | // Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future |
| 3868 | int64_t latestTolerated = latestNow + 300; |
| 3869 | const TxItems& txOrdered = wtxOrdered; |
| 3870 | for (auto it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) { |
| 3871 | CWalletTx* const pwtx = it->second.first; |
| 3872 | if (pwtx == &wtx) { |
| 3873 | continue; |
| 3874 | } |
| 3875 | CAccountingEntry* const pacentry = it->second.second; |
| 3876 | int64_t nSmartTime; |
| 3877 | if (pwtx) { |
| 3878 | nSmartTime = pwtx->nTimeSmart; |
| 3879 | if (!nSmartTime) { |
| 3880 | nSmartTime = pwtx->nTimeReceived; |
| 3881 | } |
| 3882 | } else { |
| 3883 | nSmartTime = pacentry->nTime; |
| 3884 | } |
| 3885 | if (nSmartTime <= latestTolerated) { |
| 3886 | latestEntry = nSmartTime; |
| 3887 | if (nSmartTime > latestNow) { |
| 3888 | latestNow = nSmartTime; |
| 3889 | } |
| 3890 | break; |
| 3891 | } |
| 3892 | } |
| 3893 | |
| 3894 | int64_t blocktime = pindex->GetBlockTime(); |
| 3895 | nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow)); |
| 3896 | } else { |
| 3897 | WalletLogPrintf("%s: found %s in block %s not in index\n", __func__, wtx.GetHash().ToString(), wtx.hashBlock.ToString()); |
| 3898 | } |
| 3899 | } |
| 3900 | return nTimeSmart; |
| 3901 | } |
| 3902 | |
| 3903 | bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value) |
| 3904 | { |
nothing calls this directly
no test coverage detected