aboutsummaryrefslogtreecommitdiff
path: root/src/txdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/txdb.cpp')
-rw-r--r--src/txdb.cpp45
1 files changed, 18 insertions, 27 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index d1f26e9f64..99deb31404 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -4,9 +4,11 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "txdb.h"
-#include "main.h"
-#include "hash.h"
-#include "chainparams.h"
+
+#include "core.h"
+#include "uint256.h"
+
+#include <stdint.h>
using namespace std;
@@ -38,35 +40,32 @@ bool CCoinsViewDB::HaveCoins(const uint256 &txid) {
return db.Exists(make_pair('c', txid));
}
-CBlockIndex *CCoinsViewDB::GetBestBlock() {
+uint256 CCoinsViewDB::GetBestBlock() {
uint256 hashBestChain;
if (!db.Read('B', hashBestChain))
- return NULL;
- std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(hashBestChain);
- if (it == mapBlockIndex.end())
- return NULL;
- return it->second;
+ return uint256(0);
+ return hashBestChain;
}
-bool CCoinsViewDB::SetBestBlock(CBlockIndex *pindex) {
+bool CCoinsViewDB::SetBestBlock(const uint256 &hashBlock) {
CLevelDBBatch batch;
- BatchWriteHashBestChain(batch, pindex->GetBlockHash());
+ BatchWriteHashBestChain(batch, hashBlock);
return db.WriteBatch(batch);
}
-bool CCoinsViewDB::BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex) {
+bool CCoinsViewDB::BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock) {
LogPrint("coindb", "Committing %u changed transactions to coin database...\n", (unsigned int)mapCoins.size());
CLevelDBBatch batch;
for (std::map<uint256, CCoins>::const_iterator it = mapCoins.begin(); it != mapCoins.end(); it++)
BatchWriteCoins(batch, it->first, it->second);
- if (pindex)
- BatchWriteHashBestChain(batch, pindex->GetBlockHash());
+ if (hashBlock != uint256(0))
+ BatchWriteHashBestChain(batch, hashBlock);
return db.WriteBatch(batch);
}
-CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDB(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) {
+CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) {
}
bool CBlockTreeDB::WriteBlockIndex(const CDiskBlockIndex& blockindex)
@@ -74,13 +73,9 @@ bool CBlockTreeDB::WriteBlockIndex(const CDiskBlockIndex& blockindex)
return Write(make_pair('b', blockindex.GetBlockHash()), blockindex);
}
-bool CBlockTreeDB::ReadBestInvalidWork(CBigNum& bnBestInvalidWork)
-{
- return Read('I', bnBestInvalidWork);
-}
-
bool CBlockTreeDB::WriteBestInvalidWork(const CBigNum& bnBestInvalidWork)
{
+ // Obsolete; only written for backward compatibility.
return Write('I', bnBestInvalidWork);
}
@@ -117,9 +112,9 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
pcursor->SeekToFirst();
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
- stats.hashBlock = GetBestBlock()->GetBlockHash();
+ stats.hashBlock = GetBestBlock();
ss << stats.hashBlock;
- int64 nTotalAmount = 0;
+ int64_t nTotalAmount = 0;
while (pcursor->Valid()) {
boost::this_thread::interruption_point();
try {
@@ -157,7 +152,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
}
}
delete pcursor;
- stats.nHeight = GetBestBlock()->nHeight;
+ stats.nHeight = mapBlockIndex.find(GetBestBlock())->second->nHeight;
stats.hashSerialized = ss.GetHash();
stats.nTotalAmount = nTotalAmount;
return true;
@@ -223,10 +218,6 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
pindexNew->nStatus = diskindex.nStatus;
pindexNew->nTx = diskindex.nTx;
- // Watch for genesis block
- if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == Params().HashGenesisBlock())
- pindexGenesisBlock = pindexNew;
-
if (!pindexNew->CheckIndex())
return error("LoadBlockIndex() : CheckIndex failed: %s", pindexNew->ToString().c_str());