8 static const char DB_SAPLING_ANCHOR =
'Z';
9 static const char DB_SAPLING_NULLIFIER =
'S';
10 static const char DB_BEST_SAPLING_ANCHOR =
'z';
20 bool read =
db.
Read(std::make_pair(DB_SAPLING_ANCHOR, rt), tree);
27 return db.
Read(std::make_pair(DB_SAPLING_NULLIFIER, nf), spent);
32 if (!
db.
Read(DB_BEST_SAPLING_ANCHOR, hashBestAnchor))
34 return hashBestAnchor;
41 for (CNullifiersMap::iterator it = mapToUse.begin(); it != mapToUse.end();) {
43 if (!it->second.entered)
44 batch.
Erase(std::make_pair(dbChar, it->first));
46 batch.
Write(std::make_pair(dbChar, it->first),
true);
50 CNullifiersMap::iterator itOld = it++;
51 mapToUse.erase(itOld);
53 LogPrint(
BCLog::COINDB,
"Committed %u changed nullifiers (out of %u) to coin database...\n", (
unsigned int)changed, (
unsigned int)count);
56 template<
typename Map,
typename MapIterator,
typename MapEntry,
typename Tree>
61 for (MapIterator it = mapToUse.begin(); it != mapToUse.end();) {
62 if (it->second.flags & MapEntry::DIRTY) {
63 if (!it->second.entered)
64 batch.
Erase(std::make_pair(dbChar, it->first));
66 if (it->first != Tree::empty_root()) {
67 batch.
Write(std::make_pair(dbChar, it->first), it->second.tree);
73 MapIterator itOld = it++;
74 mapToUse.erase(itOld);
76 LogPrint(
BCLog::COINDB,
"Committed %u changed sapling anchors (out of %u) to coin database...\n", (
unsigned int)changed, (
unsigned int)count);
84 ::BatchWriteAnchors<CAnchorsSaplingMap, CAnchorsSaplingMap::iterator, CAnchorsSaplingCacheEntry, SaplingMerkleTree>(batch, mapSaplingAnchors, DB_SAPLING_ANCHOR);
86 if (!hashSaplingAnchor.
IsNull())
87 batch.
Write(DB_BEST_SAPLING_ANCHOR, hashSaplingAnchor);
uint256 GetBestAnchor() const override
Get the current "tip" or the latest anchored tree root in the chain.
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const override
Retrieve the tree (Sapling) at a particular anchored root in the chain.
bool GetNullifier(const uint256 &nf) const override
Determine whether a nullifier is spent or not.
bool BatchWriteSapling(const uint256 &hashSaplingAnchor, CAnchorsSaplingMap &mapSaplingAnchors, CNullifiersMap &mapSaplingNullifiers, CDBBatch &batch)
Batch of changes queued to be written to a CDBWrapper.
void Write(const K &key, const V &value)
bool Read(const K &key, V &value) const
static libzcash::PedersenHash empty_root()
std::unordered_map< uint256, CAnchorsSaplingCacheEntry, SaltedIdHasher > CAnchorsSaplingMap
std::unordered_map< uint256, CNullifiersCacheEntry, SaltedIdHasher > CNullifiersMap
#define LogPrint(category,...)
void BatchWriteNullifiers(CDBBatch &batch, CNullifiersMap &mapToUse, const char &dbChar)
void BatchWriteAnchors(CDBBatch &batch, Map &mapToUse, const char &dbChar)