From 01eaa0fe7f15a7891ee70271c31b6c02474c4c63 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 22 Mar 2018 16:18:13 -0400 Subject: [PATCH] Generating basic diagram that includes methods --- lib/cmds/graph.js | 61 +++++++++++++++++++++++++++++++++++++++++------ lib/index.js | 16 +------------ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/lib/cmds/graph.js b/lib/cmds/graph.js index dba9c2aa..8bc67086 100644 --- a/lib/cmds/graph.js +++ b/lib/cmds/graph.js @@ -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; + }); + + } } diff --git a/lib/index.js b/lib/index.js index 21bc71f4..d31decd9 100644 --- a/lib/index.js +++ b/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() {