define api for profiler

This commit is contained in:
Iuri Matias 2018-08-01 13:27:50 -04:00 committed by Pascal Precht
parent 546d7af076
commit 7e96eb661e
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 33 additions and 2 deletions

View File

@ -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');

View File

@ -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;