mirror of
https://github.com/jwinterm/myriadcoin.git
synced 2026-11-18 10:13:54 +01:00
0.9.2
This commit is contained in:
+27
-36
@@ -1,12 +1,14 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Copyright (c) 2009-2014 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// 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;
|
||||
|
||||
@@ -24,8 +26,8 @@ void static BatchWriteHashBestChain(CLevelDBBatch &batch, const uint256 &hash) {
|
||||
CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe) {
|
||||
}
|
||||
|
||||
bool CCoinsViewDB::GetCoins(const uint256 &txid, CCoins &coins) {
|
||||
return db.Read(make_pair('c', txid), coins);
|
||||
bool CCoinsViewDB::GetCoins(const uint256 &txid, CCoins &coins) {
|
||||
return db.Read(make_pair('c', txid), coins);
|
||||
}
|
||||
|
||||
bool CCoinsViewDB::SetCoins(const uint256 &txid, const CCoins &coins) {
|
||||
@@ -35,38 +37,35 @@ bool CCoinsViewDB::SetCoins(const uint256 &txid, const CCoins &coins) {
|
||||
}
|
||||
|
||||
bool CCoinsViewDB::HaveCoins(const uint256 &txid) {
|
||||
return db.Exists(make_pair('c', 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) {
|
||||
printf("Committing %u changed transactions to coin database...\n", (unsigned int)mapCoins.size());
|
||||
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 {
|
||||
@@ -136,7 +131,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
|
||||
ssKey >> txhash;
|
||||
ss << txhash;
|
||||
ss << VARINT(coins.nVersion);
|
||||
ss << (coins.fCoinBase ? 'c' : 'n');
|
||||
ss << (coins.fCoinBase ? 'c' : 'n');
|
||||
ss << VARINT(coins.nHeight);
|
||||
stats.nTransactions++;
|
||||
for (unsigned int i=0; i<coins.vout.size(); i++) {
|
||||
@@ -153,11 +148,11 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
|
||||
}
|
||||
pcursor->Next();
|
||||
} catch (std::exception &e) {
|
||||
return error("%s() : deserialize error", __PRETTY_FUNCTION__);
|
||||
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
|
||||
}
|
||||
}
|
||||
delete pcursor;
|
||||
stats.nHeight = GetBestBlock()->nHeight;
|
||||
stats.nHeight = mapBlockIndex.find(GetBestBlock())->second->nHeight;
|
||||
stats.hashSerialized = ss.GetHash();
|
||||
stats.nTotalAmount = nTotalAmount;
|
||||
return true;
|
||||
@@ -223,19 +218,15 @@ 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());
|
||||
return error("LoadBlockIndex() : CheckIndex failed: %s", pindexNew->ToString());
|
||||
|
||||
pcursor->Next();
|
||||
} else {
|
||||
break; // if shutdown requested or finished loading block index
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
return error("%s() : deserialize error", __PRETTY_FUNCTION__);
|
||||
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
|
||||
}
|
||||
}
|
||||
delete pcursor;
|
||||
|
||||
Reference in New Issue
Block a user