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

feat: flatten contracts #896

wants to merge 1 commit into from

Conversation

iamdefinitelyahuman
Copy link
Member

What I did

Add functionality for flattening a contract.

Macarse
Macarse previously approved these changes Dec 17, 2020
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

@Macarse
Copy link
Contributor

Macarse commented Dec 18, 2020

This can be tested without deploying a new version.
Open a brownie terminal and use the contract like this:

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

build_json = my_contract._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"

f = open( 'output.sol', 'w' )
f.write(flattened_source)
f.close()

@Macarse
Copy link
Contributor

Macarse commented Dec 26, 2020

@iamdefinitelyahuman you force pushed a rebase?

@matnad
Copy link
Collaborator

matnad commented Jan 8, 2021

Commit included in #914. Closing this.

@matnad matnad closed this Jan 8, 2021
@iamdefinitelyahuman iamdefinitelyahuman deleted the feat-flatten branch March 7, 2021 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants