Exemple #1
0
        public void SerializeHeader(Stream stream)
        {
            ContractsCommon.NotNull(stream, "stream");

            Write(stream, Version);
            PreviousBlockHash.Serialize(stream);
            MerkleRoot.Serialize(stream);
            Write(stream, Timestamp);
            Write(stream, DifficultyBits);
            Write(stream, Nonce);
        }
Exemple #2
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = Index.GetHashCode();
         hashCode = (hashCode * 397) ^ PreviousBlockHash.GetHashCode();
         hashCode = (hashCode * 397) ^ Proof.GetHashCode();
         hashCode = (hashCode * 397) ^ Timestamp.GetHashCode();
         hashCode = (hashCode * 397) ^ Transactions.GetHashCode();
         return(hashCode);
     }
 }
Exemple #3
0
 public override bool Equals(object obj)
 {
     return(obj is Block item &&
            Hash.Equals(item.Hash) &&
            Index.Equals(item.Index) &&
            Difficulty.Equals(item.Difficulty) &&
            PreviousBlockHash.Equals(item.PreviousBlockHash) &&
            MinedBy.Equals(item.MinedBy) &&
            Nonce.Equals(item.Nonce) &&
            CreatedOn.Equals(item.CreatedOn) &&
            Transactions.SequenceEqual(item.Transactions));
 }
Exemple #4
0
        /// <summary>
        /// Returns a copy of the block, but without any transactions.
        /// </summary>
        /// <returns></returns>
        public Block cloneAsHeader()
        {
            EnsureParsedHeader();

            return(new Block(Parameters)
            {
                nonce = nonce,
                PreviousBlockHash = PreviousBlockHash.Duplicate(),
                MerkleRoot = MerkleRoot.Duplicate(),
                Version = Version,
                TimeSeconds = TimeSeconds,
                DifficultyTarget = DifficultyTarget,
                Transactions = null,
                hash = Hash.Duplicate()
            });
        }
Exemple #5
0
        private byte[] GetSignatureData()
        {
            var rawBlock = new BlockHeader
            {
                ChainId                      = ChainId?.Clone(),
                Index                        = Index,
                PreviousBlockHash            = PreviousBlockHash?.Clone(),
                MerkleTreeRootOfTransactions = MerkleTreeRootOfTransactions?.Clone(),
                MerkleTreeRootOfWorldState   = MerkleTreeRootOfWorldState?.Clone(),
                Bloom                        = Bloom,
                SideChainBlockHeadersRoot    = SideChainBlockHeadersRoot?.Clone(),
                SideChainTransactionsRoot    = MerkleTreeRootOfTransactions?.Clone()
            };

            if (Index > GlobalConfig.GenesisBlockHeight)
            {
                rawBlock.Time = Time?.Clone();
            }

            return(rawBlock.ToByteArray());
        }