Esempio n. 1
0
        protected byte[] SerializeHeader(Span <byte> coinbaseHash, uint nTime, uint nonce, uint?versionMask, uint?versionBits)
        {
            // build merkle-root
            var merkleRoot = mt.WithFirst(coinbaseHash.ToArray());

            // Build version
            var version = BlockTemplate.Version;

            // Overt-ASIC boost
            if (versionMask.HasValue && versionBits.HasValue)
            {
                version = (version & ~versionMask.Value) | (versionBits.Value & versionMask.Value);
            }

#pragma warning disable 618
            var blockHeader = new BlockHeader
#pragma warning restore 618
            {
                Version        = unchecked ((int)version),
                Bits           = new Target(Encoders.Hex.DecodeData(BlockTemplate.Bits)),
                HashPrevBlock  = uint256.Parse(BlockTemplate.PreviousBlockhash),
                HashMerkleRoot = new uint256(merkleRoot),
                BlockTime      = DateTimeOffset.FromUnixTimeSeconds(nTime),
                Nonce          = nonce
            };

            return(blockHeader.ToBytes());
        }
Esempio n. 2
0
        protected virtual byte[] SerializeHeader(byte[] coinbaseHash, uint nTime, uint nonce)
        {
            var merkleRoot = mt.WithFirst(coinbaseHash);

#pragma warning disable 618
            var blockHeader = new BlockHeader
#pragma warning restore 618
            {
                Version        = (int)BlockTemplate.Version,
                Bits           = new Target(Encoders.Hex.DecodeData(BlockTemplate.Bits)),
                HashPrevBlock  = uint256.Parse(BlockTemplate.PreviousBlockhash),
                HashMerkleRoot = new uint256(merkleRoot),
                BlockTime      = DateTimeOffset.FromUnixTimeSeconds(nTime),
                Nonce          = nonce
            };

            return(blockHeader.ToBytes());
        }