-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(etherscan directory output) #816
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome!
just tested this and works as expected.
since this is primarily etherscan related, I'd suggest we add support for this directly into ethers-etherscan::ContractMetadata instead
perhaps some like fn into_source_tree|expand() -> Result<SourceTree>
and the sourcetree (maybe a better name?) object would essentially hold path and content of all files?
and then SourceTree::write_to(dir: Path)
would dump them into a dir
Thanks for the review. All good feedback. I will poke around the etherscan module in ethers-rs and come back. |
Hey @jubos thanks for taking a stab at this PR! Wonder what your plans are for getting this over the line? Happy to help with any specific code you don't have time to write |
Planning to get it over the line this weekend. |
I made this PR to ethers-rs: gakonst/ethers-rs#990 that incorporates a lot of @mattsse's suggestions. We can discuss over there and this PR will end up being very abbreviated. |
Great! so we can drastically simplify this once merged? |
@jubos merged on ethers! |
Added this PR to centralize the error handling for unverified contracts. gakonst/ethers-rs#1065. Once that lands, can simplify this and other callsites in foundry. |
1c0ccca
to
c89f77a
Compare
* Inspired by etherscan.deth.net, this feature will expand a verified contract's source code paths to a directory for easy consumption with your favorite editor / IDE. * Tested via the following examples that test a few of the edge cases. > cargo run --bin cast -- etherscan-source 0x8d04a8c79cEB0889Bdd12acdF3Fa9D207eD3Ff63 -d blitmap This results in a directory tree with all the source files of the contract. > cargo run --bin cast -- etherscan-source 0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413 -d thedao This results in a single file output. > cargo run --bin cast -- etherscan-source 0xb5c31a0e22cae98ac08233e512bd627885aa24e5 -d output-dir This returns an error since the following contract is not verified yet on Etherscan
c89f77a
to
69d5025
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This is great @jubos! Love it. Testing Similarly, testing If the above 2 are unintended, do you mind addressing it so that there's no double directory and that all files have a .sol extension? Otherwise we're good for merge, and would encourage you to do a twitter ann of this as a feature :) |
The double directory is intended since there can be multiple top level contracts exposed by the etherscan API. I haven't encountered an example of this in the wild, but the data structure is an array, so creating a top level container directory with the name of the contract seems to be correct. FWIW, deth.net has the same behavior. On the .sol extension, this is just the pass through of the etherscan API result (which doesn't have an extension for the DAO). I will default it a .sol extension if an extension is not present as a quality of life improvement and update the commit. |
Added the .sol change to ethers-rs: gakonst/ethers-rs#1077. We could land this commit as is and then will get this improved behavior when the ether-rs commit lands. |
* Inspired by etherscan.deth.net, this feature will expand a verified contract's source code paths to a directory for easy consumption with your favorite editor / IDE. * Tested via the following examples that test a few of the edge cases. > cargo run --bin cast -- etherscan-source 0x8d04a8c79cEB0889Bdd12acdF3Fa9D207eD3Ff63 -d blitmap This results in a directory tree with all the source files of the contract. > cargo run --bin cast -- etherscan-source 0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413 -d thedao This results in a single file output. > cargo run --bin cast -- etherscan-source 0xb5c31a0e22cae98ac08233e512bd627885aa24e5 -d output-dir This returns an error since the following contract is not verified yet on Etherscan
Inspired by etherscan.deth.net, this feature will expand a verified contract's
source code paths to a directory for easy consumption with your favorite
editor / IDE.
Tested via the following examples that test a few of the edge cases.
Motivation
When learning about smart contracts it is a nice improvement to able the browse the contract code in your normal developer environment.
Solution
This feature parses the etherscan API source structure and writes it to directory.