Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show inherited functions in Debug (when deploying with foundry) #604

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-fireants-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

- Show inherited functions in Debug page (when deploying with foundry)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getFiles(path) {
return fs.statSync(path + "/" + file).isFile();
});
}
function getAbiOfContract(contractName) {
function getArtifactOfContract(contractName) {
const current_path_to_artifacts = path.join(
__dirname,
"..",
Expand All @@ -31,7 +31,36 @@ function getAbiOfContract(contractName) {
fs.readFileSync(`${current_path_to_artifacts}/${contractName}.json`)
);

return artifactJson.abi;
return artifactJson;
}

function getInheritedFromContracts(artifact) {
let inheritedFromContracts = [];
for (const astNode of artifact.ast.nodes) {
if (astNode.nodeType == "ContractDefinition") {
if (astNode.baseContracts.length > 0) {
inheritedFromContracts = astNode.baseContracts.map(({baseName}) => baseName.name);
}
}
}
return inheritedFromContracts;
}

function getInheritedFunctions(mainArtifact) {
const inheritedFromContracts = getInheritedFromContracts(mainArtifact);
const inheritedFunctions = {};
for (const inheritanceContractName of inheritedFromContracts) {
const {
abi,
ast: { absolutePath },
} = getArtifactOfContract(inheritanceContractName);
for (const abiEntry of abi) {
if (abiEntry.type == "function") {
inheritedFunctions[abiEntry.name] = absolutePath;
}
}
}
return inheritedFunctions;
}

function main() {
Expand Down Expand Up @@ -67,12 +96,16 @@ function main() {
(transaction) => transaction.transactionType == "CREATE"
);
transactionsCreate.forEach((transaction) => {
const artifact = getArtifactOfContract(transaction.contractName);
allGeneratedContracts[chain][
deployments[chain][transaction.contractAddress] ||
transaction.contractName
] = {
address: transaction.contractAddress,
abi: getAbiOfContract(transaction.contractName),
abi: artifact.abi,
inheritedFunctions: getInheritedFunctions(
artifact,
),
};
});
});
Expand Down