Skip to content

Commit

Permalink
move contract.eventFilter to contract.events.*.createFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjw committed Mar 16, 2018
1 parent af0bb6f commit 704a254
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def encodeABI(cls, fn_name, args=None, kwargs=None, data=None):
return encode_abi(cls.web3, fn_abi, fn_arguments, data)

@combomethod
@deprecated_for("contract.events.<event name>.createFilter")
def eventFilter(self, event_name, filter_params={}):
"""
Create filter object that tracks events emitted by this contract.
Expand Down Expand Up @@ -328,7 +329,7 @@ def eventFilter(self, event_name, filter_params={}):
return log_filter

@combomethod
@deprecated_for("contract.<functions/events>.<method name>.estimateGas")
@deprecated_for("contract.functions.<method name>.estimateGas")
def estimateGas(self, transaction=None):
"""
Estimate the gas for a call
Expand Down Expand Up @@ -1004,6 +1005,31 @@ def _parse_logs(self, txn_receipt):
continue
yield decoded_log

def createFilter(self, filter_params={}):
"""
Create filter object that tracks logs emitted by this contract event.
:param filter_params: other parameters to limit the events
"""
filter_meta_params = dict(filter_params)
argument_filters = filter_meta_params.pop('filter', {})

data_filter_set, event_filter_params = construct_event_filter_params(
self._get_event_abi(),
contract_address=self.address,
argument_filters=argument_filters,
**filter_meta_params
)

log_data_extract_fn = functools.partial(get_event_data, self._get_event_abi())

log_filter = self.web3.eth.filter(event_filter_params)

log_filter.set_data_filters(data_filter_set)
log_filter.log_entry_formatter = log_data_extract_fn
log_filter.filter_params = event_filter_params

return log_filter

@classmethod
def factory(cls, class_name, **kwargs):
return PropertyCheckingFactory(class_name, (cls,), kwargs)
Expand Down

0 comments on commit 704a254

Please sign in to comment.