Beispiel #1
0
class _ProjectBase:
    def __init__(self, name: str, contract_sources: Dict, project_path: Optional[Path]) -> None:
        self._path = project_path
        self._name = name
        self._sources = Sources(contract_sources)
        self._build = Build(self._sources)

    def _compile(self, sources: Dict, compiler_config: Dict, silent: bool) -> None:
        allow_paths = None
        if self._path is not None:
            allow_paths = self._path.joinpath("contracts").as_posix()
        build_json = compiler.compile_and_format(
            sources,
            solc_version=compiler_config["version"],
            optimize=compiler_config["optimize"],
            runs=compiler_config["runs"],
            evm_version=compiler_config["evm_version"],
            minify=compiler_config["minify_source"],
            silent=silent,
            allow_paths=allow_paths,
        )
        for data in build_json.values():
            if self._path is not None:
                path = self._path.joinpath(f"build/contracts/{data['contractName']}.json")
                with path.open("w") as fp:
                    json.dump(data, fp, sort_keys=True, indent=2, default=sorted)
            self._build._add(data)

    def _create_containers(self) -> None:
        # create container objects
        self._containers: Dict = {}
        for key, data in self._build.items():
            if data["bytecode"]:
                container = ContractContainer(self, data)
                self._containers[key] = container
                setattr(self, container._name, container)

    def __getitem__(self, key: str) -> ContractContainer:
        return self._containers[key]

    def __iter__(self) -> Iterator[ContractContainer]:
        return iter(self._containers[i] for i in sorted(self._containers))

    def __len__(self) -> int:
        return len(self._containers)

    def __contains__(self, item: ContractContainer) -> bool:
        return item in self._containers

    def dict(self) -> Dict:
        return dict(self._containers)

    def keys(self) -> KeysView[Any]:
        return self._containers.keys()
Beispiel #2
0
class _ProjectBase:
    def __init__(self, project_path: Optional["Path"], name: str) -> None:
        self._project_path = project_path
        self._name = name
        self._sources = Sources(project_path)
        self._build = Build(project_path, self._sources)

    def _compile(self, sources: Dict, compiler_config: Dict, silent: bool) -> None:
        build_json = compiler.compile_and_format(
            sources,
            solc_version=compiler_config["version"],
            optimize=compiler_config["optimize"],
            runs=compiler_config["runs"],
            evm_version=compiler_config["evm_version"],
            minify=compiler_config["minify_source"],
            silent=silent,
        )
        for data in build_json.values():
            self._build.add(data)

    def _create_containers(self) -> None:
        # create container objects
        self._containers: Dict = {}
        for key, data in self._build.items():
            if data["bytecode"]:
                container = ContractContainer(self, data)
                self._containers[key] = container
                setattr(self, container._name, container)

    def __getitem__(self, key: str) -> ContractContainer:
        return self._containers[key]

    def __iter__(self) -> Iterable:
        return iter(self._containers[i] for i in sorted(self._containers))

    def __len__(self) -> int:
        return len(self._containers)

    def __contains__(self, item: ContractContainer) -> bool:
        return item in self._containers

    def dict(self) -> Dict:
        return dict(self._containers)

    def keys(self) -> KeysView[Any]:
        return self._containers.keys()
Beispiel #3
0
class _ProjectBase:
    def __init__(self, project_path, name):
        self._project_path = project_path
        self._name = name
        self._sources = Sources(project_path)
        self._build = Build(project_path, self._sources)

    def _compile(self, sources, compiler_config, silent):
        build_json = compiler.compile_and_format(
            sources,
            solc_version=compiler_config['version'],
            optimize=compiler_config['optimize'],
            runs=compiler_config['runs'],
            evm_version=compiler_config['evm_version'],
            minify=compiler_config['minify_source'],
            silent=silent)
        for data in build_json.values():
            self._build.add(data)

    def _create_containers(self):
        # create container objects
        self._containers = {}
        for key, data in self._build.items():
            if data['bytecode']:
                container = ContractContainer(self, data)
                self._containers[key] = container
                setattr(self, container._name, container)

    def __getitem__(self, key):
        return self._containers[key]

    def __iter__(self):
        return iter(self._containers[i] for i in sorted(self._containers))

    def __len__(self):
        return len(self._containers)

    def __contains__(self, item):
        return item in self._containers

    def dict(self):
        return dict(self._containers)

    def keys(self):
        return self._containers.keys()