示例#1
0
 def __init__(
     self,
     db: ShardDbOperator,
     addresses: List[Address],
     topics: List[List[bytes]],
     end_block_header: Optional[MinorBlockHeader] = None,
     size: int = 0,
     candidate_blocks: Optional[List[MinorBlock]] = None,
     block_hash: Optional[str] = None,
 ):
     """
     `topics` is a list of lists where each one expresses the OR semantics,
     while the whole list itself is connected by AND. For details check the
     Ethereum JSONRPC spec.
     """
     self.db = db
     # if `addresses` present, should be in the same shard
     self.recipients = [addr.recipient for addr in addresses]
     self.end_block_header = end_block_header
     self.size = size
     self.candidate_blocks = candidate_blocks
     # in case filter is instantiated through constructor instead of factory methods
     if candidate_blocks is not None and (end_block_header is not None
                                          or size != 0):
         raise ValueError(
             "Should pass in either candidate blocks or end block header and size"
         )
     if candidate_blocks is not None:
         self.candidate_blocks = sorted(candidate_blocks,
                                        key=lambda x: x.header.height)
     self.block_hash = block_hash  # TODO: not supported yet
     # construct bloom bits:
     # innermost: an integer with 3 bits set
     # outer: a list of those integers are connected by OR operator
     # outermost: a list of those lists are connected by AND operator
     self.bloom_bits = []  # type: List[List[int]]
     for r in self.recipients:
         b = bloom(r)
         self.bloom_bits.append([b])
     self.topics = topics
     for tp_list in topics:
         if not tp_list:
             # regard as wildcard
             continue
         bloom_list = []
         for tp in tp_list:
             bloom_list.append(bloom(tp))
         self.bloom_bits.append(bloom_list)
     # a timestamp to control timeout. will be set upon running
     self.start_ts = None
 def __init__(
     self,
     db: ShardDbOperator,
     addresses: List[Address],
     topics: List[List[bytes]],
     start_block: int,
     end_block: int,
     block_hash: Optional[str] = None,
 ):
     """
     `topics` is a list of lists where each one expresses the OR semantics,
     while the whole list itself is connected by AND. For details check the
     Ethereum JSONRPC spec.
     """
     self.db = db
     # if `addresses` present, should be in the same shard
     self.recipients = [addr.recipient for addr in addresses]
     self.start_block = start_block
     self.end_block = end_block
     self.block_hash = block_hash  # TODO: not supported yet
     # construct bloom bits:
     # innermost: an integer with 3 bits set
     # outer: a list of those integers are connected by OR operator
     # outermost: a list of those lists are connected by AND operator
     self.bloom_bits = []  # type: List[List[int]]
     for r in self.recipients:
         b = bloom(r)
         self.bloom_bits.append([b])
     self.topics = topics
     for tp_list in topics:
         if not tp_list:
             # regard as wildcard
             continue
         bloom_list = []
         for tp in tp_list:
             bloom_list.append(bloom(tp))
         self.bloom_bits.append(bloom_list)
     # a timestamp to control timeout. will be set upon running
     self.start_ts = None
示例#3
0
 def test_bloom_bits_in_cstor(self):
     criteria = [[tp] for tp in self.log.topics]
     f = self.filter_gen_with_criteria(criteria)
     # use sha3(b'Hi(address)') to test bits
     expected_indexes = bits_in_number(bloom(sha3_256(b"Hi(address)")))
     self.assertEqual(expected_indexes, bits_in_number(f.bloom_bits[0][0]))