Changeset View
Changeset View
Standalone View
Standalone View
src/primitives/transaction.h
Show All 27 Lines | struct TxHash : public uint256 { | ||||
explicit TxHash(const uint256 &b) : uint256(b) {} | explicit TxHash(const uint256 &b) : uint256(b) {} | ||||
}; | }; | ||||
/** | /** | ||||
* An outpoint - a combination of a transaction hash and an index n into its | * An outpoint - a combination of a transaction hash and an index n into its | ||||
* vout. | * vout. | ||||
*/ | */ | ||||
class COutPoint { | class COutPoint { | ||||
public: | private: | ||||
uint256 hash; | uint256 txid; | ||||
uint32_t n; | uint32_t n; | ||||
public: | |||||
COutPoint() { SetNull(); } | COutPoint() { SetNull(); } | ||||
COutPoint(uint256 hashIn, uint32_t nIn) { | COutPoint(uint256 txidIn, uint32_t nIn) { | ||||
hash = hashIn; | txid = txidIn; | ||||
n = nIn; | n = nIn; | ||||
} | } | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(hash); | READWRITE(txid); | ||||
READWRITE(n); | READWRITE(n); | ||||
} | } | ||||
void SetNull() { | void SetNull() { | ||||
hash.SetNull(); | txid.SetNull(); | ||||
n = uint32_t(-1); | n = uint32_t(-1); | ||||
} | } | ||||
bool IsNull() const { return hash.IsNull() && n == uint32_t(-1); } | bool IsNull() const { return txid.IsNull() && n == uint32_t(-1); } | ||||
TxId GetTxId() const { return TxId(hash); } | TxId GetTxId() const { return TxId(txid); } | ||||
uint32_t GetN() const { return n; } | uint32_t GetN() const { return n; } | ||||
friend bool operator<(const COutPoint &a, const COutPoint &b) { | friend bool operator<(const COutPoint &a, const COutPoint &b) { | ||||
int cmp = a.hash.Compare(b.hash); | int cmp = a.txid.Compare(b.txid); | ||||
return cmp < 0 || (cmp == 0 && a.n < b.n); | return cmp < 0 || (cmp == 0 && a.n < b.n); | ||||
} | } | ||||
friend bool operator==(const COutPoint &a, const COutPoint &b) { | friend bool operator==(const COutPoint &a, const COutPoint &b) { | ||||
return (a.hash == b.hash && a.n == b.n); | return (a.txid == b.txid && a.n == b.n); | ||||
} | } | ||||
friend bool operator!=(const COutPoint &a, const COutPoint &b) { | friend bool operator!=(const COutPoint &a, const COutPoint &b) { | ||||
return !(a == b); | return !(a == b); | ||||
} | } | ||||
std::string ToString() const; | std::string ToString() const; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 327 Lines • Show Last 20 Lines |