Generating basic diagram that includes methods

This commit is contained in:
Richard Ramos 2018-03-22 16:18:13 -04:00
parent d7b33a309b
commit 01eaa0fe7f
2 changed files with 55 additions and 22 deletions

View File

@ -1,16 +1,63 @@
const fs = require("fs");
const klaw = require('klaw');
const path = require('path');
const SolidityParser = require("solidity-parser");
const Viz = require('viz.js'); const Viz = require('viz.js');
const fs = require('fs');
class GraphGenerator { class GraphGenerator {
constructor(config) { constructor(engine) {
this.config = config; this.engine = engine;
} }
generate() { generate() {
console.log("TODO"); let id = 0;
let contractString = "";
for (let contract in this.engine.contractsManager.contracts) {
id++;
let contractLabel = "";
contractLabel += `${contract}`;
let fHashes = this.engine.contractsManager.contracts[contract].functionHashes;
if(fHashes != {} && fHashes != undefined){
contractLabel += "|";
for(let method in this.engine.contractsManager.contracts[contract].functionHashes){
contractLabel += method + '\\l';
}
}
for(let i = 0; i < this.engine.contractsManager.contracts[contract].abiDefinition.length; i++){
if(this.engine.contractsManager.contracts[contract].abiDefinition[i].type == 'fallback')
contractLabel += "«fallback»()" + '\\l';
}
/*if(c.methods.length > 0){
contractLabel += "|";
c.methods.forEach(function(a){
contractLabel += a + '\\l';
})
} */
contractString += `${id}[label = "{${contractLabel}}"]`
contractString += "\n";
}
let dot = `
digraph hierarchy {
node[shape=record,style=filled,fillcolor=gray95]
edge[dir=back, arrowtail=empty]
${contractString}
}`;
let svg = Viz(dot);
let filename = "diagram.svg";
fs.writeFileSync(filename, svg, (err) => {
if (err) throw err;
});
} }
} }

View File

@ -227,7 +227,7 @@ class Embark {
} else { } else {
const GraphGenerator = require('./cmds/graph.js'); const GraphGenerator = require('./cmds/graph.js');
let graphGen = new GraphGenerator(engine.config); let graphGen = new GraphGenerator(engine);
graphGen.generate(); graphGen.generate();
engine.logger.info("Done".underline); engine.logger.info("Done".underline);
@ -235,20 +235,6 @@ class Embark {
} }
}); });
} }
reset() { reset() {