Skip to content

Commit

Permalink
Update event dev docs combining
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ste committed Jul 10, 2023
1 parent b96dc0f commit 30b31d6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
3 changes: 1 addition & 2 deletions examples/docs/contracts/Bar.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@
}
},
"notice": "Emitted when transfer",
"details": "Transfer some stuff",
"custom:danger": "This event exposes private info"
"details": "Transfer some stuff"
}
},
"errors": {
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/contracts/Bar.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ event Transfer(uint256 foo)
Emitted when transfer
*Transfer some stuff*

**Danger:** *This event exposes private info*



#### Parameters
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@b00ste/hardhat-dodoc",
"version": "0.3.5",
"version": "0.3.7",
"description": "Zero-config Hardhat plugin to generate documentation for all your Solidity contracts",
"repository": "github:b00ste/primitive-dodoc",
"author": "Primitive",
Expand Down
66 changes: 44 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,6 @@ async function generateDocumentation(hre: HardhatRuntimeEnvironment): Promise<vo
const buildInfo = await hre.artifacts.getBuildInfo(qualifiedName);
const info = buildInfo?.output.contracts[source][name] as CompilerOutputContractWithDocumentation;

// Getting inheritance of the contract and combining the natspec
for (const inheritanceSource in buildInfo?.output.contracts) {
const fileContracts = buildInfo?.output.contracts[inheritanceSource];
for (const inheritanceContract in fileContracts) {
const contractBuildInfo = fileContracts[
inheritanceContract
] as CompilerOutputContractWithDocumentation;
// Combining devdoc
const contractDevdoc = info.devdoc;
const parentContractDevdoc = contractBuildInfo.devdoc;
if (parentContractDevdoc !== undefined) {
if (contractDevdoc !== undefined) {
contractDevdoc.events = {
...contractDevdoc.events,
...parentContractDevdoc.events,
};
}
info.devdoc = contractDevdoc;
}
}
}

if (config.debugMode) {
console.log('ABI:\n');
console.log(JSON.stringify(info.abi, null, 4));
Expand Down Expand Up @@ -417,6 +395,50 @@ async function generateDocumentation(hre: HardhatRuntimeEnvironment): Promise<vo
}
}

// console.log(doc.events);
// Getting inheritance of the contract and combining the natspec
for (const inheritanceSource in buildInfo?.output.contracts) {
const fileContracts = buildInfo?.output.contracts[inheritanceSource];
for (const inheritanceContract in fileContracts) {
const contractBuildInfo = fileContracts[
inheritanceContract
] as CompilerOutputContractWithDocumentation;
// Combining devdoc
const parentContractDevdocEvents = contractBuildInfo.devdoc?.events;
if (parentContractDevdocEvents) {
if (doc) {
if (doc.events) {
for (const event in doc.events) {
let eventSignatrue = `${event}(`;
if (doc.events[event].inputs) {
for (const input in doc.events[event].inputs) {
eventSignatrue += `${doc.events[event].inputs[input].type},`;
}
eventSignatrue = eventSignatrue.substring(0, eventSignatrue.length - 1);
}
eventSignatrue += ')';

if (doc.events[event] && parentContractDevdocEvents[eventSignatrue]) {
if (doc.events[event].details === undefined) {
if (parentContractDevdocEvents[eventSignatrue].details) {
doc.events[event].details = parentContractDevdocEvents[eventSignatrue].details;
}
if (parentContractDevdocEvents[eventSignatrue].params) {
for (const param in parentContractDevdocEvents[eventSignatrue].params) {
doc.events[event].inputs[param].description =
parentContractDevdocEvents[eventSignatrue].params[param];
}
}
}
}
}
}
}
}
}
}
// console.log(doc.events);

doc.name = name;
docs.push(doc);
}
Expand Down

0 comments on commit 30b31d6

Please sign in to comment.