2018-05-24 14:28:23 +02:00
|
|
|
// Copyright (c) 2018 The Dash Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "evodb.h"
|
|
|
|
|
|
|
|
CEvoDB* evoDb;
|
|
|
|
|
|
|
|
CEvoDB::CEvoDB(size_t nCacheSize, bool fMemory, bool fWipe) :
|
2018-11-06 09:54:23 +01:00
|
|
|
db(fMemory ? "" : (GetDataDir() / "evodb"), nCacheSize, fMemory, fWipe),
|
2019-03-06 20:45:39 +01:00
|
|
|
rootBatch(db),
|
|
|
|
rootDBTransaction(db, rootBatch),
|
|
|
|
curDBTransaction(rootDBTransaction, rootDBTransaction)
|
2018-05-24 14:28:23 +02:00
|
|
|
{
|
|
|
|
}
|
2018-12-13 09:11:50 +01:00
|
|
|
|
2019-03-06 20:45:39 +01:00
|
|
|
bool CEvoDB::CommitRootTransaction()
|
|
|
|
{
|
|
|
|
assert(curDBTransaction.IsClean());
|
|
|
|
rootDBTransaction.Commit();
|
|
|
|
bool ret = db.WriteBatch(rootBatch);
|
|
|
|
rootBatch.Clear();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-12-13 09:11:50 +01:00
|
|
|
bool CEvoDB::VerifyBestBlock(const uint256& hash)
|
|
|
|
{
|
|
|
|
// Make sure evodb is consistent.
|
|
|
|
// If we already have best block hash saved, the previous block should match it.
|
|
|
|
uint256 hashBestBlock;
|
|
|
|
bool fHasBestBlock = Read(EVODB_BEST_BLOCK, hashBestBlock);
|
|
|
|
uint256 hashBlockIndex = fHasBestBlock ? hash : uint256();
|
|
|
|
assert(hashBestBlock == hashBlockIndex);
|
|
|
|
|
|
|
|
return fHasBestBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEvoDB::WriteBestBlock(const uint256& hash)
|
|
|
|
{
|
|
|
|
Write(EVODB_BEST_BLOCK, hash);
|
|
|
|
}
|