Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.cpp
Show All 29 Lines | |||||
struct CoinEntry { | struct CoinEntry { | ||||
COutPoint *outpoint; | COutPoint *outpoint; | ||||
char key; | char key; | ||||
CoinEntry(const COutPoint *ptr) | CoinEntry(const COutPoint *ptr) | ||||
: outpoint(const_cast<COutPoint *>(ptr)), key(DB_COIN) {} | : outpoint(const_cast<COutPoint *>(ptr)), key(DB_COIN) {} | ||||
template <typename Stream> void Serialize(Stream &s) const { | template <typename Stream> void Serialize(Stream &s) const { | ||||
s << key; | s << key; | ||||
s << outpoint->hash; | s << outpoint->unspentid; | ||||
s << VARINT(outpoint->n); | s << VARINT(outpoint->n); | ||||
} | } | ||||
template <typename Stream> void Unserialize(Stream &s) { | template <typename Stream> void Unserialize(Stream &s) { | ||||
s >> key; | s >> key; | ||||
s >> outpoint->hash; | s >> outpoint->unspentid; | ||||
s >> VARINT(outpoint->n); | s >> VARINT(outpoint->n); | ||||
} | } | ||||
}; | }; | ||||
} | } | ||||
CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) | CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) | ||||
: db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe, true) {} | : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe, true) {} | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | for (std::vector<const CBlockIndex *>::const_iterator it = | ||||
blockinfo.begin(); | blockinfo.begin(); | ||||
it != blockinfo.end(); it++) { | it != blockinfo.end(); it++) { | ||||
batch.Write(std::make_pair(DB_BLOCK_INDEX, (*it)->GetBlockHash()), | batch.Write(std::make_pair(DB_BLOCK_INDEX, (*it)->GetBlockHash()), | ||||
CDiskBlockIndex(*it)); | CDiskBlockIndex(*it)); | ||||
} | } | ||||
return WriteBatch(batch, true); | return WriteBatch(batch, true); | ||||
} | } | ||||
bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) { | bool CBlockTreeDB::ReadTxIndex(const txhash_t &txhash, CDiskTxPos &pos) { | ||||
return Read(std::make_pair(DB_TXINDEX, txid), pos); | return Read(std::make_pair(DB_TXINDEX, txhash), pos); | ||||
} | } | ||||
bool CBlockTreeDB::WriteTxIndex( | bool CBlockTreeDB::WriteTxIndex( | ||||
const std::vector<std::pair<uint256, CDiskTxPos>> &vect) { | const std::vector<std::pair<txhash_t, CDiskTxPos>> &vect) { | ||||
CDBBatch batch(*this); | CDBBatch batch(*this); | ||||
for (std::vector<std::pair<uint256, CDiskTxPos>>::const_iterator it = | for (std::vector<std::pair<txhash_t, CDiskTxPos>>::const_iterator it = | ||||
vect.begin(); | vect.begin(); | ||||
it != vect.end(); it++) | it != vect.end(); it++) | ||||
batch.Write(std::make_pair(DB_TXINDEX, it->first), it->second); | batch.Write(std::make_pair(DB_TXINDEX, it->first), it->second); | ||||
return WriteBatch(batch); | return WriteBatch(batch); | ||||
} | } | ||||
bool CBlockTreeDB::WriteFlag(const std::string &name, bool fValue) { | bool CBlockTreeDB::WriteFlag(const std::string &name, bool fValue) { | ||||
return Write(std::make_pair(DB_FLAG, name), fValue ? '1' : '0'); | return Write(std::make_pair(DB_FLAG, name), fValue ? '1' : '0'); | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | if (!pcursor->Valid()) { | ||||
return true; | return true; | ||||
} | } | ||||
LogPrintf("Upgrading database...\n"); | LogPrintf("Upgrading database...\n"); | ||||
size_t batch_size = 1 << 24; | size_t batch_size = 1 << 24; | ||||
CDBBatch batch(db); | CDBBatch batch(db); | ||||
while (pcursor->Valid()) { | while (pcursor->Valid()) { | ||||
boost::this_thread::interruption_point(); | boost::this_thread::interruption_point(); | ||||
std::pair<uint8_t, uint256> key; | std::pair<uint8_t, unspentid_t> key; | ||||
if (!pcursor->GetKey(key) || key.first != DB_COINS) { | if (!pcursor->GetKey(key) || key.first != DB_COINS) { | ||||
break; | break; | ||||
} | } | ||||
CCoins old_coins; | CCoins old_coins; | ||||
if (!pcursor->GetValue(old_coins)) { | if (!pcursor->GetValue(old_coins)) { | ||||
return error("%s: cannot parse CCoins record", __func__); | return error("%s: cannot parse CCoins record", __func__); | ||||
} | } | ||||
Show All 25 Lines |