mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-05-01 15:47:55 +00:00
497dae2494
The differential testing framework will make a second consumer. There seems to be no re-usable Rust crate for this. But we already have everything here, just needs a small refactor to make it fully re-usable. - Mostly decouple the solc JSON-input-output interface types from the `solidity` frontend crate - Expose the JSON-input-output interface types in a dedicated crate --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
//! The missing Solidity libraries.
|
|
|
|
use std::collections::BTreeMap;
|
|
use std::collections::HashSet;
|
|
|
|
use revive_solc_json_interface::SolcStandardJsonOutput;
|
|
|
|
use crate::solc::version::Version as SolcVersion;
|
|
use crate::ResolcVersion;
|
|
|
|
/// The missing Solidity libraries.
|
|
pub struct MissingLibraries {
|
|
/// The missing libraries.
|
|
pub contract_libraries: BTreeMap<String, HashSet<String>>,
|
|
}
|
|
|
|
impl MissingLibraries {
|
|
/// A shortcut constructor.
|
|
pub fn new(contract_libraries: BTreeMap<String, HashSet<String>>) -> Self {
|
|
Self { contract_libraries }
|
|
}
|
|
|
|
/// Writes the missing libraries to the standard JSON.
|
|
pub fn write_to_standard_json(
|
|
mut self,
|
|
standard_json: &mut SolcStandardJsonOutput,
|
|
solc_version: &SolcVersion,
|
|
) -> anyhow::Result<()> {
|
|
let contracts = match standard_json.contracts.as_mut() {
|
|
Some(contracts) => contracts,
|
|
None => return Ok(()),
|
|
};
|
|
|
|
for (path, contracts) in contracts.iter_mut() {
|
|
for (name, contract) in contracts.iter_mut() {
|
|
let full_name = format!("{path}:{name}");
|
|
let missing_libraries = self.contract_libraries.remove(full_name.as_str());
|
|
|
|
if let Some(missing_libraries) = missing_libraries {
|
|
contract.missing_libraries = Some(missing_libraries);
|
|
}
|
|
}
|
|
}
|
|
|
|
standard_json.version = Some(solc_version.default.to_string());
|
|
standard_json.long_version = Some(solc_version.long.to_owned());
|
|
standard_json.revive_version = Some(ResolcVersion::default().long);
|
|
|
|
Ok(())
|
|
}
|
|
}
|