コード例 #1
0
        public void Encode(RlpStream rlpStream, TxReceipt item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                rlpStream.EncodeNullObject();
                return;
            }

            var(totalLength, logsLength) = GetContentLength(item, rlpBehaviors);

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

            rlpStream.StartSequence(totalLength);
            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]);
            }
        }
コード例 #2
0
        public void Encode(Account account, RlpStream rlpStream, int?contentLength = null)
        {
            if (contentLength == null)
            {
                contentLength = GetContentLength(account);
            }

            rlpStream.StartSequence(contentLength.Value);
            rlpStream.Encode(account.Nonce);
            rlpStream.Encode(account.Balance);

            if (_slimFormat && !account.HasStorage)
            {
                rlpStream.EncodeEmptyByteArray();
            }
            else
            {
                rlpStream.Encode(account.StorageRoot);
            }

            if (_slimFormat && !account.HasCode)
            {
                rlpStream.EncodeEmptyByteArray();
            }
            else
            {
                rlpStream.Encode(account.CodeHash);
            }
        }
コード例 #3
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));
        }
コード例 #4
0
        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.GetSequenceRlpLength(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]);
            }
        }
コード例 #5
0
        public void Encode(RlpStream stream, Transaction item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            int contentLength = GetContentLength(item, false);

            stream.StartSequence(contentLength);
            stream.Encode(item.Nonce);
            stream.Encode(item.GasPrice);
            stream.Encode(item.GasLimit);
            stream.Encode(item.To);
            stream.Encode(item.Value);
            stream.Encode(item.To == null ? item.Init : item.Data);
            stream.Encode(item.Signature?.V ?? 0);
            stream.Encode(item.Signature == null ? null : item.Signature.RAsSpan.WithoutLeadingZeros());
            stream.Encode(item.Signature == null ? null : item.Signature.SAsSpan.WithoutLeadingZeros());
        }
コード例 #6
0
        public void Encode(RlpStream rlpStream, LogEntry?item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                rlpStream.EncodeNullObject();
                return;
            }

            var(total, topics) = GetContentLength(item);
            rlpStream.StartSequence(total);

            rlpStream.Encode(item.LoggersAddress);
            rlpStream.StartSequence(topics);

            for (var i = 0; i < item.Topics.Length; i++)
            {
                rlpStream.Encode(item.Topics[i]);
            }

            rlpStream.Encode(item.Data);
        }
コード例 #7
0
        public void Encode(RlpStream stream, Block item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                stream.EncodeNullObject();
                return;
            }

            (int contentLength, int txsLength, int ommersLength) = GetContentLength(item, rlpBehaviors);
            stream.StartSequence(contentLength);
            stream.Encode(item.Header);
            stream.StartSequence(txsLength);
            for (int i = 0; i < item.Transactions.Length; i++)
            {
                stream.Encode(item.Transactions[i]);
            }

            stream.StartSequence(ommersLength);
            for (int i = 0; i < item.Ommers.Length; i++)
            {
                stream.Encode(item.Ommers[i]);
            }
        }
コード例 #8
0
        public void Encode(RlpStream rlpStream, TxReceipt item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                rlpStream.EncodeNullObject();
                return;
            }

            var(totalLength, logsLength) = GetContentLength(item, rlpBehaviors);

            bool isStorage        = (rlpBehaviors & RlpBehaviors.Storage) != 0;
            bool isEip658receipts = (rlpBehaviors & RlpBehaviors.Eip658Receipts) == RlpBehaviors.Eip658Receipts;

            rlpStream.StartSequence(totalLength);
            if (isEip658receipts)
            {
                rlpStream.Encode(item.StatusCode);
            }
            else
            {
                rlpStream.Encode(item.PostTransactionState);
            }

            if (isStorage)
            {
                rlpStream.Encode(item.BlockHash);
                rlpStream.Encode(item.BlockNumber);
                rlpStream.Encode(item.Index);
                rlpStream.Encode(item.Sender);
                rlpStream.Encode(item.Recipient);
                rlpStream.Encode(item.ContractAddress);
                rlpStream.Encode(item.GasUsed);
                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]);
                }

                if (_supportTxHash)
                {
                    rlpStream.WriteByte(MarkTxHashByte);
                    rlpStream.Encode(item.TxHash);
                }

                rlpStream.Encode(item.Error);
            }
            else
            {
                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]);
                }

                rlpStream.Encode(item.Error);
            }
        }
コード例 #9
0
        public void Encode(RlpStream rlpStream, BlockHeader?header, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (header is null)
            {
                rlpStream.EncodeNullObject();
                return;
            }

            bool notForSealing = (rlpBehaviors & RlpBehaviors.ForSealing) != RlpBehaviors.ForSealing;

            rlpStream.StartSequence(GetContentLength(header, rlpBehaviors));
            rlpStream.Encode(header.ParentHash);
            rlpStream.Encode(header.UnclesHash);
            rlpStream.Encode(header.Beneficiary);
            rlpStream.Encode(header.StateRoot);
            rlpStream.Encode(header.TxRoot);
            rlpStream.Encode(header.ReceiptsRoot);
            rlpStream.Encode(header.Bloom);
            rlpStream.Encode(header.Difficulty);
            rlpStream.Encode(header.Number);
            rlpStream.Encode(header.GasLimit);
            rlpStream.Encode(header.GasUsed);
            rlpStream.Encode(header.Timestamp);
            rlpStream.Encode(header.ExtraData);

            if (notForSealing)
            {
                bool isAuRa = header.AuRaSignature != null;
                if (isAuRa)
                {
                    rlpStream.Encode(header.AuRaStep !.Value);
                    rlpStream.Encode(header.AuRaSignature);
                }
                else
                {
                    rlpStream.Encode(header.MixHash);
                    rlpStream.EncodeNonce(header.Nonce);
                }
            }

            if (header.Number >= Eip1559TransitionBlock)
            {
                rlpStream.Encode(header.BaseFeePerGas);
            }
        }
コード例 #10
0
        public void Encode(RlpStream rlpStream, BlockHeader item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                rlpStream.EncodeNullObject();
                return;
            }

            bool notForSealing = (rlpBehaviors & RlpBehaviors.ForSealing) != RlpBehaviors.ForSealing;

            rlpStream.StartSequence(GetContentLength(item, rlpBehaviors));
            rlpStream.Encode(item.ParentHash);
            rlpStream.Encode(item.OmmersHash);
            rlpStream.Encode(item.Beneficiary);
            rlpStream.Encode(item.StateRoot);
            rlpStream.Encode(item.TxRoot);
            rlpStream.Encode(item.ReceiptsRoot);
            rlpStream.Encode(item.Bloom);
            rlpStream.Encode(item.Difficulty);
            rlpStream.Encode(item.Number);
            rlpStream.Encode(item.GasLimit);
            rlpStream.Encode(item.GasUsed);
            rlpStream.Encode(item.Timestamp);
            rlpStream.Encode(item.ExtraData);

            if (notForSealing)
            {
                bool isAuRa = item.AuRaSignature != null;

                if (isAuRa)
                {
                    rlpStream.Encode(item.AuRaStep.Value);
                    rlpStream.Encode(item.AuRaSignature);
                }
                else
                {
                    rlpStream.Encode(item.MixHash);
                    rlpStream.Encode(item.Nonce);
                }
            }
        }