Skip to content

Commit

Permalink
Merge pull request #95 from Chia-Network/develop
Browse files Browse the repository at this point in the history
Release: 1.0.23
  • Loading branch information
MichaelTaylor3D authored Sep 19, 2023
2 parents 901c999 + c2c1a94 commit 16b6c60
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
26 changes: 18 additions & 8 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
4 changes: 4 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"Chia Network Inc <[email protected]>"]
Expand Down

0 comments on commit 16b6c60

Please sign in to comment.