From 8444b8ebbe79732792faf96510711401af9a7690 Mon Sep 17 00:00:00 2001 From: Bjerg Date: Sat, 23 Apr 2022 10:40:25 +0200 Subject: [PATCH] feat: abi as an extra file (#1166) --- ethers-solc/src/artifact_output/configurable.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ethers-solc/src/artifact_output/configurable.rs b/ethers-solc/src/artifact_output/configurable.rs index b25e962f..196f1d21 100644 --- a/ethers-solc/src/artifact_output/configurable.rs +++ b/ethers-solc/src/artifact_output/configurable.rs @@ -396,6 +396,7 @@ impl ExtraOutputValues { /// Determines what to emit as additional file #[derive(Debug, Copy, Clone, Eq, PartialEq, Default)] pub struct ExtraOutputFiles { + pub abi: bool, pub metadata: bool, pub ir_optimized: bool, pub ewasm: bool, @@ -420,6 +421,7 @@ impl ExtraOutputFiles { /// Returns an instance where all values are set to `true` pub fn all() -> Self { Self { + abi: true, metadata: true, ir_optimized: true, ewasm: true, @@ -435,6 +437,9 @@ impl ExtraOutputFiles { let mut config = Self::default(); for value in settings.into_iter() { match value { + ContractOutputSelection::Abi => { + config.abi = true; + } ContractOutputSelection::Metadata => { config.metadata = true; } @@ -461,6 +466,14 @@ impl ExtraOutputFiles { /// Write the set values as separate files pub fn write_extras(&self, contract: &Contract, file: &Path) -> Result<(), SolcError> { + if self.abi { + if let Some(ref abi) = contract.abi { + let file = file.with_extension("abi.json"); + fs::write(&file, serde_json::to_string_pretty(abi)?) + .map_err(|err| SolcError::io(err, file))? + } + } + if self.metadata { if let Some(ref metadata) = contract.metadata { let file = file.with_extension("metadata.json");