17 #include <boost/thread.hpp> 59 for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
61 if (it->second.coins.IsPruned())
62 batch.Erase(make_pair(
DB_COINS, it->first));
64 batch.Write(make_pair(
DB_COINS, it->first), it->second.coins);
68 CCoinsMap::iterator itOld = it++;
69 mapCoins.erase(itOld);
74 LogPrint(
"coindb",
"Committing %u changed transactions (out of %u) to coin database...\n", (
unsigned int)changed, (
unsigned int)
count);
105 boost::scoped_ptr<CDBIterator> pcursor(const_cast<CDBWrapper*>(&
db)->NewIterator());
112 while (pcursor->Valid()) {
113 boost::this_thread::interruption_point();
114 std::pair<char, uint256>
key;
117 if (pcursor->GetValue(coins)) {
119 for (
unsigned int i=0; i<coins.
vout.size(); i++) {
125 nTotalAmount +=
out.nValue;
131 return error(
"CCoinsViewDB::GetStats() : unable to read value");
147 bool CBlockTreeDB::WriteBatchSync(
const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo,
int nLastFile,
const std::vector<const CBlockIndex*>& blockinfo) {
149 for (std::vector<std::pair<int, const CBlockFileInfo*> >::const_iterator it=fileInfo.begin(); it != fileInfo.end(); it++) {
153 for (std::vector<const CBlockIndex*>::const_iterator it=blockinfo.begin(); it != blockinfo.end(); it++) {
165 for (std::vector<std::pair<uint256,CDiskTxPos> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
176 for (std::vector<std::pair<CSpentIndexKey,CSpentIndexValue> >::const_iterator it=vect.begin(); it!=vect.end(); it++) {
177 if (it->second.IsNull()) {
188 for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=vect.begin(); it!=vect.end(); it++) {
189 if (it->second.IsNull()) {
199 std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs) {
201 boost::scoped_ptr<CDBIterator> pcursor(
NewIterator());
205 while (pcursor->Valid()) {
206 boost::this_thread::interruption_point();
207 std::pair<char,CAddressUnspentKey>
key;
210 if (pcursor->GetValue(nValue)) {
211 unspentOutputs.push_back(make_pair(
key.second, nValue));
214 return error(
"failed to get address unspent value");
226 for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
233 for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
239 std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
240 int start,
int end) {
242 boost::scoped_ptr<CDBIterator> pcursor(
NewIterator());
244 if (start > 0 && end > 0) {
250 while (pcursor->Valid()) {
251 boost::this_thread::interruption_point();
252 std::pair<char,CAddressIndexKey>
key;
254 if (end > 0 &&
key.second.blockHeight > end) {
258 if (pcursor->GetValue(nValue)) {
259 addressIndex.push_back(make_pair(
key.second, nValue));
262 return error(
"failed to get address index value");
280 boost::scoped_ptr<CDBIterator> pcursor(
NewIterator());
284 while (pcursor->Valid()) {
285 boost::this_thread::interruption_point();
286 std::pair<char, CTimestampIndexKey>
key;
288 hashes.push_back(
key.second.blockHash);
312 boost::scoped_ptr<CDBIterator> pcursor(
NewIterator());
317 while (pcursor->Valid()) {
318 boost::this_thread::interruption_point();
319 std::pair<char, uint256>
key;
322 if (pcursor->GetValue(diskindex)) {
336 pindexNew->
nTx = diskindex.
nTx;
339 return error(
"%s: CheckProofOfWork failed: %s", __func__, pindexNew->
ToString());
343 return error(
"%s: failed to read value", __func__);
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
static const char DB_LAST_BLOCK
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo)
bool HaveCoins(const uint256 &txid) const
static const char DB_TIMESTAMPINDEX
static const char DB_BEST_BLOCK
CBlockTreeDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
const Consensus::Params & GetConsensus() const
bool ReadAddressUnspentIndex(uint160 addressHash, int type, std::vector< std::pair< CAddressUnspentKey, CAddressUnspentValue > > &vect)
uint64_t nTransactionOutputs
unsigned int nUndoPos
Byte offset within rev?????.dat where this block's undo data is stored.
bool ReadAddressIndex(uint160 addressHash, int type, std::vector< std::pair< CAddressIndexKey, CAmount > > &addressIndex, int start=0, int end=0)
bool WriteTxIndex(const std::vector< std::pair< uint256, CDiskTxPos > > &list)
static const char DB_ADDRESSUNSPENTINDEX
boost::unordered_map< uint256, CCoinsCacheEntry, CCoinsKeyHasher > CCoinsMap
bool WriteFlag(const std::string &name, bool fValue)
std::string ToString() const
bool Write(const K &key, const V &value, bool fSync=false)
static const char DB_ADDRESSINDEX
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
static const char DB_BLOCK_FILES
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
static const char DB_FLAG
static int LogPrint(const char *category, const char *format)
bool ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
static bool error(const char *format)
bool WriteBatch(CDBBatch &batch, bool fSync=false)
void Write(const K &key, const V &value)
bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos)
int nFile
Which # file this block is stored in (blk?????.dat)
bool WriteBatchSync(const std::vector< std::pair< int, const CBlockFileInfo *> > &fileInfo, int nLastFile, const std::vector< const CBlockIndex *> &blockinfo)
uint256 GetBlockHash() const
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
CCoinsViewDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
static const char DB_BLOCK_INDEX
bool WriteTimestampIndex(const CTimestampIndexKey ×tampIndex)
bool GetStats(CCoinsStats &stats) const
Calculate statistics about the unspent transaction output set.
bool UpdateAddressUnspentIndex(const std::vector< std::pair< CAddressUnspentKey, CAddressUnspentValue > > &vect)
bool ReadTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector< uint256 > &vect)
bool EraseAddressIndex(const std::vector< std::pair< CAddressIndexKey, CAmount > > &vect)
bool LoadBlockIndexGuts()
const CChainParams & Params()
static const int PROTOCOL_VERSION
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
bool Exists(const K &key) const
uint256 GetBlockHash() const
bool ReadReindexing(bool &fReindex)
bool ReadLastBlockFile(int &nFile)
bool ReadFlag(const std::string &name, bool &fValue)
CDBIterator * NewIterator()
bool Erase(const K &key, bool fSync=false)
const std::vector< unsigned char > & GetObfuscateKey() const
CBlockIndex * pprev
pointer to the index of the predecessor of this block
bool WriteAddressIndex(const std::vector< std::pair< CAddressIndexKey, CAmount > > &vect)
CBlockIndex * InsertBlockIndex(uint256 hash)
static const char DB_TXINDEX
unsigned int nDataPos
Byte offset within blk?????.dat where this block's data is stored.
static const char DB_REINDEX_FLAG
static const char DB_COINS
int nHeight
height of the entry in the chain. The genesis block has height 0
bool Read(const K &key, V &value) const
bool WriteReindexing(bool fReindex)
bool UpdateSpentIndex(const std::vector< std::pair< CSpentIndexKey, CSpentIndexValue > > &vect)
static const char DB_SPENTINDEX