18
18
from abc import ABC , abstractmethod
19
19
from collections import deque
20
20
from itertools import chain
21
- from typing import TYPE_CHECKING , Iterable , Iterator , Optional , Union
21
+ from typing import TYPE_CHECKING , Callable , Iterable , Iterator , Optional , Union
22
22
23
23
if TYPE_CHECKING :
24
- from hathor .transaction import BaseTransaction # noqa: F401
25
- from hathor .transaction .storage import VertexStorageProtocol
24
+ from hathor .transaction import BaseTransaction , Vertex # noqa: F401
26
25
from hathor .types import VertexId
27
26
28
27
@@ -50,7 +49,7 @@ class GenericWalk(ABC):
50
49
51
50
def __init__ (
52
51
self ,
53
- storage : VertexStorageProtocol ,
52
+ vertex_getter : Callable [[ VertexId ], Vertex ] ,
54
53
* ,
55
54
is_dag_funds : bool = False ,
56
55
is_dag_verifications : bool = False ,
@@ -64,7 +63,7 @@ def __init__(
64
63
:param is_dag_verifications: Add neighbors from the DAG of verifications
65
64
:param is_left_to_right: Decide which side of the DAG we will walk to
66
65
"""
67
- self .storage = storage
66
+ self .vertex_getter = vertex_getter
68
67
self .seen = set ()
69
68
70
69
self .is_dag_funds = is_dag_funds
@@ -119,7 +118,7 @@ def add_neighbors(self, tx: 'BaseTransaction') -> None:
119
118
for _hash in it :
120
119
if _hash not in self .seen :
121
120
self .seen .add (_hash )
122
- neighbor = self .storage . get_vertex (_hash )
121
+ neighbor = self .vertex_getter (_hash )
123
122
self ._push_visit (neighbor )
124
123
125
124
def skip_neighbors (self , tx : 'BaseTransaction' ) -> None :
@@ -164,14 +163,14 @@ class BFSTimestampWalk(GenericWalk):
164
163
165
164
def __init__ (
166
165
self ,
167
- storage : VertexStorageProtocol ,
166
+ vertex_getter : Callable [[ VertexId ], Vertex ] ,
168
167
* ,
169
168
is_dag_funds : bool = False ,
170
169
is_dag_verifications : bool = False ,
171
170
is_left_to_right : bool = True ,
172
171
) -> None :
173
172
super ().__init__ (
174
- storage ,
173
+ vertex_getter = vertex_getter ,
175
174
is_dag_funds = is_dag_funds ,
176
175
is_dag_verifications = is_dag_verifications ,
177
176
is_left_to_right = is_left_to_right
@@ -200,14 +199,14 @@ class BFSOrderWalk(GenericWalk):
200
199
201
200
def __init__ (
202
201
self ,
203
- storage : VertexStorageProtocol ,
202
+ vertex_getter : Callable [[ VertexId ], Vertex ] ,
204
203
* ,
205
204
is_dag_funds : bool = False ,
206
205
is_dag_verifications : bool = False ,
207
206
is_left_to_right : bool = True ,
208
207
) -> None :
209
208
super ().__init__ (
210
- storage ,
209
+ vertex_getter = vertex_getter ,
211
210
is_dag_funds = is_dag_funds ,
212
211
is_dag_verifications = is_dag_verifications ,
213
212
is_left_to_right = is_left_to_right
@@ -231,14 +230,14 @@ class DFSWalk(GenericWalk):
231
230
232
231
def __init__ (
233
232
self ,
234
- storage : VertexStorageProtocol ,
233
+ vertex_getter : Callable [[ VertexId ], Vertex ] ,
235
234
* ,
236
235
is_dag_funds : bool = False ,
237
236
is_dag_verifications : bool = False ,
238
237
is_left_to_right : bool = True ,
239
238
) -> None :
240
239
super ().__init__ (
241
- storage ,
240
+ vertex_getter = vertex_getter ,
242
241
is_dag_funds = is_dag_funds ,
243
242
is_dag_verifications = is_dag_verifications ,
244
243
is_left_to_right = is_left_to_right
0 commit comments