Skip to content

Commit

Permalink
explicitly check RpcApiProtocol classes (#18786)
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky authored Oct 30, 2024
1 parent 79ba87c commit e60f7f0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
7 changes: 6 additions & 1 deletion chia/rpc/crawler_rpc_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from __future__ import annotations

import ipaddress
from typing import Any, Optional
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast

from chia.rpc.rpc_server import Endpoint, EndpointResult
from chia.seeder.crawler import Crawler
from chia.util.ws_message import WsRpcMessage, create_payload_dict


class CrawlerRpcApi:
if TYPE_CHECKING:
from chia.rpc.rpc_server import RpcApiProtocol

_protocol_check: ClassVar[RpcApiProtocol] = cast("CrawlerRpcApi", None)

def __init__(self, crawler: Crawler):
self.service = crawler
self.service_name = "chia_crawler"
Expand Down
7 changes: 6 additions & 1 deletion chia/rpc/data_layer_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dataclasses
from pathlib import Path
from typing import TYPE_CHECKING, Any, Optional, Union, cast
from typing import TYPE_CHECKING, Any, ClassVar, Optional, Union, cast

from chia.data_layer.data_layer_errors import OfferIntegrityError
from chia.data_layer.data_layer_util import (
Expand Down Expand Up @@ -89,6 +89,11 @@ def get_fee(config: dict[str, Any], request: dict[str, Any]) -> uint64:


class DataLayerRpcApi:
if TYPE_CHECKING:
from chia.rpc.rpc_server import RpcApiProtocol

_protocol_check: ClassVar[RpcApiProtocol] = cast("DataLayerRpcApi", None)

# TODO: other RPC APIs do not accept a wallet and the service start does not expect to provide one
def __init__(self, data_layer: DataLayer): # , wallet: DataLayerWallet):
self.service: DataLayer = data_layer
Expand Down
7 changes: 6 additions & 1 deletion chia/rpc/farmer_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dataclasses
import operator
from typing import Any, Callable, ClassVar, Optional
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, cast

from typing_extensions import Protocol

Expand Down Expand Up @@ -78,6 +78,11 @@ def plot_matches_filter(plot: Plot, filter_item: FilterItem) -> bool:


class FarmerRpcApi:
if TYPE_CHECKING:
from chia.rpc.rpc_server import RpcApiProtocol

_protocol_check: ClassVar[RpcApiProtocol] = cast("FarmerRpcApi", None)

def __init__(self, farmer: Farmer):
self.service = farmer
self.service_name = "chia_farmer"
Expand Down
7 changes: 6 additions & 1 deletion chia/rpc/full_node_rpc_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from datetime import datetime, timezone
from typing import Any, Optional
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast

from chia.consensus.block_record import BlockRecord
from chia.consensus.blockchain import Blockchain, BlockchainMutexPriority
Expand Down Expand Up @@ -82,6 +82,11 @@ async def get_average_block_time(


class FullNodeRpcApi:
if TYPE_CHECKING:
from chia.rpc.rpc_server import RpcApiProtocol

_protocol_check: ClassVar[RpcApiProtocol] = cast("FullNodeRpcApi", None)

def __init__(self, service: FullNode) -> None:
self.service = service
self.service_name = "chia_full_node"
Expand Down
7 changes: 6 additions & 1 deletion chia/rpc/harvester_rpc_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Optional
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast

from chia.harvester.harvester import Harvester
from chia.rpc.rpc_server import Endpoint, EndpointResult
Expand All @@ -9,6 +9,11 @@


class HarvesterRpcApi:
if TYPE_CHECKING:
from chia.rpc.rpc_server import RpcApiProtocol

_protocol_check: ClassVar[RpcApiProtocol] = cast("HarvesterRpcApi", None)

def __init__(self, harvester: Harvester):
self.service = harvester
self.service_name = "chia_harvester"
Expand Down
7 changes: 6 additions & 1 deletion chia/rpc/timelord_rpc_api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from __future__ import annotations

from typing import Any, Optional
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast

from chia.rpc.rpc_server import Endpoint
from chia.timelord.timelord import Timelord
from chia.util.ws_message import WsRpcMessage, create_payload_dict


class TimelordRpcApi:
if TYPE_CHECKING:
from chia.rpc.rpc_server import RpcApiProtocol

_protocol_check: ClassVar[RpcApiProtocol] = cast("TimelordRpcApi", None)

def __init__(self, timelord: Timelord):
self.service = timelord
self.service_name = "chia_timelord"
Expand Down
7 changes: 6 additions & 1 deletion chia/rpc/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import zlib
from pathlib import Path
from typing import Any, ClassVar, Optional, Union
from typing import TYPE_CHECKING, Any, ClassVar, Optional, Union, cast

from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey
from clvm_tools.binutils import assemble
Expand Down Expand Up @@ -165,6 +165,11 @@


class WalletRpcApi:
if TYPE_CHECKING:
from chia.rpc.rpc_server import RpcApiProtocol

_protocol_check: ClassVar[RpcApiProtocol] = cast("WalletRpcApi", None)

max_get_coin_records_limit: ClassVar[uint32] = uint32(1000)
max_get_coin_records_filter_items: ClassVar[uint32] = uint32(1000)

Expand Down

0 comments on commit e60f7f0

Please sign in to comment.