From 809ccbc9adcc3ef044918f4371c1c642100dc460 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 19 May 2022 20:02:31 +0200 Subject: [PATCH] feat(solc): include id in artifact (#1284) --- ethers-solc/src/artifact_output/configurable.rs | 9 +++++++++ ethers-solc/src/compile/output/mod.rs | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/ethers-solc/src/artifact_output/configurable.rs b/ethers-solc/src/artifact_output/configurable.rs index 588d0533..ea373cf7 100644 --- a/ethers-solc/src/artifact_output/configurable.rs +++ b/ethers-solc/src/artifact_output/configurable.rs @@ -55,6 +55,9 @@ pub struct ConfigurableContractArtifact { pub ewasm: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub ast: Option, + /// The identifier of the source file + #[serde(default, skip_serializing_if = "Option::is_none")] + pub id: Option, } impl ConfigurableContractArtifact { @@ -77,6 +80,11 @@ impl ConfigurableContractArtifact { } links } + + /// Returns the source file of this artifact's contract + pub fn source_file(&self) -> Option { + self.id.map(|id| SourceFile { id, ast: self.ast.clone() }) + } } impl From for CompactContractBytecode { @@ -316,6 +324,7 @@ impl ArtifactOutput for ConfigurableArtifacts { ir: artifact_ir, ir_optimized: artifact_ir_optimized, ewasm: artifact_ewasm, + id: source_file.as_ref().map(|s| s.id), ast: source_file.and_then(|s| s.ast.clone()), generated_sources: generated_sources.unwrap_or_default(), } diff --git a/ethers-solc/src/compile/output/mod.rs b/ethers-solc/src/compile/output/mod.rs index 7730df88..e6e0a61c 100644 --- a/ethers-solc/src/compile/output/mod.rs +++ b/ethers-solc/src/compile/output/mod.rs @@ -73,6 +73,11 @@ impl ProjectCompileOutput { } /// All artifacts together with their ID and the sources of the project. + /// + /// Note: this only returns the `SourceFiles` for freshly compiled contracts because, if not + /// included in the `Artifact` itself (see + /// [`crate::ConfigurableContractArtifact::source_file()`]), is only available via the solc + /// `CompilerOutput` pub fn into_artifacts_with_sources( self, ) -> (BTreeMap, VersionedSourceFiles) {