feat(solc): add more contract iter helper functions (#1438)

This commit is contained in:
0xYYY 2022-07-01 00:17:56 +08:00 committed by GitHub
parent 9892756ee4
commit ca34d0c049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View File

@ -166,6 +166,28 @@ impl VersionedContracts {
}) })
} }
/// Returns an iterator over (`file`, `name`, `Contract`)
pub fn into_contracts_with_files(self) -> impl Iterator<Item = (String, String, Contract)> {
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<Item = (String, String, Contract, Version)> {
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`. /// Sets the contract's file paths to `root` adjoined to `self.file`.
pub fn join_all(&mut self, root: impl AsRef<Path>) -> &mut Self { pub fn join_all(&mut self, root: impl AsRef<Path>) -> &mut Self {
let root = root.as_ref(); let root = root.as_ref();

View File

@ -388,6 +388,32 @@ impl AggregatedCompilerOutput {
self.contracts.into_contracts() self.contracts.into_contracts()
} }
/// Returns an iterator over (`file`, `name`, `Contract`)
pub fn contracts_with_files_iter(&self) -> impl Iterator<Item = (&String, &String, &Contract)> {
self.contracts.contracts_with_files()
}
/// Returns an iterator over (`file`, `name`, `Contract`)
pub fn contracts_with_files_into_iter(
self,
) -> impl Iterator<Item = (String, String, Contract)> {
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<Item = (&String, &String, &Contract, &Version)> {
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<Item = (String, String, Contract, Version)> {
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 /// Given the contract file's path and the contract's name, tries to return the contract's
/// bytecode, runtime bytecode, and abi /// bytecode, runtime bytecode, and abi
/// # Example /// # Example