美文网首页比特币源码学习笔记
比特币源码阅读(区块-CBlockHeader)

比特币源码阅读(区块-CBlockHeader)

作者: 坠叶飘香 | 来源:发表于2018-07-26 18:26 被阅读0次
    Block Headers

    源码:
    src/primitives/block.h

    class CBlockHeader
    {
    public:
        // header
        int32_t nVersion;
        uint256 hashPrevBlock; //前一个区块的hash
        uint256 hashMerkleRoot;
        uint32_t nTime;
        uint32_t nBits; //难度值
        uint32_t nNonce; //随机数
    
        CBlockHeader()
        {
            SetNull();
        }
    
        ADD_SERIALIZE_METHODS;
    
        template <typename Stream, typename Operation>
        inline void SerializationOp(Stream& s, Operation ser_action) {
            READWRITE(this->nVersion);
            READWRITE(hashPrevBlock);
            READWRITE(hashMerkleRoot);
            READWRITE(nTime);
            READWRITE(nBits);
            READWRITE(nNonce);
        }
    
        void SetNull()
        {
            nVersion = 0;
            hashPrevBlock.SetNull();
            hashMerkleRoot.SetNull();
            nTime = 0;
            nBits = 0;
            nNonce = 0;
        }
    
        bool IsNull() const
        {
            return (nBits == 0);
        }
    
        uint256 GetHash() const;
    
        int64_t GetBlockTime() const
        {
            return (int64_t)nTime;
        }
    };
    

    相关文章

      网友评论

        本文标题:比特币源码阅读(区块-CBlockHeader)

        本文链接:https://www.haomeiwen.com/subject/jrximftx.html