Refactor/encapsulate chain globals into a CChain class

This commit is contained in:
Pieter Wuille
2013-10-10 23:07:44 +02:00
parent c74b6c3d8f
commit 4c6d41b8b6
19 changed files with 217 additions and 213 deletions

View File

@@ -42,7 +42,7 @@ int ClientModel::getNumConnections() const
int ClientModel::getNumBlocks() const
{
return nBestHeight;
return chainActive.Height();
}
int ClientModel::getNumBlocksAtStartup()
@@ -53,8 +53,8 @@ int ClientModel::getNumBlocksAtStartup()
QDateTime ClientModel::getLastBlockDate() const
{
if (pindexBest)
return QDateTime::fromTime_t(pindexBest->GetBlockTime());
if (chainActive.Tip())
return QDateTime::fromTime_t(chainActive.Tip()->GetBlockTime());
else if(!isTestNet())
return QDateTime::fromTime_t(1231006505); // Genesis block's time
else
@@ -63,7 +63,7 @@ QDateTime ClientModel::getLastBlockDate() const
double ClientModel::getVerificationProgress() const
{
return Checkpoints::GuessVerificationProgress(pindexBest);
return Checkpoints::GuessVerificationProgress(chainActive.Tip());
}
void ClientModel::updateTimer()

View File

@@ -17,7 +17,7 @@ QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
if (!IsFinalTx(wtx))
{
if (wtx.nLockTime < LOCKTIME_THRESHOLD)
return tr("Open for %n more block(s)", "", wtx.nLockTime - nBestHeight + 1);
return tr("Open for %n more block(s)", "", wtx.nLockTime - chainActive.Height() + 1);
else
return tr("Open until %1").arg(GUIUtil::dateTimeStr(wtx.nLockTime));
}

View File

@@ -160,14 +160,14 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
idx);
status.confirmed = wtx.IsConfirmed();
status.depth = wtx.GetDepthInMainChain();
status.cur_num_blocks = nBestHeight;
status.cur_num_blocks = chainActive.Height();
if (!IsFinalTx(wtx))
{
if (wtx.nLockTime < LOCKTIME_THRESHOLD)
{
status.status = TransactionStatus::OpenUntilBlock;
status.open_for = wtx.nLockTime - nBestHeight + 1;
status.open_for = wtx.nLockTime - chainActive.Height() + 1;
}
else
{
@@ -221,7 +221,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
bool TransactionRecord::statusUpdateNeeded()
{
return status.cur_num_blocks != nBestHeight;
return status.cur_num_blocks != chainActive.Height();
}
QString TransactionRecord::getTxID() const

View File

@@ -250,9 +250,9 @@ void TransactionTableModel::updateTransaction(const QString &hash, int status)
void TransactionTableModel::updateConfirmations()
{
if(nBestHeight != cachedNumBlocks)
if(chainActive.Height() != cachedNumBlocks)
{
cachedNumBlocks = nBestHeight;
cachedNumBlocks = chainActive.Height();
// Blocks came in since last poll.
// Invalidate status (number of confirmations) and (possibly) description
// for all rows. Qt is smart enough to only actually request the data for the

View File

@@ -73,10 +73,10 @@ void WalletModel::updateStatus()
void WalletModel::pollBalanceChanged()
{
if(nBestHeight != cachedNumBlocks)
if(chainActive.Height() != cachedNumBlocks)
{
// Balance and number of transactions might have changed
cachedNumBlocks = nBestHeight;
cachedNumBlocks = chainActive.Height();
checkBalanceChanged();
}
}