 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
6 #ifndef BITCOIN_COINS_H
7 #define BITCOIN_COINS_H
20 #include <boost/unordered_map.hpp>
114 std::vector<CTxOut>().swap(
vout);
125 while (
vout.size() > 0 &&
vout.back().IsNull())
128 std::vector<CTxOut>().swap(
vout);
134 if (txout.scriptPubKey.IsUnspendable())
166 void CalcMaskSize(
unsigned int& nBytes,
unsigned int& nNonzeroBytes)
const;
180 unsigned int nSize = 0;
181 unsigned int nMaskSize = 0, nMaskCode = 0;
183 bool fFirst =
vout.size() > 0 && !
vout[0].IsNull();
184 bool fSecond =
vout.size() > 1 && !
vout[1].IsNull();
185 assert(fFirst || fSecond || nMaskCode);
186 unsigned int nCode = 8 * (nMaskCode - (fFirst || fSecond ? 0 : 1)) + (
fCoinBase ? 1 : 0) + (
fCoinStake ? 2 : 0) + (fFirst ? 4 : 0) + (fSecond ? 8 : 0);
194 for (
unsigned int i = 0; i <
vout.size(); i++)
195 if (!
vout[i].IsNull())
202 template <
typename Stream>
205 unsigned int nMaskSize = 0, nMaskCode = 0;
207 bool fFirst =
vout.size() > 0 && !
vout[0].IsNull();
208 bool fSecond =
vout.size() > 1 && !
vout[1].IsNull();
209 assert(fFirst || fSecond || nMaskCode);
210 unsigned int nCode = 16 * (nMaskCode - (fFirst || fSecond ? 0 : 1)) + (
fCoinBase ? 1 : 0) + (
fCoinStake ? 2 : 0) + (fFirst ? 4 : 0) + (fSecond ? 8 : 0);
216 for (
unsigned int b = 0;
b < nMaskSize;
b++) {
217 unsigned char chAvail = 0;
218 for (
unsigned int i = 0; i < 8 && 2 +
b * 8 + i <
vout.size(); i++)
219 if (!
vout[2 +
b * 8 + i].IsNull())
224 for (
unsigned int i = 0; i <
vout.size(); i++) {
225 if (!
vout[i].IsNull())
232 template <
typename Stream>
235 unsigned int nCode = 0;
242 std::vector<bool> vAvail(2,
false);
243 vAvail[0] = (nCode & 4) != 0;
244 vAvail[1] = (nCode & 8) != 0;
245 unsigned int nMaskCode = (nCode / 16) + ((nCode & 12) != 0 ? 0 : 1);
247 while (nMaskCode > 0) {
248 unsigned char chAvail = 0;
250 for (
unsigned int p = 0; p < 8; p++) {
251 bool f = (chAvail & (1 << p)) != 0;
259 for (
unsigned int i = 0; i < vAvail.size(); i++) {
272 bool Spend(
int nPos);
277 return (nPos <
vout.size() && !
vout[nPos].IsNull());
291 size_t ret = memusage::DynamicUsage(
vout);
293 ret += memusage::DynamicUsage(*
static_cast<const CScriptBase*
>(&out.scriptPubKey));
330 typedef boost::unordered_map<uint256, CCoinsCacheEntry, CCoinsKeyHasher>
CCoinsMap;
402 CCoinsMap::iterator
it;
480 #endif // BITCOIN_COINS_H
void SetBackend(CCoinsView &viewIn)
An input of a transaction.
size_t operator()(const uint256 &key) const
This must return size_t.
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transactions)
size_t DynamicMemoryUsage() const
CCoinsModifier ModifyCoins(const uint256 &txid)
Return a modifiable reference to a CCoins.
void Cleanup()
remove spent outputs at the end of vout
bool GetStats(CCoinsStats &stats) const
Calculate statistics about the unspent transaction output set.
CCoinsModifier(CCoinsViewCache &cache_, CCoinsMap::iterator it_, size_t usage)
CCoinsViewCache(CCoinsView *baseIn)
const CTxOut & GetOutputFor(const CTxIn &input) const
bool IsAvailable(unsigned int nPos) const
check whether a particular output is still available
void FromTx(const CTransaction &tx, int nHeightIn)
int nHeight
at which height this transaction was included in the active block chain
unsigned int GetSerializeSize(int nType, int nVersion) const
friend bool operator==(const CCoins &a, const CCoins &b)
equality test
@ LOCKTIME_VERIFY_SEQUENCE
The basic transaction that is broadcasted on the network and contained in blocks.
Abstract view on the open txout dataset.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple CCoins changes + BestBlock change).
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple CCoins changes + BestBlock change).
virtual bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
An output of a transaction.
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow, CBlockIndex *blockIndex)
Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock.
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
std::vector< CTxOut > vout
friend bool operator!=(const CCoins &a, const CCoins &b)
A reference to a mutable cache entry.
int64_t CAmount
Amount in PRCY (Can be negative)
bool HaveCoins(const uint256 &txid) const
Just check whether we have data for a given txid.
CCoins()
empty constructor
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
256-bit unsigned big integer.
void Unserialize(Stream &s, int nType, int nVersion)
wrapper for CTxOut that provides a more compact serialization
const CCoins * AccessCoins(const uint256 &txid) const
Return a pointer to CCoins in the cache, or NULL if not found.
CCoinsViewBacked(CCoinsView *viewIn)
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
int nVersion
version of the CTransaction; accesses to this value should probably check for nHeight as well,...
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
@ LOCKTIME_MEDIAN_TIME_PAST
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple CCoins changes + BestBlock change).
CCoinsView that adds a memory cache for transactions to another CCoinsView.
uint64_t nTransactionOutputs
virtual bool GetStats(CCoinsStats &stats) const
Calculate statistics about the unspent transaction output set.
CCoinsView backed by another CCoinsView.
void SetBestBlock(const uint256 &hashBlock)
bool HaveCoins(const uint256 &txid) const
Just check whether we have data for a given txid.
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
boost::unordered_map< uint256, CCoinsCacheEntry, CCoinsKeyHasher > CCoinsMap
Undo information for a CTxIn.
bool fCoinBase
whether transaction is a coinbase
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
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.
bool Spend(const COutPoint &out, CTxInUndo &undo)
mark an outpoint spent, and construct undo information
void Serialize(Stream &s, int nType, int nVersion) const
The block chain is a tree shaped structure starting with the genesis block at the root,...
T & REF(const T &val)
Used to bypass the rule against non-const reference to temporary where it makes sense with wrappers s...
CCoins(const CTransaction &tx, int nHeightIn)
construct a CCoins from a CTransaction, at a given height
virtual bool HaveCoins(const uint256 &txid) const
Just check whether we have data for a given txid.
void CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) const
calculate number of bytes for the bitmask, and its number of non-zero bytes each bit in the bitmask r...
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
CCoinsMap::iterator FetchCoins(const uint256 &txid)
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
virtual ~CCoinsView()
As we use CCoinsViews polymorphically, have a virtual destructor.
bool Flush()
Push the modifications applied to this cache to its base.
bool IsPruned() const
check whether the entire CCoins is spent note that only !IsPruned() CCoins can be serialized