@@ -251,17 +251,22 @@ def get_logs(
251
251
# if we already know that the filter range is too large, split it
252
252
if num_blocks > filter_block_range :
253
253
results = []
254
+ last_block_hash = filter_params .get ("fromBlockParentHash" )
254
255
for filter_start in range (from_block , to_block + 1 , filter_block_range ):
255
256
filter_end = min (filter_start + filter_block_range - 1 , to_block )
256
257
partial_filter = {
257
258
** filter_params ,
258
259
"fromBlock" : filter_start ,
259
260
"toBlock" : filter_end ,
260
261
}
261
- if to_block_hash is not None and filter_end != to_block :
262
- del partial_filter ["toBlockHash" ]
263
- if from_block_parent_hash is not None and filter_start != from_block :
264
- del partial_filter ["fromBlockParentHash" ]
262
+ if filter_end == to_block :
263
+ to_block_hash = filter_params .get ("toBlockHash" )
264
+ else :
265
+ to_block_hash = self .get_block (filter_end )["hash" ].to_0x_hex ()
266
+ partial_filter ["fromBlockParentHash" ] = last_block_hash
267
+ partial_filter ["toBlockHash" ] = to_block_hash
268
+ last_block_hash = to_block_hash
269
+
265
270
results += self .get_logs (partial_filter , ** kwargs )
266
271
return results
267
272
@@ -303,10 +308,9 @@ def get_logs(
303
308
mid_block = (from_block + to_block ) // 2
304
309
left_filter = {** filter_params , "toBlock" : mid_block }
305
310
right_filter = {** filter_params , "fromBlock" : mid_block + 1 }
306
- if to_block_hash is not None :
307
- del left_filter ["toBlockHash" ]
308
- if from_block_parent_hash is not None :
309
- del right_filter ["fromBlockParentHash" ]
311
+ middle_block_hash = self .get_block (mid_block )["hash" ].to_0x_hex ()
312
+ left_filter ["toBlockHash" ] = middle_block_hash
313
+ right_filter ["fromBlockParentHash" ] = middle_block_hash
310
314
return self .get_logs (left_filter , ** kwargs ) + self .get_logs (right_filter , ** kwargs )
311
315
312
316
def get_logs_inner (self , filter_params : FilterParams , no_retry : bool = False ):
0 commit comments