示例#1
0
        private static int GetContentLength(BlockHeader?item, RlpBehaviors rlpBehaviors)
        {
            if (item is null)
            {
                return(0);
            }

            bool notForSealing = (rlpBehaviors & RlpBehaviors.ForSealing) != RlpBehaviors.ForSealing;
            int  contentLength = 0
                                 + Rlp.LengthOf(item.ParentHash)
                                 + Rlp.LengthOf(item.UnclesHash)
                                 + Rlp.LengthOf(item.Beneficiary)
                                 + Rlp.LengthOf(item.StateRoot)
                                 + Rlp.LengthOf(item.TxRoot)
                                 + Rlp.LengthOf(item.ReceiptsRoot)
                                 + Rlp.LengthOf(item.Bloom)
                                 + Rlp.LengthOf(item.Difficulty)
                                 + Rlp.LengthOf(item.Number)
                                 + Rlp.LengthOf(item.GasLimit)
                                 + Rlp.LengthOf(item.GasUsed)
                                 + Rlp.LengthOf(item.Timestamp)
                                 + Rlp.LengthOf(item.ExtraData)
                                 + (item.Number < Eip1559TransitionBlock ? 0 : Rlp.LengthOf(item.BaseFeePerGas));

            if (notForSealing)
            {
                bool isAuRa = item.AuRaSignature != null;
                if (isAuRa)
                {
                    contentLength += Rlp.LengthOf(item.AuRaStep !.Value);
                    contentLength += Rlp.LengthOf(item.AuRaSignature);
                }
                else
                {
                    contentLength += Rlp.LengthOf(item.MixHash);
                    contentLength += Rlp.LengthOfNonce(item.Nonce);
                }
            }

            return(contentLength);
        }