Ejemplo n.º 1
0
 def filter(self, filter_params=None, filter_id=None):
     if filter_id and filter_params:
         raise TypeError(
             "Ambiguous invocation: provide either a `filter_params` or a `filter_id` argument. "
             "Both were supplied.")
     if is_string(filter_params):
         if filter_params == "latest":
             filter_id = self.web3.manager.request_blocking(
                 "eth_newBlockFilter",
                 [],
             )
             return BlockFilter(self.web3, filter_id)
         elif filter_params == "pending":
             filter_id = self.web3.manager.request_blocking(
                 "eth_newPendingTransactionFilter",
                 [],
             )
             return TransactionFilter(self.web3, filter_id)
         else:
             raise ValueError(
                 "The filter API only accepts the values of `pending` or "
                 "`latest` for string based filters")
     elif isinstance(filter_params, dict):
         _filter_id = self.web3.manager.request_blocking(
             "eth_newFilter",
             [filter_params],
         )
         return LogFilter(self.web3, _filter_id)
     elif filter_id and not filter_params:
         return LogFilter(self.web3, filter_id)
     else:
         raise TypeError(
             "Must provide either filter_params as a string or "
             "a valid filter object, or a filter_id as a string "
             "or hex.")
Ejemplo n.º 2
0
 def filter(self, filter_params):
     if is_string(filter_params):
         if filter_params == "latest":
             filter_id = self.web3.manager.request_blocking(
                 "eth_newBlockFilter",
                 [],
             )
             return BlockFilter(self.web3, filter_id)
         elif filter_params == "pending":
             filter_id = self.web3.manager.request_blocking(
                 "eth_newPendingTransactionFilter",
                 [],
             )
             return TransactionFilter(self.web3, filter_id)
         else:
             raise ValueError(
                 "The filter API only accepts the values of `pending` or "
                 "`latest` for string based filters")
     elif isinstance(filter_params, dict):
         filter_id = self.web3.manager.request_blocking(
             "eth_newFilter",
             [filter_params],
         )
         return LogFilter(self.web3, filter_id)
     else:
         raise ValueError(
             "Must provide either a string or a valid filter object")