Added method to overwrite ABI
This commit is contained in:
parent
8790bf5fbf
commit
f7eab52480
|
@ -2,23 +2,21 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
artifacts::{
|
artifacts::{
|
||||||
CompactContract, CompactContractBytecode, Contract, FileToContractsMap, LosslessAbi,
|
CompactContract, CompactContractBytecode, Contract, FileToContractsMap,
|
||||||
},
|
},
|
||||||
contracts::VersionedContracts,
|
contracts::VersionedContracts,
|
||||||
error::Result,
|
error::Result,
|
||||||
utils, HardhatArtifact, ProjectPathsConfig, SolcError,
|
utils, HardhatArtifact, ProjectPathsConfig, SolcError,
|
||||||
};
|
};
|
||||||
use ethers_core::{abi::Abi, types::Bytes};
|
use ethers_core::{abi::{Abi, self}, types::Bytes};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use serde_json::map::OccupiedEntry;
|
|
||||||
use std::collections::hash_map::Entry;
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::btree_map::BTreeMap,
|
collections::btree_map::BTreeMap,
|
||||||
fmt, fs, io,
|
fmt, fs, io,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, ffi::OsStr};
|
use std::{collections::HashMap};
|
||||||
|
|
||||||
mod configurable;
|
mod configurable;
|
||||||
pub use configurable::*;
|
pub use configurable::*;
|
||||||
|
@ -286,7 +284,8 @@ impl<T> Artifacts<T> {
|
||||||
pub trait Artifact {
|
pub trait Artifact {
|
||||||
/// Returns the artifact's `Abi` and bytecode
|
/// Returns the artifact's `Abi` and bytecode
|
||||||
fn into_inner(self) -> (Option<Abi>, Option<Bytes>);
|
fn into_inner(self) -> (Option<Abi>, Option<Bytes>);
|
||||||
|
/// Alows an Artifact's ABI to be changed
|
||||||
|
fn replace_abi(self, new_abi: Option<Abi>);
|
||||||
/// Turns the artifact into a container type for abi, compact bytecode and deployed bytecode
|
/// Turns the artifact into a container type for abi, compact bytecode and deployed bytecode
|
||||||
fn into_compact_contract(self) -> CompactContract;
|
fn into_compact_contract(self) -> CompactContract;
|
||||||
|
|
||||||
|
@ -320,6 +319,11 @@ where
|
||||||
(artifact.abi, artifact.bin.and_then(|bin| bin.into_bytes()))
|
(artifact.abi, artifact.bin.and_then(|bin| bin.into_bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn replace_abi(self, new_abi: Option<Abi>) {
|
||||||
|
let artifact = self.into_compact_contract();
|
||||||
|
artifact.abi = new_abi;
|
||||||
|
}
|
||||||
|
|
||||||
fn into_compact_contract(self) -> CompactContract {
|
fn into_compact_contract(self) -> CompactContract {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
@ -567,10 +571,11 @@ pub trait ArtifactOutput {
|
||||||
//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 abi = &artifact_file.clone().artifact.into_inner();
|
||||||
|
|
||||||
let yul_artifact =
|
println!("{:?}", artifact_file);
|
||||||
&self.contract_to_artifact(&yul_target_path, &artifact_tuple.0, artifact_tuple.1);
|
println!("{:?}", abi);
|
||||||
|
//artifacts.remove_entry(&artifact_tuple.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Artifacts(artifacts)
|
Artifacts(artifacts)
|
||||||
|
|
|
@ -114,6 +114,10 @@ fn can_compile_yul_sample() {
|
||||||
// delete artifacts
|
// delete artifacts
|
||||||
std::fs::remove_dir_all(&project.paths().artifacts).unwrap();
|
std::fs::remove_dir_all(&project.paths().artifacts).unwrap();
|
||||||
let compiled = project.compile().unwrap();
|
let compiled = project.compile().unwrap();
|
||||||
|
// Make sure ABI does exist
|
||||||
|
assert!( compiled.find("SimpleStore").is_some());
|
||||||
|
|
||||||
|
|
||||||
assert!(compiled.find("Dapp").is_some());
|
assert!(compiled.find("Dapp").is_some());
|
||||||
assert!(compiled.find("SimpleStore").is_some());
|
assert!(compiled.find("SimpleStore").is_some());
|
||||||
assert!(!compiled.is_unchanged());
|
assert!(!compiled.is_unchanged());
|
||||||
|
|
Loading…
Reference in New Issue