write outputs to file, if selected (#847)

This commit is contained in:
joshieDo 2022-01-31 18:19:57 +02:00 committed by GitHub
parent 67f7dc017d
commit dd915c99f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -752,6 +752,7 @@ impl<'a> fmt::Display for OutputDiagnostics<'a> {
/// Represents a compiled solidity contract
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Contract {
/// The Ethereum Contract Metadata.
/// See https://docs.soliditylang.org/en/develop/metadata.html
@ -764,7 +765,7 @@ pub struct Contract {
pub devdoc: DevDoc,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ir: Option<String>,
#[serde(default, rename = "storageLayout", skip_serializing_if = "StorageLayout::is_empty")]
#[serde(default, skip_serializing_if = "StorageLayout::is_empty")]
pub storage_layout: StorageLayout,
/// EVM-related outputs
#[serde(default, skip_serializing_if = "Option::is_none")]
@ -772,6 +773,8 @@ pub struct Contract {
/// Ewasm related outputs
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ewasm: Option<Ewasm>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ir_optimized: Option<String>,
}
/// Minimal representation of a contract with a present abi and bytecode.

View File

@ -653,6 +653,29 @@ impl ArtifactOutput for MinimalCombinedArtifacts {
))
})?;
}
if let Some(iropt) = &contract.ir_optimized {
fs::write(&file.with_extension("iropt"), iropt)
.map_err(|err| SolcError::io(err, file.with_extension("iropt")))?
}
if let Some(ir) = &contract.ir {
fs::write(&file.with_extension("ir"), ir)
.map_err(|err| SolcError::io(err, file.with_extension("ir")))?
}
if let Some(ewasm) = &contract.ewasm {
fs::write(&file.with_extension("ewasm"), serde_json::to_vec_pretty(&ewasm)?)
.map_err(|err| SolcError::io(err, file.with_extension("ewasm")))?;
}
if let Some(evm) = &contract.evm {
if let Some(asm) = &evm.assembly {
fs::write(&file.with_extension("asm"), asm)
.map_err(|err| SolcError::io(err, file.with_extension("asm")))?
}
}
let min = CompactContractBytecode::from(contract.clone());
fs::write(&file, serde_json::to_vec_pretty(&min)?)
.map_err(|err| SolcError::io(err, file))?