diff --git a/cmd/dashboard/dashboard.js b/cmd/dashboard/dashboard.js index 107ebb97..bcdea0d9 100644 --- a/cmd/dashboard/dashboard.js +++ b/cmd/dashboard/dashboard.js @@ -28,6 +28,36 @@ class Dashboard { let console, monitor; let self = this; + let plugin = this.plugins.createPlugin('dashboard', {}); + plugin.registerAPICall( + 'ws', + '/embark/dashboard', + (ws, req) => { + let dashboardState = { contractsState: [], environment: "", status: "", availableServices: [] }; + + // TODO: doesn't feel quite right, should be refactored into a shared + // dashboard state + self.events.request('setDashboardState'); + + self.events.on('contractsState', (contracts) => { + dashboardState.contractsState = []; + + contracts.forEach(function (row) { + dashboardState.contractsState.push({contractName: row[0], address: row[1], status: row[2]}); + }); + ws.send(JSON.stringify(dashboardState)); + }); + self.events.on('status', (status) => { + dashboardState.status = status; + ws.send(JSON.stringify(dashboardState)); + }); + self.events.on('servicesState', (servicesState) => { + dashboardState.availableServices = servicesState; + ws.send(JSON.stringify(dashboardState)); + }); + } + ); + async.waterfall([ function startConsole(callback) { console = new Console({ diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index b811d247..0b95d2ac 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -38,30 +38,10 @@ class Server { }); }); - app.ws('/embark/dashboard', function(ws, req) { - let dashboardState = { contractsState: [], environment: "", status: "", availableServices: [] }; - - // TODO: doesn't feel quite right, should be refactored into a shared - // dashboard state - self.events.request('setDashboardState'); - - self.events.on('contractsState', (contracts) => { - dashboardState.contractsState = []; - - contracts.forEach(function (row) { - dashboardState.contractsState.push({contractName: row[0], address: row[1], status: row[2]}); - }); - ws.send(JSON.stringify(dashboardState)); - }); - self.events.on('status', (status) => { - dashboardState.status = status; - ws.send(JSON.stringify(dashboardState)); - }); - self.events.on('servicesState', (servicesState) => { - dashboardState.availableServices = servicesState; - ws.send(JSON.stringify(dashboardState)); - }); - }); + let apiCalls = self.plugins.getPluginsProperty("apiCalls", "apiCalls"); + for (let apiCall of apiCalls) { + app[apiCall.method].apply(app, [apiCall.endpoint, apiCall.cb]); + } app.get('/embark', function (req, res) { res.send('Welcome to Embark') diff --git a/test_apps/contracts_app/contracts/another_storage.sol b/test_apps/contracts_app/contracts/another_storage.sol index a8c1c873..92233769 100644 --- a/test_apps/contracts_app/contracts/another_storage.sol +++ b/test_apps/contracts_app/contracts/another_storage.sol @@ -1,6 +1,5 @@ pragma solidity ^0.4.17; contract AnotherStorage { - address public simpleStorageAddress; address simpleStorageAddress2;