Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.cpp
Show All 35 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->GetTxId(); | ||||
s << VARINT(outpoint->n); | s << VARINT(outpoint->GetN()); | ||||
} | } | ||||
template <typename Stream> void Unserialize(Stream &s) { | template <typename Stream> void Unserialize(Stream &s) { | ||||
s >> key; | s >> key; | ||||
s >> outpoint->hash; | uint256 id; | ||||
s >> VARINT(outpoint->n); | s >> id; | ||||
uint32_t n; | |||||
s >> VARINT(n); | |||||
*outpoint = COutPoint(id, n); | |||||
} | } | ||||
}; | }; | ||||
} // namespace | } // namespace | ||||
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) {} | ||||
bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const { | bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const { | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | while (pcursor->Valid()) { | ||||
} | } | ||||
} | } | ||||
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__); | ||||
} | } | ||||
COutPoint outpoint(key.second, 0); | TxId id(key.second); | ||||
for (size_t i = 0; i < old_coins.vout.size(); ++i) { | for (size_t i = 0; i < old_coins.vout.size(); ++i) { | ||||
if (!old_coins.vout[i].IsNull() && | if (!old_coins.vout[i].IsNull() && | ||||
!old_coins.vout[i].scriptPubKey.IsUnspendable()) { | !old_coins.vout[i].scriptPubKey.IsUnspendable()) { | ||||
Coin newcoin(std::move(old_coins.vout[i]), old_coins.nHeight, | Coin newcoin(std::move(old_coins.vout[i]), old_coins.nHeight, | ||||
old_coins.fCoinBase); | old_coins.fCoinBase); | ||||
outpoint.n = i; | COutPoint outpoint(id, i); | ||||
CoinEntry entry(&outpoint); | CoinEntry entry(&outpoint); | ||||
batch.Write(entry, newcoin); | batch.Write(entry, newcoin); | ||||
} | } | ||||
} | } | ||||
batch.Erase(key); | batch.Erase(key); | ||||
if (batch.SizeEstimate() > batch_size) { | if (batch.SizeEstimate() > batch_size) { | ||||
db.WriteBatch(batch); | db.WriteBatch(batch); | ||||
Show All 14 Lines |