3
3
import dataclasses
4
4
from collections .abc import Collection
5
5
from contextlib import AbstractAsyncContextManager
6
- from pathlib import Path
7
- from typing import Optional
6
+ from typing import TYPE_CHECKING , Optional
8
7
9
8
import aiosqlite
10
9
from chia_rs import BlockRecord , FullBlock , SubEpochChallengeSegment , SubEpochSummary
11
10
from chia_rs .sized_bytes import bytes32
12
11
from chia_rs .sized_ints import uint32 , uint64
12
+ from typing_extensions import Self
13
13
14
14
from chia .consensus .block_height_map import BlockHeightMap
15
- from chia .consensus .consensus_store_protocol import ConsensusStoreProtocol
16
15
from chia .full_node .block_store import BlockStore
17
16
from chia .full_node .coin_store import CoinStore
18
17
from chia .types .blockchain_format .coin import Coin
19
18
from chia .types .coin_record import CoinRecord
20
- from chia .util .db_wrapper import DBWrapper2
21
19
22
20
23
21
@dataclasses .dataclass
24
- class ConsensusStoreSQLite3 ( ConsensusStoreProtocol ) :
22
+ class ConsensusStoreSQLite3 :
25
23
"""
26
24
Consensus store that combines block_store, coin_store, and height_map functionality.
27
25
"""
@@ -36,7 +34,7 @@ async def create(
36
34
block_store : BlockStore ,
37
35
coin_store : CoinStore ,
38
36
height_map : BlockHeightMap ,
39
- ) -> ConsensusStoreSQLite3 :
37
+ ) -> Self :
40
38
"""Create a new ConsensusStore instance from existing sub-stores.
41
39
42
40
This factory does not create sub-stores. Construct BlockStore, CoinStore,
@@ -158,23 +156,12 @@ async def maybe_flush_height_map(self) -> None:
158
156
await self .height_map .maybe_flush ()
159
157
160
158
161
- async def build_consensus_store (
162
- db_wrapper : DBWrapper2 ,
163
- blockchain_dir : Path ,
164
- selected_network : Optional [str ] = None ,
165
- * ,
166
- use_cache : bool = True ,
167
- ) -> ConsensusStoreSQLite3 :
168
- """Convenience utility to construct a ConsensusStore from DB and path.
159
+ if TYPE_CHECKING :
160
+ # here we validate that ConsensusStoreSQLite3 implements ConsensusStoreProtocol
161
+ from typing import cast
169
162
170
- This keeps ConsensusStore.create minimal (only accepts sub-stores) while still
171
- providing a one-stop helper for callers that need to create the sub-stores.
172
- """
173
- block_store = await BlockStore .create (db_wrapper , use_cache = use_cache )
174
- coin_store = await CoinStore .create (db_wrapper )
175
- height_map = await BlockHeightMap .create (blockchain_dir , db_wrapper , selected_network )
176
- return await ConsensusStoreSQLite3 .create (block_store , coin_store , height_map )
163
+ from chia .consensus .consensus_store_protocol import ConsensusStoreProtocol
177
164
165
+ def _protocol_check (_ : ConsensusStoreProtocol ): ...
178
166
179
- # Backwards-compatible alias
180
- ConsensusStore = ConsensusStoreSQLite3
167
+ _protocol_check (cast (ConsensusStoreSQLite3 , None ))
0 commit comments