Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
feat: abi as an extra file (#1166)
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg authored Apr 23, 2022
1 parent 1b04465 commit 8444b8e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ethers-solc/src/artifact_output/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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;
}
Expand All @@ -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");
Expand Down

0 comments on commit 8444b8e

Please sign in to comment.