public bool Equals(Bloom?other) { if (ReferenceEquals(null, other)) { return(false); } return(Nethermind.Core.Extensions.Bytes.AreEqual(Bytes, other.Bytes)); }
private void Set(Span <byte> sequence, Bloom?masterBloom = null) { Bloom.BloomExtract indexes = GetExtract(sequence); Set(indexes.Index1); Set(indexes.Index2); Set(indexes.Index3); if (masterBloom != null) { masterBloom.Set(indexes.Index1); masterBloom.Set(indexes.Index2); masterBloom.Set(indexes.Index3); } }
public void Add(LogEntry[] logEntries, Bloom?blockBloom) { for (int entryIndex = 0; entryIndex < logEntries.Length; entryIndex++) { LogEntry logEntry = logEntries[entryIndex]; byte[] addressBytes = logEntry.LoggersAddress.Bytes; Set(addressBytes, blockBloom); for (int topicIndex = 0; topicIndex < logEntry.Topics.Length; topicIndex++) { Keccak topic = logEntry.Topics[topicIndex]; Set(topic.Bytes, blockBloom); } } }
private void Set(byte[] sequence, Bloom?masterBloom) { if (ReferenceEquals(this, Empty)) { throw new InvalidOperationException("An attempt was made to update Bloom.Empty constant"); } BloomExtract indexes = GetExtract(sequence); Set(indexes.Index1); Set(indexes.Index2); Set(indexes.Index3); if (masterBloom != null) { masterBloom.Set(indexes.Index1); masterBloom.Set(indexes.Index2); masterBloom.Set(indexes.Index3); } }
public Bloom(LogEntry[] logEntries, Bloom?blockBloom = null) { Bytes = new byte[ByteLength]; Add(logEntries, blockBloom); }
public BlockHeader?Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (rlpStream.IsNextItemNull()) { rlpStream.ReadByte(); return(null); } Span <byte> headerRlp = rlpStream.PeekNextItem(); int headerSequenceLength = rlpStream.ReadSequenceLength(); int headerCheck = rlpStream.Position + headerSequenceLength; Keccak? parentHash = rlpStream.DecodeKeccak(); Keccak? unclesHash = rlpStream.DecodeKeccak(); Address?beneficiary = rlpStream.DecodeAddress(); Keccak? stateRoot = rlpStream.DecodeKeccak(); Keccak? transactionsRoot = rlpStream.DecodeKeccak(); Keccak? receiptsRoot = rlpStream.DecodeKeccak(); Bloom? bloom = rlpStream.DecodeBloom(); UInt256 difficulty = rlpStream.DecodeUInt256(); long number = rlpStream.DecodeLong(); long gasLimit = rlpStream.DecodeLong(); long gasUsed = rlpStream.DecodeLong(); UInt256 timestamp = rlpStream.DecodeUInt256(); byte[]? extraData = rlpStream.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 (rlpStream.PeekPrefixAndContentLength().ContentLength == Keccak.Size) { blockHeader.MixHash = rlpStream.DecodeKeccak(); blockHeader.Nonce = (ulong)rlpStream.DecodeUBigInt(); } else { blockHeader.AuRaStep = (long)rlpStream.DecodeUInt256(); blockHeader.AuRaSignature = rlpStream.DecodeByteArray(); } if (blockHeader.Number >= Eip1559TransitionBlock) { blockHeader.BaseFeePerGas = rlpStream.DecodeUInt256(); } if ((rlpBehaviors & RlpBehaviors.AllowExtraData) != RlpBehaviors.AllowExtraData) { rlpStream.Check(headerCheck); } return(blockHeader); }
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? 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( parentHash, ommersHash, beneficiary, difficulty, (long)number, (long)gasLimit, timestamp, extraData) { StateRoot = stateRoot, TxRoot = transactionsRoot, ReceiptsRoot = receiptsRoot, Bloom = bloom, GasUsedLegacy = (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 (blockHeader.Number >= Eip1559TransitionBlock) { blockHeader.BaseFee = decoderContext.DecodeUInt256(); } if ((rlpBehaviors & RlpBehaviors.AllowExtraData) != RlpBehaviors.AllowExtraData) { decoderContext.Check(headerCheck); } return(blockHeader); }