@@ -589,6 +589,10 @@ async def async_block_hashes_in_range(
589
589
AsyncFilter = Union [AsyncRequestLogs , AsyncRequestBlocks ]
590
590
591
591
592
+ def _simulate_rpc_response_with_result (filter_id : str ) -> "RPCResponse" :
593
+ return {"jsonrpc" : "2.0" , "id" : - 1 , "result" : filter_id }
594
+
595
+
592
596
class LocalFilterMiddleware (Web3Middleware ):
593
597
def __init__ (self , w3 : Union ["Web3" , "AsyncWeb3" ]):
594
598
self .filters : Dict [str , SyncFilter ] = {}
@@ -615,7 +619,7 @@ def middleware(method: "RPCEndpoint", params: Any) -> "RPCResponse":
615
619
raise NotImplementedError (method )
616
620
617
621
self .filters [filter_id ] = _filter
618
- return { "result" : filter_id }
622
+ return _simulate_rpc_response_with_result ( filter_id )
619
623
620
624
elif method in FILTER_CHANGES_METHODS :
621
625
_filter_id = params [0 ]
@@ -626,12 +630,16 @@ def middleware(method: "RPCEndpoint", params: Any) -> "RPCResponse":
626
630
627
631
_filter = self .filters [_filter_id ]
628
632
if method == RPC .eth_getFilterChanges :
629
- return {"result" : next (_filter .filter_changes )}
633
+ return _simulate_rpc_response_with_result (
634
+ next (_filter .filter_changes ) # type: ignore
635
+ )
630
636
631
637
elif method == RPC .eth_getFilterLogs :
632
638
# type ignored b/c logic prevents RequestBlocks which
633
639
# doesn't implement get_logs
634
- return {"result" : _filter .get_logs ()} # type: ignore
640
+ return _simulate_rpc_response_with_result (
641
+ _filter .get_logs () # type: ignore
642
+ )
635
643
else :
636
644
raise NotImplementedError (method )
637
645
else :
@@ -663,7 +671,7 @@ async def middleware(method: "RPCEndpoint", params: Any) -> "RPCResponse":
663
671
raise NotImplementedError (method )
664
672
665
673
self .async_filters [filter_id ] = _filter
666
- return { "result" : filter_id }
674
+ return _simulate_rpc_response_with_result ( filter_id )
667
675
668
676
elif method in FILTER_CHANGES_METHODS :
669
677
_filter_id = params [0 ]
@@ -674,12 +682,16 @@ async def middleware(method: "RPCEndpoint", params: Any) -> "RPCResponse":
674
682
675
683
_filter = self .async_filters [_filter_id ]
676
684
if method == RPC .eth_getFilterChanges :
677
- return {"result" : await _filter .filter_changes .__anext__ ()}
685
+ return _simulate_rpc_response_with_result (
686
+ await _filter .filter_changes .__anext__ () # type: ignore
687
+ )
678
688
679
689
elif method == RPC .eth_getFilterLogs :
680
690
# type ignored b/c logic prevents RequestBlocks which
681
691
# doesn't implement get_logs
682
- return {"result" : await _filter .get_logs ()} # type: ignore
692
+ return _simulate_rpc_response_with_result (
693
+ await _filter .get_logs () # type: ignore
694
+ )
683
695
else :
684
696
raise NotImplementedError (method )
685
697
else :
0 commit comments