Esempio n. 1
0
    def compile(self, crytic_compile: "CryticCompile", **_kwargs: str) -> None:
        """Run the compilation

        Args:
            crytic_compile (CryticCompile): asscoiated CryticCompile object
            **_kwargs: unused
        """
        # pylint: disable=import-outside-toplevel
        from crytic_compile.crytic_compile import get_platforms

        try:
            if isinstance(self._target, str) and os.path.isfile(self._target):
                with open(self._target, encoding="utf8") as f_target:
                    loaded_json = json.load(f_target)
            else:
                loaded_json = json.loads(self._target)
        except (OSError, ValueError):
            # Can happen if the target is a very large string, isfile will throw an exception
            loaded_json = json.loads(self._target)

        (underlying_type,
         unit_tests) = standard.load_from_compile(crytic_compile, loaded_json)
        underlying_type = TypePlatform(underlying_type)
        platforms: List[Type[AbstractPlatform]] = get_platforms()
        platform = next((p for p in platforms if p.TYPE == underlying_type),
                        Archive)
        self._underlying_platform = platform
        self._unit_tests = unit_tests
        self._target = "tmp.zip"

        crytic_compile.src_content = loaded_json["source_content"]
Esempio n. 2
0
    def compile(self, crytic_compile: "CryticCompile", **_kwargs):
        """
        Compile

        :param crytic_compile:
        :param _kwargs:
        :return:
        """
        from crytic_compile.crytic_compile import get_platforms

        if isinstance(self._target, str) and os.path.isfile(self._target):
            with open(self._target, encoding="utf8") as f_target:
                loaded_json = json.load(f_target)
        else:
            loaded_json = json.loads(self._target)
        (underlying_type,
         unit_tests) = standard.load_from_compile(crytic_compile, loaded_json)
        underlying_type = TypePlatform(underlying_type)
        platforms: List[Type[AbstractPlatform]] = get_platforms()
        platform = next((p for p in platforms if p.TYPE == underlying_type),
                        Archive)
        self._underlying_platform = platform
        self._unit_tests = unit_tests

        crytic_compile.src_content = loaded_json["source_content"]
Esempio n. 3
0
def init(parser: ArgumentParser):
    """
    Add crytic-compile arguments to the parser

    :param parser:
    :return:
    """

    group_solc = parser.add_argument_group("Compile options")

    platforms = get_platforms()

    group_solc.add_argument(
        "--compile-force-framework",
        help="Force the compile to a given framework "
        f"({','.join([x.NAME.lower() for x in platforms])})",
        action="store",
        default=DEFAULTS_FLAG_IN_CONFIG["compile_force_framework"],
    )

    group_solc.add_argument(
        "--compile-remove-metadata",
        help="Remove the metadata from the bytecodes",
        action="store_true",
        default=DEFAULTS_FLAG_IN_CONFIG["compile_remove_metadata"],
    )

    group_solc.add_argument(
        "--compile-custom-build",
        help="Replace platform specific build command",
        action="store",
        default=DEFAULTS_FLAG_IN_CONFIG["compile_custom_build"],
    )

    group_solc.add_argument(
        "--ignore-compile",
        help="Do not run compile of any platform",
        action="store_true",
        dest="ignore_compile",
        default=DEFAULTS_FLAG_IN_CONFIG["ignore_compile"],
    )

    _init_solc(parser)
    _init_truffle(parser)
    _init_embark(parser)
    _init_dapp(parser)
    _init_etherlime(parser)
    _init_etherscan(parser)
    _init_waffle(parser)
    _init_npx(parser)
    _init_buidler(parser)
    _init_hardhat(parser)
Esempio n. 4
0
    def __call__(
        self,
        parser: argparse.ArgumentParser,
        args: Any,
        values: Any,
        option_string: Optional[str] = None,
    ) -> None:
        """Action performed

        Args:
            parser (argparse.ArgumentParser): argument parser
            args (Any):  not used
            values (Any): not used
            option_string (Optional[str], optional): not used. Defaults to None.
        """
        platforms = get_platforms()
        LOGGER.info("\n" + "\n".join([f"- {x.NAME}: {x.PROJECT_URL}" for x in platforms]))
        parser.exit()
Esempio n. 5
0
    def compile(self, crytic_compile: "CryticCompile", **_kwargs: str) -> None:
        """Compile the file (load the file for the Standard platform) and populates the CryticCompile object

        Args:
            crytic_compile (CryticCompile): Associated CryticCompile
            **_kwargs: optional arguments. Not used

        """
        # pylint: disable=import-outside-toplevel
        from crytic_compile.crytic_compile import get_platforms

        with open(self._target, encoding="utf8") as file_desc:
            loaded_json = json.load(file_desc)
        (underlying_type, unit_tests) = load_from_compile(crytic_compile, loaded_json)
        underlying_type = PlatformType(underlying_type)
        platforms: List[Type[AbstractPlatform]] = get_platforms()
        platform = next((p for p in platforms if p.TYPE == underlying_type), Standard)
        self._underlying_platform = platform
        self._unit_tests = unit_tests
Esempio n. 6
0
    def compile(self, crytic_compile: "CryticCompile", **_kwargs: str):
        """
        Compile the target (load file)

        :param crytic_compile:
        :param target:
        :param kwargs:
        :return:
        """
        from crytic_compile.crytic_compile import get_platforms

        with open(self._target, encoding="utf8") as file_desc:
            loaded_json = json.load(file_desc)
        (underlying_type, unit_tests) = load_from_compile(crytic_compile, loaded_json)
        underlying_type = PlatformType(underlying_type)
        platforms: List[Type[AbstractPlatform]] = get_platforms()
        platform = next((p for p in platforms if p.TYPE == underlying_type), Standard)
        self._underlying_platform = platform
        self._unit_tests = unit_tests
Esempio n. 7
0
 def __call__(self, parser, args, values, option_string=None):
     platforms = get_platforms()
     LOGGER.info(
         "\n" +
         "\n".join([f"- {x.NAME}: {x.PROJECT_URL}" for x in platforms]))
     parser.exit()