8
8
from concurrent .futures .thread import ThreadPoolExecutor
9
9
from pathlib import Path
10
10
from typing import TYPE_CHECKING , Any , ClassVar , Optional , cast
11
+
11
12
from chia_rs import ConsensusConstants
12
- from chia . protocols . solver_protocol import SolverInfo
13
+
13
14
from chia .protocols .outbound_message import NodeType
15
+ from chia .protocols .solver_protocol import SolverInfo
14
16
from chia .rpc .rpc_server import StateChangedProtocol , default_get_connections
15
17
from chia .server .server import ChiaServer
16
18
from chia .server .ws_connection import WSChiaConnection
17
19
18
-
19
20
log = logging .getLogger (__name__ )
20
21
21
22
22
23
class Solver :
23
24
if TYPE_CHECKING :
24
25
from chia .rpc .rpc_server import RpcServiceProtocol
26
+
25
27
_protocol_check : ClassVar [RpcServiceProtocol ] = cast ("Solver" , None )
26
28
27
29
root_path : Path
28
- _server : Optional [ChiaServer ]
30
+ _server : Optional [ChiaServer ]
29
31
_shut_down : bool
30
32
started : bool = False
31
33
executor : ThreadPoolExecutor
32
34
state_changed_callback : Optional [StateChangedProtocol ] = None
33
35
constants : ConsensusConstants
34
36
event_loop : asyncio .events .AbstractEventLoop
35
-
36
-
37
37
38
38
@property
39
- def server (self ) -> ChiaServer :
39
+ def server (self ) -> ChiaServer :
40
40
if self ._server is None :
41
41
raise RuntimeError ("server not assigned" )
42
42
@@ -52,8 +52,6 @@ def __init__(self, root_path: Path, config: dict[str, Any], constants: Consensus
52
52
self ._server = None
53
53
self .constants = constants
54
54
self .state_changed_callback : Optional [StateChangedProtocol ] = None
55
-
56
-
57
55
58
56
@contextlib .asynccontextmanager
59
57
async def manage (self ) -> AsyncIterator [None ]:
@@ -63,7 +61,7 @@ async def manage(self) -> AsyncIterator[None]:
63
61
finally :
64
62
self ._shut_down = True
65
63
66
- def solve (self , info : SolverInfo ) -> Optional [bytes ]:
64
+ def solve (self , info : SolverInfo ) -> Optional [bytes ]:
67
65
return None
68
66
69
67
def get_connections (self , request_node_type : Optional [NodeType ]) -> list [dict [str , Any ]]:
@@ -72,14 +70,11 @@ def get_connections(self, request_node_type: Optional[NodeType]) -> list[dict[st
72
70
async def on_connect (self , connection : WSChiaConnection ) -> None :
73
71
pass
74
72
75
-
76
73
async def on_disconnect (self , connection : WSChiaConnection ) -> None :
77
74
self .log .info (f"peer disconnected { connection .get_peer_logging ()} " )
78
-
79
75
80
76
def set_server (self , server : ChiaServer ) -> None :
81
77
self ._server = server
82
78
83
79
def _set_state_changed_callback (self , callback : StateChangedProtocol ) -> None :
84
80
self .state_changed_callback = callback
85
-
0 commit comments