Beispiel #1
0
        public void Encode(MemoryStream stream, BlockHeader item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                stream.Write(Rlp.OfEmptySequence.Bytes);
                return;
            }

            bool forSealing = (rlpBehaviors & RlpBehaviors.ForSealing) == RlpBehaviors.ForSealing;

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

            if (!forSealing)
            {
                Rlp.Encode(stream, item.MixHash);
                Rlp.Encode(stream, item.Nonce);
            }
        }
Beispiel #2
0
        public void Encode(MemoryStream stream, TxReceipt item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                stream.Write(Rlp.OfEmptySequence.Bytes);
                return;
            }

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

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

            Rlp.StartSequence(stream, totalLength);
            if (isEip658receipts)
            {
                Rlp.Encode(stream, item.StatusCode);
            }
            else
            {
                Rlp.Encode(stream, item.PostTransactionState);
            }

            if (isStorage)
            {
                Rlp.Encode(stream, item.BlockHash);
                Rlp.Encode(stream, item.BlockNumber);
                Rlp.Encode(stream, item.Index);
                Rlp.Encode(stream, item.Sender);
                Rlp.Encode(stream, item.Recipient);
                Rlp.Encode(stream, item.ContractAddress);
                Rlp.Encode(stream, item.GasUsed);
                Rlp.Encode(stream, item.GasUsedTotal);
                Rlp.Encode(stream, item.Bloom);

                Rlp.StartSequence(stream, logsLength);

                for (var i = 0; i < item.Logs.Length; i++)
                {
                    Rlp.Encode(stream, item.Logs[i]);
                }

                Rlp.Encode(stream, item.Error);
            }
            else
            {
                Rlp.Encode(stream, item.GasUsedTotal);
                Rlp.Encode(stream, item.Bloom);

                Rlp.StartSequence(stream, logsLength);

                for (var i = 0; i < item.Logs.Length; i++)
                {
                    Rlp.Encode(stream, item.Logs[i]);
                }
            }
        }
 public void Encode(MemoryStream stream, Transaction item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     int contentLength = GetContentLength(item, false);
     Rlp.StartSequence(stream, contentLength);
     Rlp.Encode(stream, item.Nonce);
     Rlp.Encode(stream, item.GasPrice);
     Rlp.Encode(stream, item.GasLimit);
     Rlp.Encode(stream, item.To);
     Rlp.Encode(stream, item.Value);
     Rlp.Encode(stream, item.To == null ? item.Init : item.Data);
     Rlp.Encode(stream, item.Signature?.V ?? 0);
     Rlp.Encode(stream, item.Signature == null ? null : item.Signature.RAsSpan.WithoutLeadingZeros());
     Rlp.Encode(stream, item.Signature == null ? null : item.Signature.SAsSpan.WithoutLeadingZeros());
 }
Beispiel #4
0
        public void Encode(MemoryStream stream, Block item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            (int contentLength, int txsLength, int ommersLength) = GetContentLength(item, rlpBehaviors);
            Rlp.StartSequence(stream, contentLength);
            _headerDecoder.Encode(stream, item.Header);
            Rlp.StartSequence(stream, txsLength);
            for (int i = 0; i < item.Transactions.Length; i++)
            {
                _txDecoder.Encode(stream, item.Transactions[i]);
            }

            Rlp.StartSequence(stream, ommersLength);
            for (int i = 0; i < item.Ommers.Length; i++)
            {
                _headerDecoder.Encode(stream, item.Ommers[i]);
            }
        }
Beispiel #5
0
        public void Encode(MemoryStream stream, BlockHeader item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                stream.Write(Rlp.OfEmptySequence.Bytes);
                return;
            }

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

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

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

                if (isAuRa)
                {
                    Rlp.Encode(stream, item.AuRaStep.Value);
                    Rlp.Encode(stream, item.AuRaSignature);
                }
                else
                {
                    Rlp.Encode(stream, item.MixHash);
                    Rlp.Encode(stream, item.Nonce);
                }
            }
        }
Beispiel #6
0
        public void Encode(MemoryStream stream, LogEntry item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (item == null)
            {
                stream.Write(Rlp.OfEmptySequence.Bytes);
                return;
            }

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

            Rlp.Encode(stream, item.LoggersAddress);
            Rlp.StartSequence(stream, topics);

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

            Rlp.Encode(stream, item.Data);
        }