Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: flatten contracts #896

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
flattened_source = f"pragma solidity {version};{flattened_source}\n\n{source}\n"
flattened_source = f"pragma solidity {version};\n\n{flattened_source}\n\n{source}\n"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's handled in line 144


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


class ContractContainer(_ContractBase):

Expand Down