def filterload(self, flag=1): payload = encode_varint(self.size) payload += bit_field_to_bytes(self.bit_field) payload += int_to_little_endian(self.function_count, 4) payload += int_to_little_endian(self.tweak, 4) # The matched item flag is used to tell the full node to add any matched transactions to the bloom filter. payload += int_to_little_endian(flag, 1) # filterload is the command used to set the bloom filter. return GenericMessage(b'filterload', payload)
def test_exercise_1(self): field_size = 10 function_count = 5 tweak = 99 items = (b'Hello World', b'Goodbye!') bit_field_size = field_size * 8 bit_field = [0] * bit_field_size for item in items: for i in range(function_count): seed = i * BIP37_CONSTANT + tweak h = murmur3(item, seed=seed) bit = h % bit_field_size bit_field[bit] = 1 self.assertEqual( bit_field_to_bytes(bit_field).hex(), '4000600a080000010940')
def filter_bytes(self): return bit_field_to_bytes(self.bit_field)