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

feat: abi as an extra file #1166

Merged
merged 1 commit into from
Apr 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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