diff --git a/python/src/skale_contracts/project.py b/python/src/skale_contracts/project.py index 8be3bf7..5352cba 100644 --- a/python/src/skale_contracts/project.py +++ b/python/src/skale_contracts/project.py @@ -11,22 +11,32 @@ if TYPE_CHECKING: from eth_typing import Address from .network import Network - from .project_metadata import ProjectMetadata class Project(ABC): """Represents set of smart contracts known as project""" - def __init__(self, network: Network, metadata: ProjectMetadata) -> None: + def __init__(self, network: Network) -> None: super().__init__() self.network = network - self._metadata = metadata + + @staticmethod + @abstractmethod + def name() -> str: + """Name of the project""" @property @abstractmethod def github_repo(self) -> str: """URL of github repo with the project""" + + @property + def folder(self) -> str: + """Folder name with instances json files""" + return self.name() + + def get_instance(self, alias_or_address: str) -> Instance: """Create instance object based on alias or address""" if self.network.web3.is_address(alias_or_address): @@ -63,7 +73,7 @@ def get_instance_data_url(self, alias: str) -> str: """Get URL of a file containing address for provided alias""" if self.network.is_listed(): return f'{REPOSITORY_URL}{self.network.as_listed().path}/' + \ - f'{self._metadata.path}/{alias}.json' + f'{self.folder}/{alias}.json' raise ValueError('Network is unknown') @abstractmethod diff --git a/python/src/skale_contracts/project_factory.py b/python/src/skale_contracts/project_factory.py index 8626b0b..1446669 100644 --- a/python/src/skale_contracts/project_factory.py +++ b/python/src/skale_contracts/project_factory.py @@ -2,33 +2,25 @@ from __future__ import annotations from typing import TYPE_CHECKING -from attr import dataclass +import inspect +from .project import Project from . import projects -from .project_metadata import ProjectMetadata if TYPE_CHECKING: - from .project import Project from .network import Network -@dataclass -class Projects: - """Contains all known projects""" - skale_manager = ProjectMetadata(name='skale-manager', path='skale-manager') - mainnet_ima = ProjectMetadata(name='mainnet-ima', path='mainnet-ima') - schain_ima = ProjectMetadata(name='schain-ima', path='schain-ima') - skale_allocator = ProjectMetadata(name='skale-allocator', path='skale-allocator') +projects_dict = { + class_type.name(): class_type + for _, class_type + in inspect.getmembers(projects, inspect.isclass) + if issubclass(class_type, Project) +} def create_project(network: Network, name: str) -> Project: """Create Project object based on it's name""" - if name == Projects.skale_manager.name: - return projects.SkaleManager(network, Projects.skale_manager) - if name == Projects.mainnet_ima.name: - return projects.MainnetIma(network, Projects.mainnet_ima) - if name == Projects.schain_ima.name: - return projects.SchainIma(network, Projects.schain_ima) - if name == Projects.skale_allocator.name: - return projects.SkaleAllocator(network, Projects.skale_allocator) + if name in projects_dict: + return projects_dict[name](network) raise ValueError(f'Project with name {name} is unknown') diff --git a/python/src/skale_contracts/project_metadata.py b/python/src/skale_contracts/project_metadata.py deleted file mode 100644 index 96435a8..0000000 --- a/python/src/skale_contracts/project_metadata.py +++ /dev/null @@ -1,4 +0,0 @@ -"""Tools for project metadata processing""" -from collections import namedtuple - -ProjectMetadata = namedtuple('ProjectMetadata', ['name', 'path']) diff --git a/python/src/skale_contracts/projects/ima.py b/python/src/skale_contracts/projects/ima.py index cab97be..be4f89f 100644 --- a/python/src/skale_contracts/projects/ima.py +++ b/python/src/skale_contracts/projects/ima.py @@ -30,9 +30,7 @@ def __init__(self, project: Project, address: Address) -> None: class ImaProject(Project): """Represents IMA project""" - @property - def github_repo(self) -> str: - return 'https://github.com/skalenetwork/ima/' + github_repo = 'https://github.com/skalenetwork/ima/' class MainnetImaInstance(ImaInstance): @@ -74,6 +72,10 @@ def contract_manager(self) -> Contract: class MainnetImaProject(ImaProject): """Represents mainnet part of IMA project""" + @staticmethod + def name() -> str: + return 'mainnet-ima' + def create_instance(self, address: Address) -> Instance: return MainnetImaInstance(self, address) @@ -107,6 +109,10 @@ def get_contract_address(self, name: str, *args: str|Address|ChecksumAddress) -> class SchainImaProject(ImaProject): """Represents schain part of IMA project""" + @staticmethod + def name() -> str: + return 'schain-ima' + def get_instance(self, alias_or_address: str) -> Instance: if alias_or_address == PREDEPLOYED_ALIAS: return self.create_instance(SchainImaInstance.PREDEPLOYED['MessageProxyForSchain']) diff --git a/python/src/skale_contracts/projects/skale_allocator.py b/python/src/skale_contracts/projects/skale_allocator.py index 952a3e1..1075ac9 100644 --- a/python/src/skale_contracts/projects/skale_allocator.py +++ b/python/src/skale_contracts/projects/skale_allocator.py @@ -38,9 +38,10 @@ def _get_escrow (self, beneficiary: Address) -> Address: class SkaleAllocatorProject(Project): """Represents skale-allocator project""" - @property - def github_repo(self) -> str: - return 'https://github.com/skalenetwork/skale-allocator/' + @staticmethod + def name() -> str: + return 'skale-allocator' + github_repo = 'https://github.com/skalenetwork/skale-allocator/' def create_instance(self, address: Address) -> Instance: return SkaleAllocatorInstance(self, address) diff --git a/python/src/skale_contracts/projects/skale_manager.py b/python/src/skale_contracts/projects/skale_manager.py index 0733df8..b6737a5 100644 --- a/python/src/skale_contracts/projects/skale_manager.py +++ b/python/src/skale_contracts/projects/skale_manager.py @@ -62,9 +62,10 @@ def _actual_name(self, name: str) -> str: class SkaleManagerProject(Project): """Represents skale-manager project""" - @property - def github_repo(self) -> str: - return 'https://github.com/skalenetwork/skale-manager/' + @staticmethod + def name() -> str: + return 'skale-manager' + github_repo = 'https://github.com/skalenetwork/skale-manager/' def create_instance(self, address: Address) -> Instance: return SkaleManagerInstance(self, address)