/// <summary> /// Determine whether a second bloom is possibly contained within the filter. /// </summary> /// <param name="bloom">The second bloom to test.</param> /// <returns>Whether this data could be contained within the filter.</returns> public bool Test(Bloom bloom) { var copy = new Bloom(bloom.ToBytes()); copy.Or(this); return(this.Equals(copy)); }
/// <summary> /// Determine whether some input is possibly contained within the filter. /// </summary> /// <param name="test">The byte array to test.</param> /// <returns>Whether this data could be contained within the filter.</returns> public bool Test(byte[] test) { var compare = new Bloom(); compare.Add(test); return(this.Test(compare)); }
/// <summary> /// Given this and another bloom, bitwise-OR all the data to get a bloom filter representing a range of data. /// </summary> public void Or(Bloom bloom) { for (int i = 0; i < this.data.Length; ++i) { this.data[i] |= bloom.data[i]; } }
public static void ReadWriteCompressed(this BitcoinStream stream, ref Bloom bloom) { // Ensure that the length can be serialized using a single byte. const int maxSerializedSize = byte.MaxValue + 1; if (Bloom.BloomLength > maxSerializedSize) { throw new InvalidOperationException($"'{nameof(ReadWriteCompressed)}' does not support bloom filters greater than {maxSerializedSize} bytes in length."); } if (stream.Serializing) { // Writing to stream. byte[] ser = bloom.GetCompressedBloom(); byte len = (byte)(ser.Length - 1); stream.ReadWrite(ref len); stream.ReadWrite(ref ser); } else { // Reading from stream. byte len = 0; stream.ReadWrite(ref len); // A value of 0 can be used to support larger blooms in the future. For now its not supported. if (len == 0) { throw new NotImplementedException("The bloom compression format is not supported."); } var c = new byte[(int)len + 1]; stream.ReadWrite(ref c); bloom = Bloom.GetDecompressedBloom(c); } }
public override void CopyFields(BlockHeader source) { base.CopyFields(source); if (source is PosBlockHeader header && header.HasSmartContractFields) { this.HashStateRoot = header.HashStateRoot; this.ReceiptRoot = header.ReceiptRoot; this.LogsBloom = header.LogsBloom; } }
public bool Equals(Bloom obj) { if (object.ReferenceEquals(obj, null)) { return(false); } if (object.ReferenceEquals(this, obj)) { return(true); } return(obj == this); }
public PosBlockHeader() { this.hashStateRoot = 0; this.receiptRoot = 0; this.logsBloom = new Bloom(); }