diff --git a/ethers-solc/src/compile/output/contracts.rs b/ethers-solc/src/compile/output/contracts.rs index 6a2f0873..f8de71b2 100644 --- a/ethers-solc/src/compile/output/contracts.rs +++ b/ethers-solc/src/compile/output/contracts.rs @@ -166,6 +166,28 @@ impl VersionedContracts { }) } + /// Returns an iterator over (`file`, `name`, `Contract`) + pub fn into_contracts_with_files(self) -> impl Iterator { + self.0.into_iter().flat_map(|(file, contracts)| { + contracts.into_iter().flat_map(move |(name, c)| { + let file = file.clone(); + c.into_iter().map(move |c| (file.clone(), name.clone(), c.contract)) + }) + }) + } + + /// Returns an iterator over (`file`, `name`, `Contract`, `Version`) + pub fn into_contracts_with_files_and_version( + self, + ) -> impl Iterator { + self.0.into_iter().flat_map(|(file, contracts)| { + contracts.into_iter().flat_map(move |(name, c)| { + let file = file.clone(); + c.into_iter().map(move |c| (file.clone(), name.clone(), c.contract, c.version)) + }) + }) + } + /// Sets the contract's file paths to `root` adjoined to `self.file`. pub fn join_all(&mut self, root: impl AsRef) -> &mut Self { let root = root.as_ref(); diff --git a/ethers-solc/src/compile/output/mod.rs b/ethers-solc/src/compile/output/mod.rs index c7e10779..4724cf7f 100644 --- a/ethers-solc/src/compile/output/mod.rs +++ b/ethers-solc/src/compile/output/mod.rs @@ -388,6 +388,32 @@ impl AggregatedCompilerOutput { self.contracts.into_contracts() } + /// Returns an iterator over (`file`, `name`, `Contract`) + pub fn contracts_with_files_iter(&self) -> impl Iterator { + self.contracts.contracts_with_files() + } + + /// Returns an iterator over (`file`, `name`, `Contract`) + pub fn contracts_with_files_into_iter( + self, + ) -> impl Iterator { + self.contracts.into_contracts_with_files() + } + + /// Returns an iterator over (`file`, `name`, `Contract`, `Version`) + pub fn contracts_with_files_and_version_iter( + &self, + ) -> impl Iterator { + self.contracts.contracts_with_files_and_version() + } + + /// Returns an iterator over (`file`, `name`, `Contract`, `Version`) + pub fn contracts_with_files_and_version_into_iter( + self, + ) -> impl Iterator { + self.contracts.into_contracts_with_files_and_version() + } + /// Given the contract file's path and the contract's name, tries to return the contract's /// bytecode, runtime bytecode, and abi /// # Example