private (int Total, int Logs) GetContentLength(TxReceipt item, RlpBehaviors rlpBehaviors)
        {
            if (item == null)
            {
                return(0, 0);
            }

            int contentLength = 0;

            contentLength += Rlp.LengthOf(item.GasUsedTotal);
            contentLength += Rlp.LengthOf(item.Bloom);

            int logsLength = GetLogsLength(item);

            contentLength += Rlp.LengthOfSequence(logsLength);

            bool isEip658Receipts = (rlpBehaviors & RlpBehaviors.Eip658Receipts) == RlpBehaviors.Eip658Receipts;

            if (!item.SkipStateAndStatusInRlp)
            {
                contentLength += isEip658Receipts
                    ? Rlp.LengthOf(item.StatusCode)
                    : Rlp.LengthOf(item.PostTransactionState);
            }

            return(contentLength, logsLength);
        }
Example #2
0
        public int GetLength(Block item, RlpBehaviors rlpBehaviors)
        {
            if (item == null)
            {
                return(1);
            }

            return(Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors).Total));
        }
Example #3
0
        public int GetLength(Account item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                return(1);
            }

            return(Rlp.LengthOfSequence(GetContentLength(item)));
        }
Example #4
0
        public int GetLength(LogEntry?item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                return(1);
            }

            return(Rlp.LengthOfSequence(GetContentLength(item).Total));
        }
        /// <summary>
        /// https://eips.ethereum.org/EIPS/eip-2718
        /// </summary>
        public int GetLength(TxReceipt item, RlpBehaviors rlpBehaviors)
        {
            (int Total, int Logs)length = GetContentLength(item, rlpBehaviors);
            int receiptPayloadLength = Rlp.LengthOfSequence(length.Total);

            bool isForTxRoot = (rlpBehaviors & RlpBehaviors.SkipTypedWrapping) == RlpBehaviors.SkipTypedWrapping;
            int  result      = item.TxType != TxType.Legacy
                ? isForTxRoot
                    ? (1 + receiptPayloadLength)
                    : Rlp.LengthOfSequence(1 + receiptPayloadLength) // Rlp(TransactionType || TransactionPayload)
                : receiptPayloadLength;

            return(result);
        }
Example #6
0
        public Rlp Encode(Account?item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item is null)
            {
                return(Rlp.OfEmptySequence);
            }

            int       contentLength = GetContentLength(item);
            RlpStream rlpStream     = new(Rlp.LengthOfSequence(contentLength));

            Encode(item, rlpStream, contentLength);

            return(new Rlp(rlpStream.Data));
        }
Example #7
0
        public Rlp Encode(Account item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                return(Rlp.OfEmptySequence);
            }

            int       contentLength = GetContentLength(item);
            RlpStream rlpStream     = new RlpStream(Rlp.LengthOfSequence(contentLength));

            rlpStream.StartSequence(contentLength);
            rlpStream.Encode(item.Nonce);
            rlpStream.Encode(item.Balance);
            rlpStream.Encode(item.StorageRoot);
            rlpStream.Encode(item.CodeHash);
            return(new Rlp(rlpStream.Data));
        }
        public void Encode(RlpStream rlpStream, TxReceipt item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                rlpStream.EncodeNullObject();
                return;
            }

            (int totalContentLength, int logsLength) = GetContentLength(item, rlpBehaviors);
            int sequenceLength = Rlp.LengthOfSequence(totalContentLength);

            bool isEip658Receipts = (rlpBehaviors & RlpBehaviors.Eip658Receipts) == RlpBehaviors.Eip658Receipts;

            if (item.TxType != TxType.Legacy)
            {
                if ((rlpBehaviors & RlpBehaviors.SkipTypedWrapping) == RlpBehaviors.None)
                {
                    rlpStream.StartByteArray(sequenceLength + 1, false);
                }

                rlpStream.WriteByte((byte)item.TxType);
            }

            rlpStream.StartSequence(totalContentLength);
            if (!item.SkipStateAndStatusInRlp)
            {
                if (isEip658Receipts)
                {
                    rlpStream.Encode(item.StatusCode);
                }
                else
                {
                    rlpStream.Encode(item.PostTransactionState);
                }
            }

            rlpStream.Encode(item.GasUsedTotal);
            rlpStream.Encode(item.Bloom);

            rlpStream.StartSequence(logsLength);
            for (var i = 0; i < item.Logs.Length; i++)
            {
                rlpStream.Encode(item.Logs[i]);
            }
        }
Example #9
0
 public int GetLength(TxReceipt item, RlpBehaviors rlpBehaviors)
 {
     return(Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors).Total));
 }
Example #10
0
 public int GetLength(BlockHeader?item, RlpBehaviors rlpBehaviors)
 {
     return(Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors)));
 }