Skip to content

Commit 209377a

Browse files
committed
Use GetBlockTime() more
1 parent 6654a87 commit 209377a

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

src/checkpoints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace Checkpoints {
127127
} else {
128128
double nCheapBefore = data.nTransactionsLastCheckpoint;
129129
double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
130-
double nExpensiveAfter = (nNow - pindex->nTime)/86400.0*data.fTransactionsPerDay;
130+
double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
131131
fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
132132
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
133133
}

src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
17881788

17891789
// BIP16 didn't become active until Apr 1 2012
17901790
int64_t nBIP16SwitchTime = 1333238400;
1791-
bool fStrictPayToScriptHash = (pindex->nTime >= nBIP16SwitchTime);
1791+
bool fStrictPayToScriptHash = (pindex->GetBlockTime() >= nBIP16SwitchTime);
17921792

17931793
unsigned int flags = SCRIPT_VERIFY_NOCACHE |
17941794
(fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE);
@@ -2437,7 +2437,7 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
24372437
if (pcheckpoint && block.hashPrevBlock != (chainActive.Tip() ? chainActive.Tip()->GetBlockHash() : uint256(0)))
24382438
{
24392439
// Extra checks to prevent "fill up memory by spamming with bogus blocks"
2440-
int64_t deltaTime = block.GetBlockTime() - pcheckpoint->nTime;
2440+
int64_t deltaTime = block.GetBlockTime() - pcheckpoint->GetBlockTime();
24412441
if (deltaTime < 0)
24422442
{
24432443
return state.DoS(100, error("CheckBlockHeader() : block with timestamp before last checkpoint"),
@@ -2548,7 +2548,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
25482548
CDiskBlockPos blockPos;
25492549
if (dbp != NULL)
25502550
blockPos = *dbp;
2551-
if (!FindBlockPos(state, blockPos, nBlockSize+8, nHeight, block.nTime, dbp != NULL))
2551+
if (!FindBlockPos(state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL))
25522552
return error("AcceptBlock() : FindBlockPos failed");
25532553
if (dbp == NULL)
25542554
if (!WriteBlockToDisk(block, blockPos))
@@ -3146,7 +3146,7 @@ bool InitBlockIndex() {
31463146
unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION);
31473147
CDiskBlockPos blockPos;
31483148
CValidationState state;
3149-
if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.nTime))
3149+
if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.GetBlockTime()))
31503150
return error("LoadBlockIndex() : FindBlockPos failed");
31513151
if (!WriteBlockToDisk(block, blockPos))
31523152
return error("LoadBlockIndex() : writing genesis block to disk failed");

src/pow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
2626
// Special difficulty rule for testnet:
2727
// If the new block's timestamp is more than 2* 10 minutes
2828
// then allow mining of a min-difficulty block.
29-
if (pblock->nTime > pindexLast->nTime + Params().TargetSpacing()*2)
29+
if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + Params().TargetSpacing()*2)
3030
return nProofOfWorkLimit;
3131
else
3232
{

src/qt/clientmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ QDateTime ClientModel::getLastBlockDate() const
8585
if (chainActive.Tip())
8686
return QDateTime::fromTime_t(chainActive.Tip()->GetBlockTime());
8787
else
88-
return QDateTime::fromTime_t(Params().GenesisBlock().nTime); // Genesis block's time of current network
88+
return QDateTime::fromTime_t(Params().GenesisBlock().GetBlockTime()); // Genesis block's time of current network
8989
}
9090

9191
double ClientModel::getVerificationProgress() const

src/rpcdump.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Value importwallet(const Array& params, bool fHelp)
157157
if (!file.is_open())
158158
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
159159

160-
int64_t nTimeBegin = chainActive.Tip()->nTime;
160+
int64_t nTimeBegin = chainActive.Tip()->GetBlockTime();
161161

162162
bool fGood = true;
163163

@@ -215,7 +215,7 @@ Value importwallet(const Array& params, bool fHelp)
215215
pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI
216216

217217
CBlockIndex *pindex = chainActive.Tip();
218-
while (pindex && pindex->pprev && pindex->nTime > nTimeBegin - 7200)
218+
while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200)
219219
pindex = pindex->pprev;
220220

221221
if (!pwalletMain->nTimeFirstKey || nTimeBegin < pwalletMain->nTimeFirstKey)
@@ -301,7 +301,7 @@ Value dumpwallet(const Array& params, bool fHelp)
301301
file << strprintf("# Wallet dump created by Bitcoin %s (%s)\n", CLIENT_BUILD, CLIENT_DATE);
302302
file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime()));
303303
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
304-
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->nTime));
304+
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
305305
file << "\n";
306306
for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
307307
const CKeyID &keyid = it->second;

src/rpcmining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
442442
result.push_back(Pair("noncerange", "00000000ffffffff"));
443443
result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
444444
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
445-
result.push_back(Pair("curtime", (int64_t)pblock->nTime));
445+
result.push_back(Pair("curtime", pblock->GetBlockTime()));
446446
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
447447
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
448448

src/rpcrawtransaction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
9999
if (chainActive.Contains(pindex))
100100
{
101101
entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight));
102-
entry.push_back(Pair("time", (int64_t)pindex->nTime));
103-
entry.push_back(Pair("blocktime", (int64_t)pindex->nTime));
102+
entry.push_back(Pair("time", pindex->GetBlockTime()));
103+
entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
104104
}
105105
else
106106
entry.push_back(Pair("confirmations", 0));

src/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
5050
{
5151
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
5252
entry.push_back(Pair("blockindex", wtx.nIndex));
53-
entry.push_back(Pair("blocktime", (int64_t)(mapBlockIndex[wtx.hashBlock]->nTime)));
53+
entry.push_back(Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime()));
5454
}
5555
uint256 hash = wtx.GetHash();
5656
entry.push_back(Pair("txid", hash.GetHex()));

src/wallet.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
515515
{
516516
if (mapBlockIndex.count(wtxIn.hashBlock))
517517
{
518-
unsigned int latestNow = wtx.nTimeReceived;
519-
unsigned int latestEntry = 0;
518+
int64_t latestNow = wtx.nTimeReceived;
519+
int64_t latestEntry = 0;
520520
{
521521
// Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future
522522
int64_t latestTolerated = latestNow + 300;
@@ -547,7 +547,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
547547
}
548548
}
549549

550-
unsigned int& blocktime = mapBlockIndex[wtxIn.hashBlock]->nTime;
550+
int64_t blocktime = mapBlockIndex[wtxIn.hashBlock]->GetBlockTime();
551551
wtx.nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow));
552552
}
553553
else
@@ -889,7 +889,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
889889

890890
// no need to read and scan block, if block was created before
891891
// our wallet birthday (as adjusted for block time variability)
892-
while (pindex && nTimeFirstKey && (pindex->nTime < (nTimeFirstKey - 7200)))
892+
while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - 7200)))
893893
pindex = chainActive.Next(pindex);
894894

895895
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
@@ -2092,7 +2092,7 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
20922092

20932093
// Extract block timestamps for those keys
20942094
for (std::map<CKeyID, CBlockIndex*>::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++)
2095-
mapKeyBirth[it->first] = it->second->nTime - 7200; // block times can be 2h off
2095+
mapKeyBirth[it->first] = it->second->GetBlockTime() - 7200; // block times can be 2h off
20962096
}
20972097

20982098
bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)

0 commit comments

Comments
 (0)