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

文档:https://en.bitcoin.it/wiki/Protocol_documentation

交易的输入是另外一笔交易的输出,它的结构如下图:

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 <typename Stream, typename Operation>
    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;
};
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 这一章讲的比特币的交易记录的细节。通过这一章你可以理解,比特币的交易是采用什么样的组织形式构成的,同时也可以看到,...
    Scalers阅读 2,363评论 1 3
  • 你觉得生活很满意吗? 也许吧! 你觉得对未来很有信心吗? 也许吧! 你觉得周围的人都是善解人意吗?也许吧! 你觉得...
    燕落无痕阅读 189评论 0 0
  • 2018.6.22 阵雨 星期五 五点多妹妹就醒了,自己在那里玩,小手也不老实,一直拍打着我,还没睡醒的我眼睛...
    TianHao妈妈阅读 112评论 0 2
  • 孤独是人生的选择,而非注定的命运!有人把孤独当借口,可以对感情放肆,自私且想着高尚,释怀…… 总会有一个人出现,让...
    如果可以最好不相见阅读 227评论 0 0

友情链接更多精彩内容