-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some parameters to compile_contract_file()
- Loading branch information
Showing
1 changed file
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |