Generating basic diagram that includes methods
This commit is contained in:
parent
d7b33a309b
commit
01eaa0fe7f
|
@ -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 fs = require('fs');
|
||||
|
||||
class GraphGenerator {
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
constructor(engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
16
lib/index.js
16
lib/index.js
|
@ -227,7 +227,7 @@ class Embark {
|
|||
} else {
|
||||
|
||||
const GraphGenerator = require('./cmds/graph.js');
|
||||
let graphGen = new GraphGenerator(engine.config);
|
||||
let graphGen = new GraphGenerator(engine);
|
||||
graphGen.generate();
|
||||
|
||||
engine.logger.info("Done".underline);
|
||||
|
@ -235,20 +235,6 @@ class Embark {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
reset() {
|
||||
|
|
Loading…
Reference in New Issue