예제 #1
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));
        }
예제 #2
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());
 }
예제 #3
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);
        }
예제 #4
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]);
            }
        }
예제 #5
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]);
                }

                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]);
                }
            }
        }
예제 #6
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);
                }
            }
        }