diff --git a/lib/core/engine.js b/lib/core/engine.js index 296586ed..106abb64 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -193,7 +193,7 @@ class Engine { this.registerModule('compiler', {plugins: self.plugins, disableOptimizations: options.disableOptimizations}); this.registerModule('solidity', {ipc: self.ipc, useDashboard: this.useDashboard}); this.registerModule('vyper'); - this.registerModule('profiler'); + this.registerModule('profiler', {plugins: this.plugins}); this.registerModule('deploytracker', {trackContracts: options.trackContracts}); this.registerModule('specialconfigs'); this.registerModule('console_listener', {ipc: self.ipc}); diff --git a/lib/modules/profiler/index.js b/lib/modules/profiler/index.js index 377acad5..1ce550a7 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;