def search(self, expression, callback_func): ''' searches through all contract accounts ''' cnt = 0 indexer = AccountIndexer(self) for contract, address_hash, balance in self.get_contracts(): if contract.matches_expression(expression): try: address = _encode_hex( indexer.get_contract_by_hash(address_hash)) except AddressNotFoundError: ''' The hash->address mapping does not exist in our index. If the index is up-to-date, this likely means that the contract was created by an internal transaction. Skip this contract as right now we don't have a good solution for this. ''' continue callback_func(contract, address, balance) cnt += 1 if not cnt % 1000: logging.info("Searched %d contracts" % cnt)
def contract_hash_to_address(self, hash): ''' tries to find corresponding account address ''' address_hash = binascii.a2b_hex(utils.remove_0x_head(hash)) indexer = AccountIndexer(self) return _encode_hex(indexer.get_contract_by_hash(address_hash))
def contract_hash_to_address(self, hash): ''' tries to find corresponding account address ''' indexer = AccountIndexer(self) addressHash = binascii.a2b_hex(utils.remove_0x_head(hash)) address = indexer.get_contract_by_hash(addressHash) if address: return _encode_hex(address) else: return "Not found"
def get_contracts(self): ''' iterate through all contracts ''' indexer = AccountIndexer(self) for account in self.reader._get_head_state().get_all_accounts(): if account.code is not None: code = _encode_hex(account.code) contract = ETHContract(code) address = indexer.get_contract_by_hash(account.address) if address is None: address = account.address yield contract, _encode_hex(address), account.balance
def search(self, expression, callback_func): ''' searches through non-zero balance contracts ''' cnt = 0 indexer = AccountIndexer(self) for contract, address_hash, balance in self.get_contracts(): if contract.matches_expression(expression): try: address = _encode_hex( indexer.get_contract_by_hash(address_hash)) except AddressNotFoundError: address = _encode_hex(address_hash) callback_func(contract, address, balance) cnt += 1 if not cnt % 1000: logging.info("Searched %d contracts" % cnt)