public static void DecodeStructRef(ref Rlp.ValueDecoderContext decoderContext, RlpBehaviors storage, out LogEntryStructRef item) { if (decoderContext.IsNextItemNull()) { decoderContext.ReadByte(); item = new LogEntryStructRef(); return; } decoderContext.ReadSequenceLength(); decoderContext.DecodeAddressStructRef(out var address); var peekPrefixAndContentLength = decoderContext.PeekPrefixAndContentLength(); var sequenceLength = peekPrefixAndContentLength.PrefixLength + peekPrefixAndContentLength.ContentLength; var topics = decoderContext.Data.Slice(decoderContext.Position, sequenceLength); decoderContext.SkipItem(); var data = decoderContext.DecodeByteArraySpan(); item = new LogEntryStructRef(address, data, topics); }
public void DecodeStructRef(ref Rlp.ValueDecoderContext decoderContext, RlpBehaviors rlpBehaviors, out TxReceiptStructRef item) { item = new TxReceiptStructRef(); if (decoderContext.IsNextItemNull()) { decoderContext.ReadByte(); return; } bool isStorage = (rlpBehaviors & RlpBehaviors.Storage) != 0; decoderContext.ReadSequenceLength(); Span <byte> firstItem = decoderContext.DecodeByteArraySpan(); if (firstItem.Length == 1) { item.StatusCode = firstItem[0]; } else { item.PostTransactionState = firstItem.Length == 0 ? new ValueKeccak() : new ValueKeccak(firstItem); } if (isStorage) { decoderContext.DecodeValueKeccak(out item.BlockHash); } if (isStorage) { item.BlockNumber = (long)decoderContext.DecodeUInt256(); } if (isStorage) { item.Index = decoderContext.DecodeInt(); } if (isStorage) { decoderContext.DecodeAddressStructRef(out item.Sender); } if (isStorage) { decoderContext.DecodeAddressStructRef(out item.Recipient); } if (isStorage) { decoderContext.DecodeAddressStructRef(out item.ContractAddress); } if (isStorage) { item.GasUsed = (long)decoderContext.DecodeUBigInt(); } item.GasUsedTotal = (long)decoderContext.DecodeUBigInt(); decoderContext.DecodeBloomStructRef(out item.Bloom); var peekPrefixAndContentLength = decoderContext.PeekPrefixAndContentLength(); var logsBytes = peekPrefixAndContentLength.ContentLength + peekPrefixAndContentLength.PrefixLength; item.LogsRlp = decoderContext.Data.Slice(decoderContext.Position, logsBytes); decoderContext.SkipItem(); bool allowExtraData = (rlpBehaviors & RlpBehaviors.AllowExtraData) != 0; if (!allowExtraData) { if (isStorage && _supportTxHash) { // since txHash was added later and may not be in rlp, we provide special mark byte that it will be next if (decoderContext.PeekByte() == MarkTxHashByte) { decoderContext.ReadByte(); decoderContext.DecodeValueKeccak(out item.TxHash); } } // since error was added later we can only rely on it in cases where we read receipt only and no data follows, empty errors might not be serialized if (decoderContext.Position != decoderContext.Length) { item.Error = decoderContext.DecodeString(); } } }
public BlockHeader?Decode(ref Rlp.ValueDecoderContext decoderContext, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (decoderContext.IsNextItemNull()) { return(null); } var headerRlp = decoderContext.PeekNextItem(); int headerSequenceLength = decoderContext.ReadSequenceLength(); int headerCheck = decoderContext.Position + headerSequenceLength; Keccak? parentHash = decoderContext.DecodeKeccak(); Keccak? unclesHash = decoderContext.DecodeKeccak(); Address?beneficiary = decoderContext.DecodeAddress(); Keccak? stateRoot = decoderContext.DecodeKeccak(); Keccak? transactionsRoot = decoderContext.DecodeKeccak(); Keccak? receiptsRoot = decoderContext.DecodeKeccak(); Bloom? bloom = decoderContext.DecodeBloom(); UInt256 difficulty = decoderContext.DecodeUInt256(); long number = decoderContext.DecodeLong(); long gasLimit = decoderContext.DecodeLong(); long gasUsed = decoderContext.DecodeLong(); UInt256 timestamp = decoderContext.DecodeUInt256(); byte[]? extraData = decoderContext.DecodeByteArray(); BlockHeader blockHeader = new( parentHash, unclesHash, beneficiary, difficulty, number, gasLimit, timestamp, extraData) { StateRoot = stateRoot, TxRoot = transactionsRoot, ReceiptsRoot = receiptsRoot, Bloom = bloom, GasUsed = gasUsed, Hash = Keccak.Compute(headerRlp) }; if (decoderContext.PeekPrefixAndContentLength().ContentLength == Keccak.Size) { blockHeader.MixHash = decoderContext.DecodeKeccak(); blockHeader.Nonce = (ulong)decoderContext.DecodeUBigInt(); } else { blockHeader.AuRaStep = (long)decoderContext.DecodeUInt256(); blockHeader.AuRaSignature = decoderContext.DecodeByteArray(); } if (blockHeader.Number >= Eip1559TransitionBlock) { blockHeader.BaseFeePerGas = decoderContext.DecodeUInt256(); } if ((rlpBehaviors & RlpBehaviors.AllowExtraData) != RlpBehaviors.AllowExtraData) { decoderContext.Check(headerCheck); } return(blockHeader); }
public BlockHeader Decode(Rlp.ValueDecoderContext decoderContext, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (decoderContext.IsNextItemNull()) { return(null); } var headerRlp = decoderContext.PeekNextItem(); int headerSequenceLength = decoderContext.ReadSequenceLength(); int headerCheck = decoderContext.Position + headerSequenceLength; Keccak parentHash = decoderContext.DecodeKeccak(); Keccak ommersHash = decoderContext.DecodeKeccak(); Address beneficiary = decoderContext.DecodeAddress(); Keccak stateRoot = decoderContext.DecodeKeccak(); Keccak transactionsRoot = decoderContext.DecodeKeccak(); Keccak receiptsRoot = decoderContext.DecodeKeccak(); Bloom bloom = decoderContext.DecodeBloom(); UInt256 difficulty = decoderContext.DecodeUInt256(); UInt256 number = decoderContext.DecodeUInt256(); UInt256 gasLimit = decoderContext.DecodeUInt256(); UInt256 gasUsed = decoderContext.DecodeUInt256(); UInt256 timestamp = decoderContext.DecodeUInt256(); byte[] extraData = decoderContext.DecodeByteArray(); BlockHeader blockHeader = new BlockHeader( parentHash, ommersHash, beneficiary, difficulty, (long)number, (long)gasLimit, timestamp, extraData) { StateRoot = stateRoot, TxRoot = transactionsRoot, ReceiptsRoot = receiptsRoot, Bloom = bloom, GasUsed = (long)gasUsed, Hash = Keccak.Compute(headerRlp) }; if (decoderContext.PeekPrefixAndContentLength().ContentLength == Keccak.Size) { blockHeader.MixHash = decoderContext.DecodeKeccak(); blockHeader.Nonce = (ulong)decoderContext.DecodeUBigInt(); } else { blockHeader.AuRaStep = (long)decoderContext.DecodeUInt256(); blockHeader.AuRaSignature = decoderContext.DecodeByteArray(); } if ((rlpBehaviors & RlpBehaviors.AllowExtraData) != RlpBehaviors.AllowExtraData) { decoderContext.Check(headerCheck); } return(blockHeader); }