Changed typing in the yul_abi_targets data structure to use a contract instead of an abi, then during yul_abi injection, create an artifact from a contract

This commit is contained in:
0xKitsune 2022-03-08 19:01:20 -05:00
parent 9fac73d999
commit 8790bf5fbf
2 changed files with 16 additions and 25 deletions

View File

@ -514,7 +514,7 @@ pub trait ArtifactOutput {
//the second value is the abi that will be injected into the yul artifact //the second value is the abi that will be injected into the yul artifact
//the third value is the abi.sol file path to be removed from artifacts //the third value is the abi.sol file path to be removed from artifacts
let mut yul_abi_targets: HashMap<String, (String, Abi, String)> = HashMap::new(); let mut yul_abi_targets: HashMap<String, (String, Contract, String)> = HashMap::new();
let mut artifacts = ArtifactsMap::new(); let mut artifacts = ArtifactsMap::new();
for (file, contracts) in contracts.as_ref().iter() { for (file, contracts) in contracts.as_ref().iter() {
@ -541,7 +541,7 @@ pub trait ArtifactOutput {
target_file, target_file,
( (
artifact_name.to_string(), artifact_name.to_string(),
contract.contract.abi.as_ref().unwrap().abi.clone(), contract.contract.clone(),
file.to_string(), file.to_string(),
), ),
); );
@ -563,23 +563,14 @@ pub trait ArtifactOutput {
//inject yul abis into target .yul artifacts //inject yul abis into target .yul artifacts
for (yul_target_path, artifact_tuple) in yul_abi_targets { for (yul_target_path, artifact_tuple) in yul_abi_targets {
//find the target yul entry with the target file path //find the target yul entry with the target file path
let mut _entries = artifacts.entry(yul_target_path).or_insert(BTreeMap::new()); let mut _entries = artifacts.entry(yul_target_path.clone()).or_insert(BTreeMap::new());
//get the artifact file from the entry //get the artifact file from the entry
let artifact_file = &_entries.get(&artifact_tuple.0).unwrap()[0]; let artifact_file = &_entries.get(&artifact_tuple.0).unwrap()[0];
//inject the abi into the yul artifact //inject the abi into the yul artifact
let mut yul_artifact = &artifact_file.artifact; let mut yul_artifact = &artifact_file.artifact;
// create a new artifact let yul_artifact =
let new_artifact = artifact_file.artifact.clone(); &self.contract_to_artifact(&yul_target_path, &artifact_tuple.0, artifact_tuple.1);
//get the contract_abi of the new artifact
let mut contract_abi = new_artifact.into_inner().0;
//set the contract abi to the corresponding .abi.sol file
contract_abi = Some(artifact_tuple.1);
//TODO: Abi is injecting, now we just need to reassign the yul_artifact to be the new_artifact
println!("{:?}", contract_abi);
println!("\n");
} }
Artifacts(artifacts) Artifacts(artifacts)

View File

@ -1089,7 +1089,7 @@ impl TryFrom<ContractBytecode> for ContractBytecodeSome {
fn try_from(value: ContractBytecode) -> Result<Self, Self::Error> { fn try_from(value: ContractBytecode) -> Result<Self, Self::Error> {
if value.abi.is_none() || value.bytecode.is_none() || value.deployed_bytecode.is_none() { if value.abi.is_none() || value.bytecode.is_none() || value.deployed_bytecode.is_none() {
return Err(value) return Err(value);
} }
Ok(value.unwrap()) Ok(value.unwrap())
} }
@ -1111,7 +1111,7 @@ impl TryFrom<CompactContract> for CompactContractSome {
fn try_from(value: CompactContract) -> Result<Self, Self::Error> { fn try_from(value: CompactContract) -> Result<Self, Self::Error> {
if value.abi.is_none() || value.bin.is_none() || value.bin_runtime.is_none() { if value.abi.is_none() || value.bin.is_none() || value.bin_runtime.is_none() {
return Err(value) return Err(value);
} }
Ok(value.unwrap()) Ok(value.unwrap())
} }
@ -1290,7 +1290,7 @@ impl<'a> TryFrom<CompactContractRef<'a>> for CompactContractRefSome<'a> {
fn try_from(value: CompactContractRef<'a>) -> Result<Self, Self::Error> { fn try_from(value: CompactContractRef<'a>) -> Result<Self, Self::Error> {
if value.abi.is_none() || value.bin.is_none() || value.bin_runtime.is_none() { if value.abi.is_none() || value.bin.is_none() || value.bin_runtime.is_none() {
return Err(value) return Err(value);
} }
Ok(value.unwrap()) Ok(value.unwrap())
} }
@ -1516,7 +1516,7 @@ impl CompactBytecode {
address: Address, address: Address,
) -> bool { ) -> bool {
if !self.object.is_unlinked() { if !self.object.is_unlinked() {
return true return true;
} }
let file = file.as_ref(); let file = file.as_ref();
@ -1529,7 +1529,7 @@ impl CompactBytecode {
self.link_references.insert(key, contracts); self.link_references.insert(key, contracts);
} }
if self.link_references.is_empty() { if self.link_references.is_empty() {
return self.object.resolve().is_some() return self.object.resolve().is_some();
} }
} }
false false
@ -1601,7 +1601,7 @@ impl Bytecode {
address: Address, address: Address,
) -> bool { ) -> bool {
if !self.object.is_unlinked() { if !self.object.is_unlinked() {
return true return true;
} }
let file = file.as_ref(); let file = file.as_ref();
@ -1614,7 +1614,7 @@ impl Bytecode {
self.link_references.insert(key, contracts); self.link_references.insert(key, contracts);
} }
if self.link_references.is_empty() { if self.link_references.is_empty() {
return self.object.resolve().is_some() return self.object.resolve().is_some();
} }
} }
false false
@ -1629,7 +1629,7 @@ impl Bytecode {
{ {
for (file, lib, addr) in libs.into_iter() { for (file, lib, addr) in libs.into_iter() {
if self.link(file, lib, addr) { if self.link(file, lib, addr) {
return true return true;
} }
} }
false false
@ -1643,7 +1643,7 @@ impl Bytecode {
{ {
for (name, addr) in libs.into_iter() { for (name, addr) in libs.into_iter() {
if self.link_fully_qualified(name, addr) { if self.link_fully_qualified(name, addr) {
return true return true;
} }
} }
false false
@ -1776,8 +1776,8 @@ impl BytecodeObject {
pub fn contains_fully_qualified_placeholder(&self, name: impl AsRef<str>) -> bool { pub fn contains_fully_qualified_placeholder(&self, name: impl AsRef<str>) -> bool {
if let BytecodeObject::Unlinked(unlinked) = self { if let BytecodeObject::Unlinked(unlinked) = self {
let name = name.as_ref(); let name = name.as_ref();
unlinked.contains(&utils::library_hash_placeholder(name)) || unlinked.contains(&utils::library_hash_placeholder(name))
unlinked.contains(&utils::library_fully_qualified_placeholder(name)) || unlinked.contains(&utils::library_fully_qualified_placeholder(name))
} else { } else {
false false
} }