 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
16 #include <boost/thread.hpp>
18 static const char DB_COINS =
'c';
19 static const char DB_BLOCK_FILES =
'f';
20 static const char DB_TXINDEX =
't';
21 static const char DB_BLOCK_INDEX =
'b';
23 static const char DB_BEST_BLOCK =
'B';
24 static const char DB_FLAG =
'F';
25 static const char DB_REINDEX_FLAG =
'R';
26 static const char DB_LAST_BLOCK =
'l';
27 static const char DB_INT =
'I';
28 static const char DB_KEYIMAGE =
'k';
37 return db.
Read(std::make_pair(DB_COINS, txid), coins);
42 return db.
Exists(std::make_pair(DB_COINS, txid));
48 if (!
db.
Read(DB_BEST_BLOCK, hashBestChain))
58 for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
60 if (it->second.coins.IsPruned())
61 batch.
Erase(std::make_pair(DB_COINS, it->first));
63 batch.
Write(std::make_pair(DB_COINS, it->first), it->second.coins);
67 CCoinsMap::iterator itOld = it++;
68 mapCoins.erase(itOld);
71 batch.
Write(DB_BEST_BLOCK, hashBlock);
73 LogPrint(
BCLog::COINDB,
"Committing %u changed transactions (out of %u) to coin database...\n", (
unsigned int)changed, (
unsigned int)count);
83 return Write(std::make_pair(DB_BLOCK_INDEX, blockindex.
GetBlockHash()), blockindex);
89 return Read(std::make_pair(DB_BLOCK_FILES, nFile), info);
95 return Write(DB_REINDEX_FLAG,
'1');
97 return Erase(DB_REINDEX_FLAG);
102 fReindexing =
Exists(DB_REINDEX_FLAG);
108 return Read(DB_LAST_BLOCK, nFile);
116 boost::scoped_ptr<CDBIterator> pcursor(
const_cast<CDBWrapper*
>(&
db)->NewIterator());
117 pcursor->Seek(DB_COINS);
123 while (pcursor->Valid()) {
124 boost::this_thread::interruption_point();
125 std::pair<char, uint256>
key;
127 if (pcursor->GetKey(
key) &&
key.first == DB_COINS) {
128 if (pcursor->GetValue(coins)) {
130 for (
unsigned int i = 0; i < coins.
vout.size(); i++) {
136 nTotalAmount += out.
nValue;
142 return error(
"CCoinsViewDB::GetStats() : unable to read value");
156 bool CBlockTreeDB::WriteBatchSync(
const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo,
int nLastFile,
const std::vector<const CBlockIndex*>& blockinfo) {
158 for (std::vector<std::pair<int, const CBlockFileInfo*> >::const_iterator it=fileInfo.begin(); it != fileInfo.end(); it++) {
159 batch.
Write(std::make_pair(DB_BLOCK_FILES, it->first), *it->second);
161 batch.
Write(DB_LAST_BLOCK, nLastFile);
162 for (std::vector<const CBlockIndex*>::const_iterator it=blockinfo.begin(); it != blockinfo.end(); it++) {
170 return Read(std::make_pair(DB_TXINDEX, txid), pos);
176 for (std::vector<std::pair<uint256, CDiskTxPos> >::const_iterator it = vect.begin(); it != vect.end(); it++) {
177 batch.
Write(std::make_pair(DB_TXINDEX, it->first), it->second);
185 return Read(std::make_pair(DB_KEYIMAGE, keyImage), bh);
191 if (!
Read(std::make_pair(DB_KEYIMAGE, keyImage), bh))
return false;
205 return Write(std::make_pair(DB_KEYIMAGE, keyImage), bh);
208 while (
ReadKeyImage(keyImage + std::to_string(i), blockHash)) {
211 return Write(std::make_pair(DB_KEYIMAGE, keyImage + std::to_string(i)), bh);
216 return Write(std::make_pair(DB_FLAG,
name), fValue ?
'1' :
'0');
222 if (!
Read(std::make_pair(DB_FLAG,
name), ch))
230 return Write(std::make_pair(DB_INT,
name), nValue);
235 return Read(std::make_pair(DB_INT,
name), nValue);
240 boost::scoped_ptr<CDBIterator> pcursor(
NewIterator());
242 pcursor->Seek(std::make_pair(DB_BLOCK_INDEX,
UINT256_ZERO));
246 while (pcursor->Valid()) {
247 boost::this_thread::interruption_point();
248 std::pair<char, uint256>
key;
249 if (pcursor->GetKey(
key) &&
key.first == DB_BLOCK_INDEX) {
251 if (pcursor->GetValue(diskindex)) {
266 pindexNew->
nTx = diskindex.
nTx;
284 return error(
"LoadBlockIndex() : CheckProofOfWork failed: %s", pindexNew->
ToString());
294 return error(
"%s : failed to read value", __func__);
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
CBlockIndex * pnext
pointer to the index of the next block
const uint256 UINT256_ZERO
constant uint256 instances
bool WriteInt(const std::string &name, int nValue)
int nFile
Which # file this block is stored in (blk?????.dat)
bool GetStats(CCoinsStats &stats) const
Calculate statistics about the unspent transaction output set.
Batch of changes queued to be written to a CDBWrapper.
unsigned int nTx
Number of transactions in this block.
bool LoadBlockIndexGuts()
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int nHeight
height of the entry in the chain. The genesis block has height 0
std::string ToString() const
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
bool Read(const K &key, V &value) const
unsigned int nDataPos
Byte offset within blk?????.dat where this block's data is stored.
Used to marshal pointers into hashes for db storage.
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
bool ReadReindexing(bool &fReindex)
void Write(const K &key, const V &value)
RecursiveMutex cs_main
Global state.
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
CDBIterator * NewIterator()
bool WriteBlockIndex(const CDiskBlockIndex &blockindex)
An output of a transaction.
bool HaveCoins(const uint256 &txid) const
Just check whether we have data for a given txid.
bool WriteBatchSync(const std::vector< std::pair< int, const CBlockFileInfo * > > &fileInfo, int nLastFile, const std::vector< const CBlockIndex * > &blockinfo)
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo)
int64_t CAmount
Amount in PRCY (Can be negative)
256-bit unsigned big integer.
bool ReadFlag(const std::string &name, bool &fValue)
bool Erase(const K &key, bool fSync=false)
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
#define LogPrint(category,...)
CCoinsViewDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
bool CheckProofOfWork(uint256 hash, unsigned int nBits)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
uint256 GetBlockHash() const
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple CCoins changes + BestBlock change).
bool ReadInt(const std::string &name, int &nValue)
uint256 nAccumulatorCheckpoint
bool WriteTxIndex(const std::vector< std::pair< uint256, CDiskTxPos > > &list)
bool WriteReindexing(bool fReindex)
bool WriteFlag(const std::string &name, bool fValue)
bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos)
uint64_t nTransactionOutputs
unsigned int nUndoPos
Byte offset within rev?????.dat where this block's undo data is stored.
A writer stream (for serialization) that computes a 256-bit hash.
const fs::path & GetDataDir(bool fNetSpecific)
CBlockTreeDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
const CChainParams & Params()
Return the currently selected parameters.
boost::unordered_map< uint256, CCoinsCacheEntry, CCoinsKeyHasher > CCoinsMap
CBlockIndex * InsertBlockIndex(uint256 hash)
Create a new block index entry for a given block hash.
uint256 hashPoAMerkleRoot
PoA block header.
uint256 GetBlockHash() const
bool Write(const K &key, const V &value, bool fSync=false)
bool Exists(const K &key) const
bool ReadKeyImages(const std::string &keyImage, std::vector< uint256 > &bhs)
The block chain is a tree shaped structure starting with the genesis block at the root,...
bool WriteBatch(CDBBatch &batch, bool fSync=false)
bool WriteKeyImage(const std::string &keyImage, const uint256 &height)
bool error(const char *fmt, const Args &... args)
bool ReadKeyImage(const std::string &keyImage, uint256 &bh)
bool ReadLastBlockFile(int &nFile)