5 #ifndef BITCOIN_COINS_H
6 #define BITCOIN_COINS_H
15 #include <boost/foreach.hpp>
90 CCoins() : fCoinBase(false), vout(0), nHeight(0), nVersion(0) { }
94 while (vout.size() > 0 && vout.back().IsNull())
97 std::vector<CTxOut>().swap(vout);
101 BOOST_FOREACH(
CTxOut &txout, vout) {
111 std::swap(to.
nHeight, nHeight);
129 void CalcMaskSize(
unsigned int &nBytes,
unsigned int &nNonzeroBytes)
const;
136 unsigned int nSize = 0;
137 unsigned int nMaskSize = 0, nMaskCode = 0;
139 bool fFirst = vout.size() > 0 && !vout[0].IsNull();
140 bool fSecond = vout.size() > 1 && !vout[1].IsNull();
141 assert(fFirst || fSecond || nMaskCode);
142 unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
150 for (
unsigned int i = 0; i < vout.size(); i++)
151 if (!vout[i].IsNull())
158 template<
typename Stream>
159 void Serialize(Stream &s,
int nType,
int nVersion)
const {
160 unsigned int nMaskSize = 0, nMaskCode = 0;
162 bool fFirst = vout.size() > 0 && !vout[0].IsNull();
163 bool fSecond = vout.size() > 1 && !vout[1].IsNull();
164 assert(fFirst || fSecond || nMaskCode);
165 unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
171 for (
unsigned int b = 0; b<nMaskSize; b++) {
172 unsigned char chAvail = 0;
173 for (
unsigned int i = 0; i < 8 && 2+b*8+i < vout.size(); i++)
174 if (!vout[2+b*8+i].IsNull())
179 for (
unsigned int i = 0; i < vout.size(); i++) {
180 if (!vout[i].IsNull())
187 template<
typename Stream>
189 unsigned int nCode = 0;
194 fCoinBase = nCode & 1;
195 std::vector<bool> vAvail(2,
false);
196 vAvail[0] = nCode & 2;
197 vAvail[1] = nCode & 4;
198 unsigned int nMaskCode = (nCode / 8) + ((nCode & 6) != 0 ? 0 : 1);
200 while (nMaskCode > 0) {
201 unsigned char chAvail = 0;
203 for (
unsigned int p = 0; p < 8; p++) {
204 bool f = (chAvail & (1 << p)) != 0;
211 vout.assign(vAvail.size(),
CTxOut());
212 for (
unsigned int i = 0; i < vAvail.size(); i++) {
225 bool Spend(
int nPos);
229 return (nPos < vout.size() && !vout[nPos].IsNull());
235 BOOST_FOREACH(
const CTxOut &out, vout)
253 CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {}
278 virtual bool BatchWrite(
const std::map<uint256, CCoins> &mapCoins,
const uint256 &hashBlock);
302 bool BatchWrite(
const std::map<uint256, CCoins> &mapCoins,
const uint256 &hashBlock);
323 bool BatchWrite(
const std::map<uint256, CCoins> &mapCoins,
const uint256 &hashBlock);
unsigned int GetSerializeSize(int nType, int nVersion) const
uint64_t nTransactionOutputs
void Serialize(Stream &s, int nType, int nVersion) const
void SetBackend(CCoinsView &viewIn)
std::vector< CTxOut > vout
wrapper for CTxOut that provides a more compact serialization
void Unserialize(Stream &s, int nType, int nVersion)
pruned version of CTransaction: only retains metadata and unspent transaction outputs ...
bool GetStats(CCoinsStats &stats)
virtual uint256 GetBestBlock()
Undo information for a CTxIn.
bool GetCoins(const uint256 &txid, CCoins &coins)
bool IsAvailable(unsigned int nPos) const
CCoins(const CTransaction &tx, int nHeightIn)
friend bool operator==(const CCoins &a, const CCoins &b)
virtual bool SetBestBlock(const uint256 &hashBlock)
Abstract view on the open txout dataset.
bool HaveCoins(const uint256 &txid)
An input of a transaction.
virtual bool GetCoins(const uint256 &txid, CCoins &coins)
bool HaveInputs(const CTransaction &tx)
std::map< uint256, CCoins >::iterator FetchCoins(const uint256 &txid)
void CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) const
bool BatchWrite(const std::map< uint256, CCoins > &mapCoins, const uint256 &hashBlock)
bool IsUnspendable() const
const CTxOut & GetOutputFor(const CTxIn &input)
virtual bool HaveCoins(const uint256 &txid)
CCoinsViewCache(CCoinsView &baseIn, bool fDummy=false)
An output of a transaction.
CCoinsViewBacked(CCoinsView &viewIn)
An outpoint - a combination of a transaction hash and an index n into its vout.
virtual bool GetStats(CCoinsStats &stats)
bool SetBestBlock(const uint256 &hashBlock)
bool Spend(const COutPoint &out, CTxInUndo &undo)
double GetPriority(const CTransaction &tx, int nHeight)
virtual bool BatchWrite(const std::map< uint256, CCoins > &mapCoins, const uint256 &hashBlock)
bool SetCoins(const uint256 &txid, const CCoins &coins)
bool HaveCoins(const uint256 &txid)
bool BatchWrite(const std::map< uint256, CCoins > &mapCoins, const uint256 &hashBlock)
int64_t GetValueIn(const CTransaction &tx)
Amount of bitcoins coming in to a transaction Note that lightweight clients may not know anything bes...
bool GetCoins(const uint256 &txid, CCoins &coins)
bool SetCoins(const uint256 &txid, const CCoins &coins)
bool SetBestBlock(const uint256 &hashBlock)
unsigned int GetCacheSize()
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
friend bool operator!=(const CCoins &a, const CCoins &b)
std::map< uint256, CCoins > cacheCoins
virtual bool SetCoins(const uint256 &txid, const CCoins &coins)