From 3ee1b6796ed66079851ca8238e63f822466571ad Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 28 Sep 2022 20:58:12 +0200 Subject: [PATCH] feat(solc): add versioned artifacts helper (#1752) --- ethers-solc/src/compile/output/mod.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ethers-solc/src/compile/output/mod.rs b/ethers-solc/src/compile/output/mod.rs index f5e0f959..57198cb0 100644 --- a/ethers-solc/src/compile/output/mod.rs +++ b/ethers-solc/src/compile/output/mod.rs @@ -80,11 +80,30 @@ impl ProjectCompileOutput { /// let artifacts: BTreeMap = project.compile().unwrap().artifacts().collect(); /// ``` pub fn artifacts(&self) -> impl Iterator { + self.versioned_artifacts().map(|(name, (artifact, _))| (name, artifact)) + } + + /// This returns a chained iterator of both cached and recompiled contract artifacts that yields + /// the contract name and the corresponding artifact + /// + /// # Example + /// + /// ```no_run + /// use std::collections::btree_map::BTreeMap; + /// use semver::Version; + /// use ethers_solc::ConfigurableContractArtifact; + /// use ethers_solc::Project; + /// + /// let project = Project::builder().build().unwrap(); + /// let artifacts: BTreeMap = project.compile().unwrap().versioned_artifacts().collect(); + /// ``` + pub fn versioned_artifacts(&self) -> impl Iterator { self.cached_artifacts .artifact_files() .chain(self.compiled_artifacts.artifact_files()) .filter_map(|artifact| { - T::contract_name(&artifact.file).map(|name| (name, &artifact.artifact)) + T::contract_name(&artifact.file) + .map(|name| (name, (&artifact.artifact, &artifact.version))) }) }