|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import logging |
| 4 | +from typing import TYPE_CHECKING, ClassVar, Optional, cast |
| 5 | + |
| 6 | +if TYPE_CHECKING: |
| 7 | + from chia.server.api_protocol import ApiProtocol |
| 8 | + |
| 9 | +# Minimal imports to avoid circular dependencies |
| 10 | +from chia.protocols import harvester_protocol |
| 11 | +from chia.protocols.harvester_protocol import PlotSyncResponse |
| 12 | +from chia.protocols.outbound_message import Message |
| 13 | +from chia.protocols.protocol_message_types import ProtocolMessageTypes |
| 14 | +from chia.server.api_protocol import ApiMetadata |
| 15 | +from chia.server.ws_connection import WSChiaConnection |
| 16 | + |
| 17 | + |
| 18 | +class HarvesterApiStub: |
| 19 | + """Lightweight API stub for HarvesterAPI to break circular dependencies.""" |
| 20 | + |
| 21 | + if TYPE_CHECKING: |
| 22 | + _protocol_check: ClassVar[ApiProtocol] = cast("HarvesterApiStub", None) |
| 23 | + |
| 24 | + log: logging.Logger |
| 25 | + metadata: ClassVar[ApiMetadata] = ApiMetadata() |
| 26 | + |
| 27 | + def ready(self) -> bool: |
| 28 | + """Check if the harvester is ready.""" |
| 29 | + return True |
| 30 | + |
| 31 | + @metadata.request(peer_required=True) |
| 32 | + async def harvester_handshake( |
| 33 | + self, harvester_handshake: harvester_protocol.HarvesterHandshake, peer: WSChiaConnection |
| 34 | + ) -> None: |
| 35 | + """Handshake between the harvester and farmer.""" |
| 36 | + |
| 37 | + @metadata.request(peer_required=True) |
| 38 | + async def new_signage_point_harvester( |
| 39 | + self, new_challenge: harvester_protocol.NewSignagePointHarvester, peer: WSChiaConnection |
| 40 | + ) -> None: |
| 41 | + """Handle new signage point from farmer.""" |
| 42 | + |
| 43 | + @metadata.request(reply_types=[ProtocolMessageTypes.respond_signatures]) |
| 44 | + async def request_signatures(self, request: harvester_protocol.RequestSignatures) -> Optional[Message]: |
| 45 | + """Handle signature request from farmer.""" |
| 46 | + return None |
| 47 | + |
| 48 | + @metadata.request() |
| 49 | + async def request_plots(self, _: harvester_protocol.RequestPlots) -> Message: |
| 50 | + """Handle request for plot information.""" |
| 51 | + raise NotImplementedError("Stub method should not be called") |
| 52 | + |
| 53 | + @metadata.request() |
| 54 | + async def plot_sync_response(self, response: PlotSyncResponse) -> None: |
| 55 | + """Handle plot sync response.""" |
0 commit comments