From 4b4ebd74ba270b568fa5505a8b547f7503f09d0b Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 25 Dec 2021 05:45:53 +0100 Subject: [PATCH] fix: make evm bytecode optional (#735) --- ethers-solc/src/artifacts.rs | 6 +++--- ethers-solc/src/hh.rs | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ethers-solc/src/artifacts.rs b/ethers-solc/src/artifacts.rs index cc92aaea..2feb5534 100644 --- a/ethers-solc/src/artifacts.rs +++ b/ethers-solc/src/artifacts.rs @@ -635,7 +635,7 @@ impl From for CompactContract { fn from(c: Contract) -> Self { let (bin, bin_runtime) = if let Some(evm) = c.evm { ( - Some(evm.bytecode.object), + evm.bytecode.map(|c| c.object), evm.deployed_bytecode.and_then(|deployed| deployed.bytecode.map(|evm| evm.object)), ) } else { @@ -688,7 +688,7 @@ impl<'a> From<&'a Contract> for CompactContractRef<'a> { fn from(c: &'a Contract) -> Self { let (bin, bin_runtime) = if let Some(ref evm) = c.evm { ( - Some(&evm.bytecode.object), + evm.bytecode.as_ref().map(|c| &c.object), evm.deployed_bytecode .as_ref() .and_then(|deployed| deployed.bytecode.as_ref().map(|evm| &evm.object)), @@ -738,7 +738,7 @@ pub struct Evm { pub assembly: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub legacy_assembly: Option, - pub bytecode: Bytecode, + pub bytecode: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub deployed_bytecode: Option, /// The list of function hashes diff --git a/ethers-solc/src/hh.rs b/ethers-solc/src/hh.rs index 5f4a47bd..dd79f75a 100644 --- a/ethers-solc/src/hh.rs +++ b/ethers-solc/src/hh.rs @@ -25,7 +25,7 @@ pub struct HardhatArtifact { pub abi: Abi, /// A "0x"-prefixed hex string of the unlinked deployment bytecode. If the contract is not /// deployable, this has the string "0x" - pub bytecode: BytecodeObject, + pub bytecode: Option, /// A "0x"-prefixed hex string of the unlinked runtime/deployed bytecode. If the contract is /// not deployable, this has the string "0x" pub deployed_bytecode: Option, @@ -43,7 +43,7 @@ impl From for CompactContract { fn from(artifact: HardhatArtifact) -> Self { CompactContract { abi: Some(artifact.abi), - bin: Some(artifact.bytecode), + bin: artifact.bytecode, bin_runtime: artifact.deployed_bytecode, } } @@ -90,12 +90,13 @@ impl ArtifactOutput for HardhatArtifacts { (None, Default::default()) }; - ( - evm.bytecode.object, - evm.bytecode.link_references, - deployed_bytecode, - deployed_link_references, - ) + let (bytecode, link_ref) = if let Some(bc) = evm.bytecode { + (Some(bc.object), bc.link_references) + } else { + (None, Default::default()) + }; + + (bytecode, link_ref, deployed_bytecode, deployed_link_references) } else { (Default::default(), Default::default(), None, Default::default()) };