Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
feat: add getter to ProjectCompileOutput (#908)
Browse files Browse the repository at this point in the history
* feat: add getter to `ProjectCompileOutput`

Add a function `compiled_contracts_by_compiler_version`
to the `ProjectCompileOutput` that returns a `BTreeMap`
that maps the compiler version to a vector of the contract
names and contract structs.

* changelog: update

* chore(solc): remove &mut

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
  • Loading branch information
tynes and gakonst authored Feb 13, 2022
1 parent 27a4454 commit faba6e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
so that the receipt can be returned to the called when deploying
a contract [#865](https://github.com/gakonst/ethers-rs/pull/865)
- Add Arbitrum mainnet and testnet to the list of known chains
- Add a getter to `ProjectCompileOutput` that returns a mapping of compiler
versions to a vector of name + contract struct tuples
[#908](https://github.com/gakonst/ethers-rs/pull/908)

## ethers-contract-abigen

Expand Down
16 changes: 16 additions & 0 deletions ethers-solc/src/compile/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ impl<T: ArtifactOutput> ProjectCompileOutput<T> {
pub fn compiled_artifacts(&self) -> &Artifacts<T::Artifact> {
&self.compiled_artifacts
}

/// Returns a `BTreeMap` that maps the compiler version used during [`Project::compile()`]
/// to a Vector of tuples containing the contract name and the `Contract`
pub fn compiled_contracts_by_compiler_version(
&self,
) -> BTreeMap<Version, Vec<(String, Contract)>> {
let mut contracts = BTreeMap::new();
let versioned_contracts = &self.compiler_output.contracts;
for (_, name, contract, version) in versioned_contracts.contracts_with_files_and_version() {
contracts
.entry(version.to_owned())
.or_insert(Vec::<(String, Contract)>::new())
.push((name.to_string(), contract.clone()));
}
contracts
}
}

impl<T: ArtifactOutput> ProjectCompileOutput<T>
Expand Down

0 comments on commit faba6e0

Please sign in to comment.