6 #ifndef BITCOIN_COINS_H 7 #define BITCOIN_COINS_H 18 #include <boost/foreach.hpp> 19 #include <boost/unordered_map.hpp> 114 while (
vout.size() > 0 &&
vout.back().IsNull())
117 std::vector<CTxOut>().swap(
vout);
149 void CalcMaskSize(
unsigned int &nBytes,
unsigned int &nNonzeroBytes)
const;
156 unsigned int nSize = 0;
157 unsigned int nMaskSize = 0, nMaskCode = 0;
159 bool fFirst =
vout.size() > 0 && !
vout[0].IsNull();
160 bool fSecond =
vout.size() > 1 && !
vout[1].IsNull();
161 assert(fFirst || fSecond || nMaskCode);
162 unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (
fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
170 for (
unsigned int i = 0; i <
vout.size(); i++)
171 if (!
vout[i].IsNull())
178 template<
typename Stream>
180 unsigned int nMaskSize = 0, nMaskCode = 0;
182 bool fFirst =
vout.size() > 0 && !
vout[0].IsNull();
183 bool fSecond =
vout.size() > 1 && !
vout[1].IsNull();
184 assert(fFirst || fSecond || nMaskCode);
185 unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (
fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
191 for (
unsigned int b = 0; b<nMaskSize; b++) {
192 unsigned char chAvail = 0;
193 for (
unsigned int i = 0; i < 8 && 2+b*8+i <
vout.size(); i++)
194 if (!
vout[2+b*8+i].IsNull())
199 for (
unsigned int i = 0; i <
vout.size(); i++) {
200 if (!
vout[i].IsNull())
207 template<
typename Stream>
209 unsigned int nCode = 0;
215 std::vector<bool> vAvail(2,
false);
216 vAvail[0] = (nCode & 2) != 0;
217 vAvail[1] = (nCode & 4) != 0;
218 unsigned int nMaskCode = (nCode / 8) + ((nCode & 6) != 0 ? 0 : 1);
220 while (nMaskCode > 0) {
221 unsigned char chAvail = 0;
223 for (
unsigned int p = 0;
p < 8;
p++) {
224 bool f = (chAvail & (1 <<
p)) != 0;
232 for (
unsigned int i = 0; i < vAvail.size(); i++) {
242 bool Spend(uint32_t nPos);
246 return (nPos <
vout.size() && !
vout[nPos].IsNull());
298 typedef boost::unordered_map<uint256, CCoinsCacheEntry, CCoinsKeyHasher>
CCoinsMap;
368 CCoinsMap::iterator
it;
493 #endif // BITCOIN_COINS_H
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
friend bool operator==(const CCoins &a, const CCoins &b)
equality test
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
unsigned int GetSerializeSize(int nType, int nVersion) const
bool GetStats(CCoinsStats &stats) const
Calculate statistics about the unspent transaction output set.
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
static size_t DynamicUsage(const int8_t &v)
CCoinsModifier(CCoinsViewCache &cache_, CCoinsMap::iterator it_, size_t usage)
uint64_t nTransactionOutputs
bool IsAvailable(unsigned int nPos) const
check whether a particular output is still available
bool fCoinBase
whether transaction is a coinbase
void FromTx(const CTransaction &tx, int nHeightIn)
void Unserialize(Stream &s, int nType, int nVersion)
boost::unordered_map< uint256, CCoinsCacheEntry, CCoinsKeyHasher > CCoinsMap
bool HaveCoins(const uint256 &txid) const
const CTxOut & GetOutputFor(const CTxIn &input) const
virtual ~CCoinsView()
As we use CCoinsViews polymorphically, have a virtual destructor.
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
void Serialize(Stream &s, int nType, int nVersion) const
CCoinsMap::iterator FetchCoins(const uint256 &txid)
void Cleanup()
remove spent outputs at the end of vout
size_t DynamicMemoryUsage() const
virtual bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
virtual bool GetStats(CCoinsStats &stats) const
Calculate statistics about the unspent transaction output set.
CCoins(const CTransaction &tx, int nHeightIn)
construct a CCoins from a CTransaction, at a given height
bool IsUnspendable() const
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
bool Spend(uint32_t nPos)
mark a vout spent
CCoinsViewCache(CCoinsView *baseIn)
void SetBackend(CCoinsView &viewIn)
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
virtual bool HaveCoins(const uint256 &txid) const
void SetBestBlock(const uint256 &hashBlock)
CCoinsModifier ModifyCoins(const uint256 &txid)
friend bool operator!=(const CCoins &a, const CCoins &b)
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
void Uncache(const uint256 &txid)
CCoins()
empty constructor
CCoinsViewBacked(CCoinsView *viewIn)
size_t operator()(const uint256 &key) const
bool HaveCoinsInCache(const uint256 &txid) const
double GetPriority(const CTransaction &tx, int nHeight, CAmount &inChainInputValue) const
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transactions)
bool HaveCoins(const uint256 &txid) const
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
const std::vector< CTxOut > vout
void CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) const
static size_t RecursiveDynamicUsage(const CScript &script)
CCoinsModifier ModifyNewCoins(const uint256 &txid)
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
CAmount GetValueIn(const CTransaction &tx) const
int nHeight
at which height this transaction was included in the active block chain
const CCoins * AccessCoins(const uint256 &txid) const