@@ -346,6 +346,35 @@ def set_contract_factory(
346
346
) -> None :
347
347
self .defaultContractFactory = contractFactory
348
348
349
+ def filter_munger (
350
+ self ,
351
+ filter_params : Optional [Union [str , FilterParams ]] = None ,
352
+ filter_id : Optional [HexStr ] = None ,
353
+ ) -> Union [List [FilterParams ], List [HexStr ], List [str ]]:
354
+ if filter_id and filter_params :
355
+ raise TypeError (
356
+ "Ambiguous invocation: provide either a `filter_params` or a "
357
+ "`filter_id` argument. Both were supplied."
358
+ )
359
+ if isinstance (filter_params , dict ):
360
+ return [filter_params ]
361
+ elif is_string (filter_params ):
362
+ if filter_params in ["latest" , "pending" ]:
363
+ return [filter_params ]
364
+ else :
365
+ raise ValueError (
366
+ "The filter API only accepts the values of `pending` or "
367
+ "`latest` for string based filters"
368
+ )
369
+ elif filter_id and not filter_params :
370
+ return [filter_id ]
371
+ else :
372
+ raise TypeError (
373
+ "Must provide either filter_params as a string or "
374
+ "a valid filter object, or a filter_id as a string "
375
+ "or hex."
376
+ )
377
+
349
378
350
379
class AsyncEth (BaseEth ):
351
380
is_async = True
@@ -597,6 +626,37 @@ async def get_storage_at(
597
626
) -> HexBytes :
598
627
return await self ._get_storage_at (account , position , block_identifier )
599
628
629
+ filter : Method [Callable [..., Awaitable [Any ]]] = Method (
630
+ method_choice_depends_on_args = select_filter_method (
631
+ if_new_block_filter = RPC .eth_newBlockFilter ,
632
+ if_new_pending_transaction_filter = RPC .eth_newPendingTransactionFilter ,
633
+ if_new_filter = RPC .eth_newFilter ,
634
+ ),
635
+ mungers = [BaseEth .filter_munger ],
636
+ )
637
+
638
+ _get_filter_changes : Method [
639
+ Callable [[HexStr ], Awaitable [List [LogReceipt ]]]
640
+ ] = Method (RPC .eth_getFilterChanges , mungers = [default_root_munger ])
641
+
642
+ async def get_filter_changes (self , filter_id : HexStr ) -> List [LogReceipt ]:
643
+ return await self ._get_filter_changes (filter_id )
644
+
645
+ _get_filter_logs : Method [Callable [[HexStr ], Awaitable [List [LogReceipt ]]]] = Method (
646
+ RPC .eth_getFilterLogs , mungers = [default_root_munger ]
647
+ )
648
+
649
+ async def get_filter_logs (self , filter_id : HexStr ) -> List [LogReceipt ]:
650
+ return await self ._get_filter_logs (filter_id )
651
+
652
+ _uninstall_filter : Method [Callable [[HexStr ], Awaitable [bool ]]] = Method (
653
+ RPC .eth_uninstallFilter ,
654
+ mungers = [default_root_munger ],
655
+ )
656
+
657
+ async def uninstall_filter (self , filter_id : HexStr ) -> bool :
658
+ return await self ._uninstall_filter (filter_id )
659
+
600
660
601
661
class Eth (BaseEth ):
602
662
defaultContractFactory : Type [Union [Contract , ContractCaller ]] = Contract
@@ -902,42 +962,13 @@ def fee_history(
902
962
) -> FeeHistory :
903
963
return self ._fee_history (block_count , newest_block , reward_percentiles )
904
964
905
- def filter_munger (
906
- self ,
907
- filter_params : Optional [Union [str , FilterParams ]] = None ,
908
- filter_id : Optional [HexStr ] = None ,
909
- ) -> Union [List [FilterParams ], List [HexStr ], List [str ]]:
910
- if filter_id and filter_params :
911
- raise TypeError (
912
- "Ambiguous invocation: provide either a `filter_params` or a "
913
- "`filter_id` argument. Both were supplied."
914
- )
915
- if isinstance (filter_params , dict ):
916
- return [filter_params ]
917
- elif is_string (filter_params ):
918
- if filter_params in ["latest" , "pending" ]:
919
- return [filter_params ]
920
- else :
921
- raise ValueError (
922
- "The filter API only accepts the values of `pending` or "
923
- "`latest` for string based filters"
924
- )
925
- elif filter_id and not filter_params :
926
- return [filter_id ]
927
- else :
928
- raise TypeError (
929
- "Must provide either filter_params as a string or "
930
- "a valid filter object, or a filter_id as a string "
931
- "or hex."
932
- )
933
-
934
965
filter : Method [Callable [..., Any ]] = Method (
935
966
method_choice_depends_on_args = select_filter_method (
936
967
if_new_block_filter = RPC .eth_newBlockFilter ,
937
968
if_new_pending_transaction_filter = RPC .eth_newPendingTransactionFilter ,
938
969
if_new_filter = RPC .eth_newFilter ,
939
970
),
940
- mungers = [filter_munger ],
971
+ mungers = [BaseEth . filter_munger ],
941
972
)
942
973
943
974
get_filter_changes : Method [Callable [[HexStr ], List [LogReceipt ]]] = Method (
@@ -948,6 +979,11 @@ def filter_munger(
948
979
RPC .eth_getFilterLogs , mungers = [default_root_munger ]
949
980
)
950
981
982
+ uninstall_filter : Method [Callable [[HexStr ], bool ]] = Method (
983
+ RPC .eth_uninstallFilter ,
984
+ mungers = [default_root_munger ],
985
+ )
986
+
951
987
get_logs : Method [Callable [[FilterParams ], List [LogReceipt ]]] = Method (
952
988
RPC .eth_getLogs , mungers = [default_root_munger ]
953
989
)
@@ -962,11 +998,6 @@ def filter_munger(
962
998
mungers = [default_root_munger ],
963
999
)
964
1000
965
- uninstall_filter : Method [Callable [[HexStr ], bool ]] = Method (
966
- RPC .eth_uninstallFilter ,
967
- mungers = [default_root_munger ],
968
- )
969
-
970
1001
get_work : Method [Callable [[], List [HexBytes ]]] = Method (
971
1002
RPC .eth_getWork ,
972
1003
is_property = True ,
0 commit comments