1
1
from __future__ import annotations
2
2
3
- from abc import ABC , abstractmethod
4
3
from enum import IntEnum
5
- from pathlib import Path
6
- from typing import TYPE_CHECKING
4
+ from typing import TYPE_CHECKING , ClassVar , Protocol , cast
7
5
8
6
from chia_rs .sized_bytes import bytes32
9
7
from chia_rs .sized_ints import uint8
@@ -20,62 +18,30 @@ class PlotVersion(IntEnum):
20
18
V2 = 2
21
19
22
20
23
- class ProverProtocol (ABC ):
24
- @abstractmethod
25
- def get_filepath (self ) -> Path :
26
- """Returns the filename for the plot"""
27
-
28
- @abstractmethod
29
- def get_filename (self ) -> str :
30
- """Returns the filename string for the plot"""
31
-
32
- @abstractmethod
33
- def get_size (self ) -> uint8 :
34
- """Returns the k size of the plot"""
35
-
36
- @abstractmethod
37
- def get_memo (self ) -> bytes :
38
- """Returns the memo"""
39
-
40
- @abstractmethod
41
- def get_compression_level (self ) -> uint8 :
42
- """Returns the compression level"""
43
-
44
- @abstractmethod
45
- def get_version (self ) -> PlotVersion :
46
- """Returns the plot version"""
47
-
48
- @abstractmethod
49
- def __bytes__ (self ) -> bytes :
50
- """Returns the prover bytes"""
51
-
52
- @abstractmethod
53
- def get_id (self ) -> bytes32 :
54
- """Returns the plot ID"""
55
-
56
- @abstractmethod
57
- def get_qualities_for_challenge (self , challenge : bytes32 ) -> list [bytes32 ]:
58
- """Returns the qualities for a given challenge"""
59
-
60
- @abstractmethod
61
- def get_full_proof (self , challenge : bytes , index : int , parallel_read : bool = True ) -> bytes :
62
- """Returns the full proof for a given challenge and index"""
21
+ class ProverProtocol (Protocol ):
22
+ def get_filename (self ) -> str : ...
23
+ def get_size (self ) -> uint8 : ...
24
+ def get_memo (self ) -> bytes : ...
25
+ def get_compression_level (self ) -> uint8 : ...
26
+ def get_version (self ) -> PlotVersion : ...
27
+ def __bytes__ (self ) -> bytes : ...
28
+ def get_id (self ) -> bytes32 : ...
29
+ def get_qualities_for_challenge (self , challenge : bytes32 ) -> list [bytes32 ]: ...
30
+ def get_full_proof (self , challenge : bytes , index : int , parallel_read : bool = True ) -> bytes : ...
63
31
64
32
@classmethod
65
- @abstractmethod
66
- def from_bytes (cls , data : bytes ) -> ProverProtocol :
67
- """Create a prover from serialized bytes"""
33
+ def from_bytes (cls , data : bytes ) -> ProverProtocol : ...
68
34
69
35
70
- class V2Prover (ProverProtocol ):
71
- """V2 Plot Prover stubb"""
36
+ class V2Prover :
37
+ """Placeholder for future V2 plot format support"""
38
+
39
+ if TYPE_CHECKING :
40
+ _protocol_check : ClassVar [ProverProtocol ] = cast ("V2Prover" , None )
72
41
73
42
def __init__ (self , filename : str ):
74
43
self ._filename = filename
75
44
76
- def get_filepath (self ) -> Path :
77
- return Path (self ._filename )
78
-
79
45
def get_filename (self ) -> str :
80
46
return str (self ._filename )
81
47
@@ -102,29 +68,29 @@ def get_id(self) -> bytes32:
102
68
# TODO: Extract plot ID from V2 plot file
103
69
raise NotImplementedError ("V2 plot format is not yet implemented" )
104
70
105
- def get_qualities_for_challenge (self , _challenge : bytes ) -> list [bytes32 ]:
71
+ def get_qualities_for_challenge (self , challenge : bytes ) -> list [bytes32 ]:
106
72
# TODO: todo_v2_plots Implement plot quality lookup
107
73
raise NotImplementedError ("V2 plot format is not yet implemented" )
108
74
109
- def get_full_proof (self , _challenge : bytes , _index : int , _parallel_read : bool = True ) -> bytes :
75
+ def get_full_proof (self , challenge : bytes , index : int , parallel_read : bool = True ) -> bytes :
110
76
# TODO: todo_v2_plots Implement plot proof generation
111
77
raise NotImplementedError ("V2 plot format is not yet implemented" )
112
78
113
79
@classmethod
114
- def from_bytes (cls , _data : bytes ) -> V2Prover :
80
+ def from_bytes (cls , data : bytes ) -> V2Prover :
115
81
# TODO: todo_v2_plots Implement prover deserialization from cache
116
82
raise NotImplementedError ("V2 plot format is not yet implemented" )
117
83
118
84
119
- class V1Prover ( ProverProtocol ) :
85
+ class V1Prover :
120
86
"""Wrapper for existing DiskProver to implement ProverProtocol"""
121
87
88
+ if TYPE_CHECKING :
89
+ _protocol_check : ClassVar [ProverProtocol ] = cast ("V1Prover" , None )
90
+
122
91
def __init__ (self , disk_prover : DiskProver ) -> None :
123
92
self ._disk_prover = disk_prover
124
93
125
- def get_filepath (self ) -> Path :
126
- return Path (self ._disk_prover .get_filename ())
127
-
128
94
def get_filename (self ) -> str :
129
95
return str (self ._disk_prover .get_filename ())
130
96
0 commit comments