Skip to content

Commit

Permalink
feat: flatten contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Dec 17, 2020
1 parent cf976fe commit a3c4b44
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ def decode_input(self, calldata: Union[str, bytes]) -> Tuple[str, Any]:

return function_sig, input_args

def flatten(self) -> str:
"""
Return a single, deployable source code for this contract.
"""
language = self._build["language"]
if language == "Vyper":
return self._build["source"]
elif language == "Solidity":
flattened_source = ""

for name in self._build["dependencies"]:
build_json = self._project._build.get(name)
offset = slice(*build_json["offset"])
source = build_json["source"][offset]
flattened_source = f"{flattened_source}\n\n{source}"

build_json = self._build
version = build_json["compiler"]["version"]
offset = slice(*build_json["offset"])
source = build_json["source"][offset]
flattened_source = f"pragma solidity {version};{flattened_source}\n\n{source}\n"

return flattened_source
else:
raise TypeError(f"Unsupported language for flattening: {language}")


class ContractContainer(_ContractBase):

Expand Down

0 comments on commit a3c4b44

Please sign in to comment.