比特币源码阅读(交易-COutPoint)

【比特币源码阅读(交易-COutPoint)】文档:https://en.bitcoin.it/wiki/Protocol_documentation
交易的输入是另外一笔交易的输出,它的结构如下图: 比特币源码阅读(交易-COutPoint)
文章图片
outpoint.png 对应的源码: src/primitives/transaction.h

/** An outpoint - a combination of a transaction hash and an index n into its vout */ class COutPoint { public: uint256 hash; //out所在交易的hash uint32_t n; //所在索引COutPoint(): n((uint32_t) -1) { } COutPoint(const uint256& hashIn, uint32_t nIn): hash(hashIn), n(nIn) { }ADD_SERIALIZE_METHODS; //序列化template inline void SerializationOp(Stream& s, Operation ser_action) { READWRITE(hash); READWRITE(n); }void SetNull() { hash.SetNull(); n = (uint32_t) -1; } //重置 bool IsNull() const { return (hash.IsNull() && n == (uint32_t) -1); }friend bool operator<(const COutPoint& a, const COutPoint& b) //小于 { int cmp = a.hash.Compare(b.hash); //这里hash判断大小有意义么? return cmp < 0 || (cmp == 0 && a.n < b.n); }friend bool operator==(const COutPoint& a, const COutPoint& b)//相等的条件 { return (a.hash == b.hash && a.n == b.n); }friend bool operator!=(const COutPoint& a, const COutPoint& b) //不相等的条件 { return !(a == b); }std::string ToString() const; };

    推荐阅读