3
3
"""
4
4
5
5
from abc import abstractmethod
6
+ from collections import defaultdict
6
7
from dataclasses import dataclass
7
8
from functools import cached_property
8
9
from typing import Any , ClassVar , Dict , Generic , List , Literal , Sequence , SupportsBytes , Tuple
@@ -1204,7 +1205,6 @@ class Requests:
1204
1205
def __init__ (
1205
1206
self ,
1206
1207
* requests : RequestBase ,
1207
- max_request_type : int | None = None ,
1208
1208
requests_lists : List [List [RequestBase ] | Bytes ] | None = None ,
1209
1209
):
1210
1210
"""
@@ -1217,21 +1217,21 @@ def __init__(
1217
1217
self .requests_list .append (requests_list_to_bytes (requests_list ))
1218
1218
return
1219
1219
else :
1220
-
1221
- assert max_request_type is not None , "max_request_type must be provided"
1222
-
1223
- lists : List [List [RequestBase ]] = [[] for _ in range (max_request_type + 1 )]
1220
+ lists : Dict [int , List [RequestBase ]] = defaultdict (list )
1224
1221
for r in requests :
1225
1222
lists [r .type ].append (r )
1226
1223
1227
- self .requests_list = [requests_list_to_bytes (requests_list ) for requests_list in lists ]
1224
+ self .requests_list = [
1225
+ Bytes (bytes ([request_type ]) + requests_list_to_bytes (lists [request_type ]))
1226
+ for request_type in sorted (lists .keys ())
1227
+ ]
1228
1228
1229
1229
def __bytes__ (self ) -> bytes :
1230
1230
"""
1231
1231
Returns the requests hash.
1232
1232
"""
1233
1233
s : bytes = b""
1234
- for i , r in enumerate ( self .requests_list ) :
1234
+ for r in self .requests_list :
1235
1235
# Append the index of the request type to the request data before hashing
1236
- s = s + Bytes ( bytes ([ i ]) + r ) .sha256 ()
1236
+ s = s + r .sha256 ()
1237
1237
return Bytes (s ).sha256 ()
0 commit comments