Dash Core  0.12.2.1
P2P Digital Currency
CCoins Class Reference

#include <coins.h>

Public Member Functions

void FromTx (const CTransaction &tx, int nHeightIn)
 
 CCoins (const CTransaction &tx, int nHeightIn)
 construct a CCoins from a CTransaction, at a given height More...
 
void Clear ()
 
 CCoins ()
 empty constructor More...
 
void Cleanup ()
 remove spent outputs at the end of vout More...
 
void ClearUnspendable ()
 
void swap (CCoins &to)
 
void CalcMaskSize (unsigned int &nBytes, unsigned int &nNonzeroBytes) const
 
bool IsCoinBase () const
 
unsigned int GetSerializeSize (int nType, int nVersion) const
 
template<typename Stream >
void Serialize (Stream &s, int nType, int nVersion) const
 
template<typename Stream >
void Unserialize (Stream &s, int nType, int nVersion)
 
bool Spend (uint32_t nPos)
 mark a vout spent More...
 
bool IsAvailable (unsigned int nPos) const
 check whether a particular output is still available More...
 
bool IsPruned () const
 
size_t DynamicMemoryUsage () const
 

Public Attributes

bool fCoinBase
 whether transaction is a coinbase More...
 
std::vector< CTxOutvout
 unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are dropped More...
 
int nHeight
 at which height this transaction was included in the active block chain More...
 
int nVersion
 

Friends

bool operator== (const CCoins &a, const CCoins &b)
 equality test More...
 
bool operator!= (const CCoins &a, const CCoins &b)
 

Detailed Description

Pruned version of CTransaction: only retains metadata and unspent transaction outputs

Serialized format:

The nCode value consists of:

  • bit 0: IsCoinBase()
  • bit 1: vout[0] is not spent
  • bit 2: vout[1] is not spent
  • The higher bits encode N, the number of non-zero bytes in the following bitvector.
    • In case both bit 1 and bit 2 are unset, they encode N-1, as there must be at least one non-spent output).

Example: 0104835800816115944e077fe7c803cfa57f29b36bf87c1d358bb85e <><><-----------------------------------------—><-—> | \ | / version code vout[1] height

  • version = 1
  • code = 4 (vout[1] is not spent, and 0 non-zero bytes of bitvector follow)
  • unspentness bitvector: as 0 non-zero bytes follow, it has length 0
  • vout[1]: 835800816115944e077fe7c803cfa57f29b36bf87c1d35
    • 8358: compact amount representation for 60000000000 (600 BTC)
    • 00: special txout type pay-to-pubkey-hash
    • 816115944e077fe7c803cfa57f29b36bf87c1d35: address uint160
  • height = 203998

Example: 0109044086ef97d5790061b01caab50f1b8e9c50a5057eb43c2d9563a4eebbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa486af3b <><><–><-----------------------------------------------—><-------------------------------------------—><-—> / \ \ | | / version code unspentness vout[4] vout[16] height

  • version = 1
  • code = 9 (coinbase, neither vout[0] or vout[1] are unspent, 2 (1, +1 because both bit 1 and bit 2 are unset) non-zero bitvector bytes follow)
  • unspentness bitvector: bits 2 (0x04) and 14 (0x4000) are set, so vout[2+2] and vout[14+2] are unspent
  • vout[4]: 86ef97d5790061b01caab50f1b8e9c50a5057eb43c2d9563a4ee
    • 86ef97d579: compact amount representation for 234925952 (2.35 BTC)
    • 00: special txout type pay-to-pubkey-hash
    • 61b01caab50f1b8e9c50a5057eb43c2d9563a4ee: address uint160
  • vout[16]: bbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa4
    • bbd123: compact amount representation for 110397 (0.001 BTC)
    • 00: special txout type pay-to-pubkey-hash
    • 8c988f1a4a4de2161e0f50aac7f17e7f9555caa4: address uint160
  • height = 120891

Definition at line 73 of file coins.h.

Constructor & Destructor Documentation

◆ CCoins() [1/2]

CCoins::CCoins ( const CTransaction tx,
int  nHeightIn 
)
inline

construct a CCoins from a CTransaction, at a given height

Definition at line 98 of file coins.h.

◆ CCoins() [2/2]

CCoins::CCoins ( )
inline

empty constructor

Definition at line 110 of file coins.h.

Member Function Documentation

◆ CalcMaskSize()

void CCoins::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 represents the availability of one output, but the availabilities of the first two outputs are encoded separately

Definition at line 17 of file coins.cpp.

Referenced by GetSerializeSize(), and Serialize().

◆ Cleanup()

void CCoins::Cleanup ( )
inline

remove spent outputs at the end of vout

Definition at line 113 of file coins.h.

Referenced by ClearUnspendable(), Spend(), and Unserialize().

◆ Clear()

void CCoins::Clear ( )
inline

Definition at line 102 of file coins.h.

Referenced by ApplyTxInUndo(), and DisconnectBlock().

◆ ClearUnspendable()

void CCoins::ClearUnspendable ( )
inline

Definition at line 120 of file coins.h.

Referenced by DisconnectBlock(), and FromTx().

◆ DynamicMemoryUsage()

size_t CCoins::DynamicMemoryUsage ( ) const
inline

Definition at line 258 of file coins.h.

Referenced by CCoinsViewCache::BatchWrite().

◆ FromTx()

void CCoins::FromTx ( const CTransaction tx,
int  nHeightIn 
)
inline

Definition at line 89 of file coins.h.

Referenced by CCoins().

◆ GetSerializeSize()

unsigned int CCoins::GetSerializeSize ( int  nType,
int  nVersion 
) const
inline

Definition at line 155 of file coins.h.

◆ IsAvailable()

bool CCoins::IsAvailable ( unsigned int  nPos) const
inline

◆ IsCoinBase()

bool CCoins::IsCoinBase ( ) const
inline

◆ IsPruned()

bool CCoins::IsPruned ( ) const
inline

check whether the entire CCoins is spent note that only !IsPruned() CCoins can be serialized

Definition at line 251 of file coins.h.

Referenced by ApplyTxInUndo(), ConnectBlock(), and CCoinsViewMemPool::GetCoins().

◆ Serialize()

template<typename Stream >
void CCoins::Serialize ( Stream &  s,
int  nType,
int  nVersion 
) const
inline

Definition at line 179 of file coins.h.

◆ Spend()

bool CCoins::Spend ( uint32_t  nPos)

mark a vout spent

Definition at line 35 of file coins.cpp.

Referenced by CTxMemPool::pruneSpent(), and UpdateCoins().

◆ swap()

void CCoins::swap ( CCoins to)
inline

Definition at line 128 of file coins.h.

Referenced by CCoinsViewCache::BatchWrite(), Clear(), and CCoinsViewCache::FetchCoins().

◆ Unserialize()

template<typename Stream >
void CCoins::Unserialize ( Stream &  s,
int  nType,
int  nVersion 
)
inline

Definition at line 208 of file coins.h.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const CCoins a,
const CCoins b 
)
friend

Definition at line 145 of file coins.h.

◆ operator==

bool operator== ( const CCoins a,
const CCoins b 
)
friend

equality test

Definition at line 136 of file coins.h.

Member Data Documentation

◆ fCoinBase

bool CCoins::fCoinBase

whether transaction is a coinbase

Definition at line 77 of file coins.h.

Referenced by ApplyTxInUndo(), Clear(), FromTx(), GetSerializeSize(), gettxout(), IsCoinBase(), Serialize(), swap(), Unserialize(), and UpdateCoins().

◆ nHeight

◆ nVersion

int CCoins::nVersion

version of the CTransaction; accesses to this value should probably check for nHeight as well, as new tx version will probably only be introduced at certain heights

Definition at line 87 of file coins.h.

Referenced by ApplyTxInUndo(), Clear(), DisconnectBlock(), FromTx(), GetSerializeSize(), gettxout(), rest_getutxos(), Serialize(), swap(), Unserialize(), and UpdateCoins().

◆ vout


The documentation for this class was generated from the following files: