From faba6e014da854e296d095541679e852e2288eec Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Sun, 13 Feb 2022 11:47:00 -0800 Subject: [PATCH] feat: add getter to `ProjectCompileOutput` (#908) * 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 --- CHANGELOG.md | 3 +++ ethers-solc/src/compile/output.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be90c928..8c88bab8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/ethers-solc/src/compile/output.rs b/ethers-solc/src/compile/output.rs index 3cd0a9dc..c3bed6dd 100644 --- a/ethers-solc/src/compile/output.rs +++ b/ethers-solc/src/compile/output.rs @@ -141,6 +141,22 @@ impl ProjectCompileOutput { pub fn compiled_artifacts(&self) -> &Artifacts { &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> { + 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 ProjectCompileOutput