6 #ifndef ANONCOIN_COINS_H
7 #define ANONCOIN_COINS_H
16 #include <boost/foreach.hpp>
91 CCoins() : fCoinBase(false), vout(0), nHeight(0), nVersion(0) { }
95 while (vout.size() > 0 && vout.back().IsNull())
98 std::vector<CTxOut>().swap(vout);
112 std::swap(to.
nHeight, nHeight);
130 void CalcMaskSize(
unsigned int &nBytes,
unsigned int &nNonzeroBytes)
const;
137 unsigned int nSize = 0;
138 unsigned int nMaskSize = 0, nMaskCode = 0;
140 bool fFirst = vout.size() > 0 && !vout[0].IsNull();
141 bool fSecond = vout.size() > 1 && !vout[1].IsNull();
142 assert(fFirst || fSecond || nMaskCode);
143 unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
151 for (
unsigned int i = 0; i < vout.size(); i++)
152 if (!vout[i].IsNull())
159 template<
typename Stream>
160 void Serialize(Stream &s,
int nType,
int nVersion)
const {
161 unsigned int nMaskSize = 0, nMaskCode = 0;
163 bool fFirst = vout.size() > 0 && !vout[0].IsNull();
164 bool fSecond = vout.size() > 1 && !vout[1].IsNull();
165 assert(fFirst || fSecond || nMaskCode);
166 unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
172 for (
unsigned int b = 0; b<nMaskSize; b++) {
173 unsigned char chAvail = 0;
174 for (
unsigned int i = 0; i < 8 && 2+b*8+i < vout.size(); i++)
175 if (!vout[2+b*8+i].IsNull())
180 for (
unsigned int i = 0; i < vout.size(); i++) {
181 if (!vout[i].IsNull())
188 template<
typename Stream>
190 unsigned int nCode = 0;
195 fCoinBase = nCode & 1;
196 std::vector<bool> vAvail(2,
false);
197 vAvail[0] = nCode & 2;
198 vAvail[1] = nCode & 4;
199 unsigned int nMaskCode = (nCode / 8) + ((nCode & 6) != 0 ? 0 : 1);
201 while (nMaskCode > 0) {
202 unsigned char chAvail = 0;
204 for (
unsigned int p = 0; p < 8; p++) {
205 bool f = (chAvail & (1 << p)) != 0;
212 vout.assign(vAvail.size(),
CTxOut());
213 for (
unsigned int i = 0; i < vAvail.size(); i++) {
226 bool Spend(
int nPos);
230 return (nPos < vout.size() && !vout[nPos].IsNull());
236 BOOST_FOREACH(
const CTxOut &out, vout)
254 CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {}
279 virtual bool BatchWrite(
const std::map<uint256, CCoins> &mapCoins,
const uint256 &hashBlock);
303 bool BatchWrite(
const std::map<uint256, CCoins> &mapCoins,
const uint256 &hashBlock);
324 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)
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 anoncoins coming in to a transaction Note that lightweight clients may not know anything be...
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)