diff --git a/lib/core/engine.js b/lib/core/engine.js index c6c2284d3..bfe159834 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -192,7 +192,10 @@ class Engine { let self = this; this.setupCompilerAndContractsManagerService(options); - this.registerModule('profiler'); + this.registerModule('compiler', {plugins: self.plugins, disableOptimizations: options.disableOptimizations}); + this.registerModule('solidity', {ipc: self.ipc, useDashboard: this.useDashboard}); + this.registerModule('vyper'); + this.registerModule('profiler', {plugins: this.plugins}); this.registerModule('deploytracker', {trackContracts: options.trackContracts}); this.registerModule('specialconfigs'); this.registerModule('ens'); diff --git a/lib/modules/profiler/index.js b/lib/modules/profiler/index.js index 377acad57..1ce550a7f 100644 --- a/lib/modules/profiler/index.js +++ b/lib/modules/profiler/index.js @@ -2,13 +2,15 @@ const asciiTable = require('ascii-table'); const GasEstimator = require('./gasEstimator.js'); class Profiler { - constructor(embark) { + constructor(embark, options) { this.embark = embark; this.logger = embark.logger; this.events = embark.events; + this.plugins = options.plugins; this.gasEstimator = new GasEstimator(embark); this.registerConsoleCommand(); + this.registerApi(); } profile(contractName, contract, callback) { @@ -65,6 +67,32 @@ class Profiler { }; }); } + + registerApi() { + const self = this; + + let plugin = this.plugins.createPlugin('profiler', {}); + plugin.registerAPICall( + 'get', + '/embark-api/profiler/:contractName', + (req, res) => { + let contractName = req.params.contractName; + //self.events.request('contracts:contract', req.params.contractName, res.send.bind(res)); + self.events.request('contracts:contract', contractName, (contract) => { + if (!contract || !contract.deployedAddress) { + return res.send("-- couldn't profile " + contractName + " - it's not deployed or could be an interface"); + } + self.profile(contractName, contract, (err, table) => { + if (err) { + return res.send(err); + } + res.send(table); + }); + }); + } + ); + } + } module.exports = Profiler;