diff --git a/app/config.py b/app/config.py index b58c6c3..b4ecedc 100644 --- a/app/config.py +++ b/app/config.py @@ -7,14 +7,12 @@ import yaml from pydantic import BaseSettings, root_validator, validator - class ExecutionMode(enum.Enum): DEV = "dev" REGISTRY = "registry" CLIENT = "client" EXPLORER = "explorer" - class ServerPort(enum.Enum): DEV = 31999 CLIMATE_WAREHOUSE = 31310 @@ -51,20 +49,31 @@ class Settings(BaseSettings): CHIA_HOSTNAME: str = "localhost" CHIA_FULL_NODE_RPC_PORT: int = 8555 CHIA_WALLET_RPC_PORT: int = 9256 + CLIMATE_EXPLORER_PORT: Optional[int] = None + CLIMATE_TOKEN_CLIENT_PORT: Optional[int] = None + CLIMATE_TOKEN_REGISTRY_PORT: Optional[int] = None + DEV_PORT: Optional[int] = None + + @classmethod + def get_instance(cls): + if cls._instance is None: + cls._instance = get_settings() + return cls._instance @root_validator def configure_port(cls, values): if values["MODE"] == ExecutionMode.REGISTRY: - values["SERVER_PORT"] = ServerPort.CLIMATE_TOKEN_REGISTRY.value + values["SERVER_PORT"] = values.get('CLIMATE_TOKEN_REGISTRY_PORT', ServerPort.CLIMATE_TOKEN_REGISTRY.value) elif values["MODE"] == ExecutionMode.CLIENT: - values["SERVER_PORT"] = ServerPort.CLIMATE_TOKEN_CLIENT.value + values["SERVER_PORT"] = values.get('CLIMATE_TOKEN_CLIENT_PORT', ServerPort.CLIMATE_TOKEN_CLIENT.value) elif values["MODE"] == ExecutionMode.EXPLORER: - values["SERVER_PORT"] = ServerPort.CLIMATE_EXPLORER.value + values["SERVER_PORT"] = values.get('CLIMATE_EXPLORER_PORT', ServerPort.CLIMATE_EXPLORER.value) elif values["MODE"] == ExecutionMode.DEV: - values["SERVER_PORT"] = ServerPort.DEV.value + values["SERVER_PORT"] = values.get('DEV_PORT', ServerPort.DEV.value) else: raise ValueError(f"Invalid mode {values['MODE']}!") - + + print(f"Set SERVER_PORT to {values['SERVER_PORT']}") return values @validator("CHIA_ROOT", pre=True) @@ -105,8 +114,9 @@ def get_settings() -> Settings: settings_dict = default_settings.dict() | (settings_dict or {}) settings = Settings(**settings_dict) + Settings._instance = Settings(**settings_dict) - return settings + return Settings._instance settings = get_settings() diff --git a/config.yaml b/config.yaml index a01c79b..6e77c57 100644 --- a/config.yaml +++ b/config.yaml @@ -10,3 +10,7 @@ CHIA_HOSTNAME: localhost CHIA_FULL_NODE_RPC_PORT: 8555 CHIA_WALLET_RPC_PORT: 9256 DEFAULT_FEE: 1000000000 # mojos +CLIMATE_TOKEN_REGISTRY_PORT: 31312 +CLIMATE_EXPLORER_PORT: 31313 +CLIMATE_TOKEN_CLIENT_PORT: 31314 +DEV_PORT: 31999 diff --git a/pyproject.toml b/pyproject.toml index ade567a..4d96ce7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "Chia Climate Token Driver" -version = "1.0.23" +version = "1.0.24" description = "https://github.com/Chia-Network/climate-token-driver" authors = ["Harry Hsu ", "Chia Network Inc "]