Changeset View
Changeset View
Standalone View
Standalone View
src/coins.h
Show First 20 Lines • Show All 518 Lines • ▼ Show 20 Lines | public: | ||||
/** | /** | ||||
* Return a modifiable reference to a CCoins. If no entry with the given | * Return a modifiable reference to a CCoins. If no entry with the given | ||||
* txid exists, a new one is created. Simultaneous modifications are not | * txid exists, a new one is created. Simultaneous modifications are not | ||||
* allowed. | * allowed. | ||||
*/ | */ | ||||
CCoinsModifier ModifyCoins(const uint256 &txid); | CCoinsModifier ModifyCoins(const uint256 &txid); | ||||
/** | /** | ||||
* Return a modifiable reference to a CCoins. Assumes that no entry with the | * Add a coin. Set potential_overwrite to true if a non-pruned version may | ||||
* given txid exists and creates a new one. This saves a database access in | * already exist. | ||||
* the case where the coins were to be wiped out by FromTx anyway. This | |||||
* should not be called with the 2 historical coinbase duplicate pairs | |||||
* because the new coins are marked fresh, and in the event the duplicate | |||||
* coinbase was spent before a flush, the now pruned coins would not | |||||
* properly overwrite the first coinbase of the pair. Simultaneous | |||||
* modifications are not allowed. | |||||
*/ | */ | ||||
CCoinsModifier ModifyNewCoins(const uint256 &txid, bool coinbase); | void AddCoin(const COutPoint &outpoint, const Coin &coin, | ||||
bool potential_overwrite); | |||||
/** | |||||
* Spend a coin. Pass moveto in order to get the deleted data. | |||||
* If no unspent output exists for the passed outpoint, this call has no | |||||
* effect. | |||||
*/ | |||||
bool SpendCoin(const COutPoint &outpoint, Coin *moveto = nullptr); | |||||
/** | /** | ||||
* Push the modifications applied to this cache to its base. | * Push the modifications applied to this cache to its base. | ||||
* Failure to call this method before destruction will cause the changes to | * Failure to call this method before destruction will cause the changes to | ||||
* be forgotten. If false is returned, the state of this cache (and its | * be forgotten. If false is returned, the state of this cache (and its | ||||
* backing view) will be undefined. | * backing view) will be undefined. | ||||
*/ | */ | ||||
bool Flush(); | bool Flush(); | ||||
Show All 32 Lines | public: | ||||
double GetPriority(const CTransaction &tx, int nHeight, | double GetPriority(const CTransaction &tx, int nHeight, | ||||
CAmount &inChainInputValue) const; | CAmount &inChainInputValue) const; | ||||
const CTxOut &GetOutputFor(const CTxIn &input) const; | const CTxOut &GetOutputFor(const CTxIn &input) const; | ||||
friend class CCoinsModifier; | friend class CCoinsModifier; | ||||
private: | private: | ||||
CCoinsMap::const_iterator FetchCoins(const uint256 &txid) const; | CCoinsMap::iterator FetchCoins(const uint256 &txid) const; | ||||
/** | /** | ||||
* By making the copy constructor private, we prevent accidentally using it | * By making the copy constructor private, we prevent accidentally using it | ||||
* when one intends to create a cache on top of a base cache. | * when one intends to create a cache on top of a base cache. | ||||
*/ | */ | ||||
CCoinsViewCache(const CCoinsViewCache &); | CCoinsViewCache(const CCoinsViewCache &); | ||||
}; | }; | ||||
//! Utility function to add all of a transaction's outputs to a cache. | |||||
// It assumes that overwrites are only possible for coinbase transactions. | |||||
// TODO: pass in a boolean to limit these possible overwrites to known | |||||
// (pre-BIP34) cases. | |||||
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight); | |||||
//! Utility function to find any unspent output with a given txid. | //! Utility function to find any unspent output with a given txid. | ||||
const Coin AccessByTxid(const CCoinsViewCache &cache, const uint256 &txid); | const Coin AccessByTxid(const CCoinsViewCache &cache, const uint256 &txid); | ||||
#endif // BITCOIN_COINS_H | #endif // BITCOIN_COINS_H |