22 #include <unordered_map>
68 template<
typename Stream>
76 template<
typename Stream>
175 typedef std::unordered_map<uint256, CNullifiersCacheEntry, SaltedIdHasher>
CNullifiersMap;
177 typedef std::unordered_map<COutPoint, CCoinsCacheEntry, SaltedOutpointHasher>
CCoinsMap;
223 const uint256& hashSaplingAnchor,
266 const uint256& hashSaplingAnchor,
278 static const unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS = LOCKTIME_VERIFY_SEQUENCE |
279 LOCKTIME_MEDIAN_TIME_PAST;
420 template<
typename Tree,
typename Cache,
typename CacheEntry>
428 template<
typename Tree,
typename Cache,
typename CacheIterator,
typename CacheEntry>
436 template<
typename Tree>
int64_t CAmount
Amount in PIV (Can be negative)
CCoinsView backed by another CCoinsView.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const uint256 &hashSaplingAnchor, CAnchorsSaplingMap &mapSaplingAnchors, CNullifiersMap &mapSaplingNullifiers) override
Do a bulk modification (multiple Coin changes + BestBlock change).
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether we have data for a given outpoint.
bool GetNullifier(const uint256 &nullifier) const override
Determine whether a nullifier is spent or not.
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
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.
void SetBackend(CCoinsView &viewIn)
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
CCoinsViewBacked(CCoinsView *viewIn)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const uint256 &hashSaplingAnchor, CAnchorsSaplingMap &mapSaplingAnchors, CNullifiersMap &mapSaplingNullifiers) override
Do a bulk modification (multiple Coin changes + BestBlock change).
void SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
uint256 hashSaplingAnchor
CAmount GetValueIn(const CTransaction &tx) const
Amount of pivx coming in to a transaction Note that lightweight clients may not know anything besides...
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
CCoinsViewCache(CCoinsView *baseIn)
CCoinsViewCache(const CCoinsViewCache &)=delete
By deleting the copy constructor, we prevent accidentally using it when one intends to create a cache...
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
void BringBestAnchorIntoCache(const uint256 ¤tRoot, Tree &tree)
Interface for bringing an anchor into the cache.
CAnchorsSaplingMap cacheSaplingAnchors
void SetNullifiers(const CTransaction &tx, bool spent)
void PushAnchor(const Tree &tree)
bool PruneInvalidEntries()
CNullifiersMap cacheSaplingNullifiers
void PopAnchor(const uint256 &rt)
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool potential_overwrite)
Add a coin.
void AbstractPopAnchor(const uint256 &newrt, Cache &cacheAnchors, uint256 &hash)
Generalized interface for popping anchors.
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const override
Retrieve the tree (Sapling) at a particular anchored root in the chain.
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
uint256 GetBestAnchor() const override
Get the current "tip" or the latest anchored tree root in the chain.
void SetBestBlock(const uint256 &hashBlock)
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
bool GetUTXOCoin(const COutPoint &outpoint, Coin &coin) const
Get the coin and check if it's spent.
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
bool GetNullifier(const uint256 &nullifier) const override
Determine whether a nullifier is spent or not.
int GetCoinDepthAtHeight(const COutPoint &output, int nHeight) const
bool Flush()
Push the modifications applied to this cache to its base.
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
bool HaveShieldedRequirements(const CTransaction &tx) const
Check whether all sapling spend requirements (anchors/nullifiers) are satisfied.
CAmount GetTotalAmount() const
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether we have data for a given outpoint.
void AbstractPushAnchor(const Tree &tree, Cache &cacheAnchors, uint256 &hash)
Generalized interface for pushing anchors.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to a Coin in the cache, or a pruned one if not found.
Cursor for iterating over CoinsView state.
virtual bool Valid() const =0
CCoinsViewCursor(const uint256 &hashBlockIn)
virtual unsigned int GetValueSize() const =0
virtual ~CCoinsViewCursor()
virtual bool GetKey(COutPoint &key) const =0
const uint256 & GetBestBlock() const
Get best block at the time this cursor was created.
virtual bool GetValue(Coin &coin) const =0
Abstract view on the open txout dataset.
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const uint256 &hashSaplingAnchor, CAnchorsSaplingMap &mapSaplingAnchors, CNullifiersMap &mapSaplingNullifiers)
Do a bulk modification (multiple Coin changes + BestBlock change).
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
virtual bool GetNullifier(const uint256 &nullifier) const
Determine whether a nullifier is spent or not.
virtual uint256 GetBestAnchor() const
Get the current "tip" or the latest anchored tree root in the chain.
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
virtual std::vector< uint256 > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
virtual bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const
Retrieve the tree (Sapling) at a particular anchored root in the chain.
virtual ~CCoinsView()
As we use CCoinsViews polymorphically, have a virtual destructor.
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether we have data for a given outpoint.
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
An outpoint - a combination of a transaction hash and an index n into its vout.
The basic transaction that is broadcasted on the network and contained in blocks.
An output of a transaction.
Coin(CTxOut &&outIn, int nHeightIn, bool fCoinBaseIn, bool fCoinStakeIn)
construct a Coin from a CTxOut and height/coinbase properties.
void Serialize(Stream &s) const
bool fCoinStake
whether the containing transaction was a coinstake
Coin(const CTxOut &outIn, int nHeightIn, bool fCoinBaseIn, bool fCoinStakeIn)
CTxOut out
unspent transaction output
bool fCoinBase
whether the containing transaction was a coinbase
void Unserialize(Stream &s)
uint32_t nHeight
at which height the containing transaction was included in the active block chain
size_t DynamicMemoryUsage() const
size_t operator()(const uint256 &txid) const
This must return size_t.
size_t operator()(const COutPoint &id) const
This must return size_t.
const Coin & AccessByTxid(const CCoinsViewCache &cache, const uint256 &txid)
Utility function to find any unspent output with a given txid.
std::unordered_map< uint256, CAnchorsSaplingCacheEntry, SaltedIdHasher > CAnchorsSaplingMap
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check=false, bool fSkipInvalid=false)
Utility function to add all of a transaction's outputs to a cache.
std::unordered_map< uint256, CNullifiersCacheEntry, SaltedIdHasher > CNullifiersMap
uint64_t SipHashUint256Extra(uint64_t k0, uint64_t k1, const uint256 &val, uint32_t extra)
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
CAnchorsSaplingCacheEntry()
CCoinsCacheEntry(Coin &&coin_)