コード例 #1
0
ファイル: main.py プロジェクト: thanos/brownie
 def _compare_build_json(self, contract_name: str) -> bool:
     config = self._compiler_config
     # confirm that this contract was previously compiled
     try:
         source = self._sources.get(contract_name)
         build_json = self._build.get(contract_name)
     except KeyError:
         return True
     # compare source hashes
     hash_ = get_hash(source, contract_name, config["minify_source"],
                      build_json["language"])
     if build_json["sha1"] != hash_:
         return True
     # compare compiler settings
     if _compare_settings(config, build_json["compiler"]):
         return True
     if build_json["language"] == "Solidity":
         # compare solc-specific compiler settings
         if _compare_settings(config["solc"], build_json["compiler"]):
             return True
         # compare solc pragma against compiled version
         if Version(build_json["compiler"]
                    ["version"]) not in get_pragma_spec(source):
             return True
     return False
コード例 #2
0
ファイル: main.py プロジェクト: banteg/brownie
def _compare_build_json(contract_name):
    try:
        build_json = build.get(contract_name)
    except KeyError:
        return True
    return (build_json['compiler'] != CONFIG['solc']
            or build_json['sha1'] != sources.get_hash(
                contract_name, CONFIG['solc']['minify_source']))
コード例 #3
0
ファイル: main.py プロジェクト: melnaquib/brownie
 def _compare_build_json(self, contract_name):
     config = self._compiler_config
     try:
         source = self._sources.get(contract_name)
         build_json = self._build.get(contract_name)
     except KeyError:
         return True
     if build_json['sha1'] != get_hash(source, contract_name,
                                       config['minify_source']):
         return True
     return next((True for k, v in build_json['compiler'].items()
                  if config[k] and v != config[k]), False)
コード例 #4
0
ファイル: main.py プロジェクト: trnhgquan/brownie
 def _compare_build_json(self, contract_name: str) -> bool:
     config = self._compiler_config
     try:
         source = self._sources.get(contract_name)
         build_json = self._build.get(contract_name)
     except KeyError:
         return True
     if build_json["sha1"] != get_hash(
         source, contract_name, config["minify_source"], build_json["language"]
     ):
         return True
     return next(
         (True for k, v in build_json["compiler"].items() if config[k] and v != config[k]), False
     )
コード例 #5
0
 def _compare_build_json(self, contract_name: str) -> bool:
     config = self._compiler_config
     try:
         source = self._sources.get(contract_name)
         build_json = self._build.get(contract_name)
     except KeyError:
         return True
     if build_json["sha1"] != get_hash(source, contract_name,
                                       config["minify_source"],
                                       build_json["language"]):
         return True
     if _compare_settings(config, build_json["compiler"]):
         return True
     if build_json["language"] == "Solidity" and _compare_settings(
             config["solc"], build_json["compiler"]):
         return True
     return False
コード例 #6
0
def generate_build_json(input_json: Dict,
                        output_json: Dict,
                        compiler_data: Optional[Dict] = None,
                        silent: bool = True) -> Dict:
    """Formats standard compiler output to the brownie build json.

    Args:
        input_json: solc input json used to compile
        output_json: output json returned by compiler
        compiler_data: additonal data to include under 'compiler' in build json
        silent: verbose reporting

    Returns: build json dict"""

    if input_json["language"] not in ("Solidity", "Vyper"):
        raise UnsupportedLanguage(f"{input_json['language']}")

    if not silent:
        print("Generating build data...")

    if compiler_data is None:
        compiler_data = {}
    compiler_data["evm_version"] = input_json["settings"]["evmVersion"]
    minified = compiler_data.get("minify_source", False)
    build_json = {}
    path_list = list(input_json["sources"])

    if input_json["language"] == "Solidity":
        compiler_data.update({
            "optimize":
            input_json["settings"]["optimizer"]["enabled"],
            "runs":
            input_json["settings"]["optimizer"]["runs"],
        })
        source_nodes, statement_nodes, branch_nodes = solidity._get_nodes(
            output_json)

    for path_str, contract_name in [
        (k, v) for k in path_list for v in output_json["contracts"].get(k, {})
    ]:

        if not silent:
            print(f" - {contract_name}...")

        abi = output_json["contracts"][path_str][contract_name]["abi"]
        output_evm = output_json["contracts"][path_str][contract_name]["evm"]
        hash_ = sources.get_hash(
            input_json["sources"][path_str]["content"],
            contract_name,
            minified,
            input_json["language"],
        )

        if input_json["language"] == "Solidity":
            contract_node = next(i[contract_name] for i in source_nodes
                                 if i.absolutePath == path_str)
            build_json[contract_name] = solidity._get_unique_build_json(
                output_evm,
                contract_node,
                statement_nodes,
                branch_nodes,
                next((True for i in abi if i["type"] == "fallback"), False),
            )

        else:
            if contract_name == "<stdin>":
                contract_name = "Vyper"
            build_json[contract_name] = vyper._get_unique_build_json(
                output_evm,
                path_str,
                contract_name,
                output_json["sources"][path_str]["ast"],
                (0, len(input_json["sources"][path_str]["content"])),
            )

        build_json[contract_name].update({
            "abi":
            abi,
            "ast":
            output_json["sources"][path_str]["ast"],
            "compiler":
            compiler_data,
            "contractName":
            contract_name,
            "deployedBytecode":
            output_evm["deployedBytecode"]["object"],
            "deployedSourceMap":
            output_evm["deployedBytecode"]["sourceMap"],
            "language":
            input_json["language"],
            "opcodes":
            output_evm["deployedBytecode"]["opcodes"],
            "sha1":
            hash_,
            "source":
            input_json["sources"][path_str]["content"],
            "sourceMap":
            output_evm["bytecode"].get("sourceMap", ""),
            "sourcePath":
            path_str,
        })
        size = len(remove_0x_prefix(
            output_evm["deployedBytecode"]["object"])) / 2  # type: ignore
        if size > 24577:
            notify(
                "WARNING",
                f"deployed size of {contract_name} is {size} bytes, exceeds EIP-170 limit of 24577",
            )

    if not silent:
        print("")

    return build_json