Skip to content

Commit

Permalink
Add some parameters to compile_contract_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Dec 27, 2023
1 parent 3dceec7 commit c3b9d3e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pons/_compiler.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
from pathlib import Path
from typing import Dict, Union
from typing import Dict, Union, Mapping, Iterable

import solcx

from ._contract import CompiledContract


def compile_contract_file(path: Union[str, Path]) -> Dict[str, CompiledContract]:
def compile_contract_file(
path: Union[str, Path],
import_remappings: Mapping[str, str] = {},
optimize: bool = False,
evm_version: str = "london", # TODO: use an enum
) -> Dict[str, CompiledContract]:
path = Path(path).resolve()

compiled = solcx.compile_files([path], output_values=["abi", "bin"], evm_version="london")
compiled = solcx.compile_files(
[path],
output_values=["abi", "bin"],
evm_version=evm_version,
import_remappings=import_remappings,
optimize=optimize,
)

results = {}
for identifier, compiled_contract in compiled.items():
path, contract_name = identifier.split(":")

contract = CompiledContract.from_compiler_output(
json_abi=compiled_contract["abi"], bytecode=bytes.fromhex(compiled_contract["bin"])
json_abi=compiled_contract["abi"],
bytecode=bytes.fromhex(compiled_contract["bin"]),
)

# TODO: can we have several identical contract names in the compilation result?
results[contract_name] = contract

return results

0 comments on commit c3b9d3e

Please sign in to comment.