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))) }) }