-
Notifications
You must be signed in to change notification settings - Fork 796
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(solc): Use IndexedPathBuf for CompilerInput Sources #1151
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.
it seems that this is primarily for verification?
Are there any other advantages, because this touches a lot of internal code and indexedpath is only needed for verification?
I've been thinking a bit about how to implement this, but haven't gotten around to writing it down yet.
What if we make the standard_json
function return a new type that acts like a CompilerInput
but seriealises with sorted sources? basically your IndexedPath apporach
the index would probably come from the graph, imported_nodes
I think? So I think we can make sources: Vec<(PathBuf, Source)
, which is serialised as map
ref https://serde.rs/impl-serialize.html#serializing-a-sequence-or-map
Yess
I believe this only useful for verification only
Do you mean I think if we can change the return of |
Yeah I'd say let's try to make it sort only when serializing in a non invasive way if possible! |
@gakonst ok, noted 🙇 |
Motivation
Based on foundry-rs/foundry#1283 it seems that Etherscan is not automatically detect main contract to be displayed as the first source on the list.
After learning how
hardhat-etherscan
verification works turns out that hardhat always place the main contract as the first key of thesources
.This behaviour is currently not possible in
ethers-solc
due to CompilerInput sources is usingBTreeMap<PathBuf, Source>
. When compiler input is serialized as JSON, it always ordered alphabetically (PathBuf
default), not by their insertion order.Solution
This changes propose
Sources
to be defined asBTreeMap<IndexedPathBuf, Source>
instead ofBTreeMap<PathBuf, Source>
.IndexedPathBuf
containsindex
field which we can use to determine how the key is sorted by just simply assign theindex
value.In the case of verification, the
sources
key will be ordered by source code for main contract first then followed by the imported source codes.Results:
(
SimpleERC20
is on top of the list and followed by the imports)PR Checklist