lint fixes

This commit is contained in:
Iuri Matias 2018-10-29 14:15:48 +01:00
parent c6902efb2f
commit 99d618c2e3
12 changed files with 179 additions and 179 deletions

View File

@ -133,7 +133,7 @@ Plugin.prototype.registerDappGenerator = function(framework, cb){
Plugin.prototype.registerCustomType = function(type){
this.pluginTypes.push(type);
}
};
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {
this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options});

View File

@ -3,8 +3,8 @@ const ProcessState = {
Unstarted: 'unstarted',
Starting: 'starting',
Running: 'running',
Stopping: 'stopping',
}
Stopping: 'stopping'
};
class ProcessManager {
constructor(options) {
@ -21,21 +21,21 @@ class ProcessManager {
const self = this;
self.plugin = this.plugins.createPlugin('processManager', {});
this.servicesState = {}
this.servicesState = {};
this.events.on("servicesState", (servicesState) => {
this.servicesState = servicesState;
})
});
self.plugin.registerAPICall(
'get',
'/embark-api/services',
(req, res) => {
let processList = []
let processList = [];
for (let serviceName in this.servicesState) {
let service = this.servicesState[serviceName]
processList.push({state: service.status, name: serviceName, description: service.name})
let service = this.servicesState[serviceName];
processList.push({state: service.status, name: serviceName, description: service.name});
}
res.send(processList)
res.send(processList);
}
);

View File

@ -1,5 +1,5 @@
const uuid = require('uuid/v1');
const utils = require("../../utils/utils.js")
const utils = require("../../utils/utils.js");
const keccak = require('keccakjs');
const ERROR_OBJ = {error: __('Wrong authentication token. Get your token from the Embark console by typing `token`')};
@ -20,7 +20,7 @@ class Authenticator {
let hash = new keccak();
let url = req.url;
let queryParamIndex = url.indexOf('?');
url = url.substring(0, queryParamIndex !== -1 ? queryParamIndex : url.length)
url = url.substring(0, queryParamIndex !== -1 ? queryParamIndex : url.length);
hash.update(cnonce);
hash.update(this.authToken);
@ -60,7 +60,7 @@ class Authenticator {
return {
match: () => cmd === "copytoken",
process: (callback) => {
utils.copyToClipboard(this.authToken)
utils.copyToClipboard(this.authToken);
callback(null, __('Token copied to clipboard: %s', this.authToken));
}
};

View File

@ -411,8 +411,8 @@ class BlockchainConnector {
const signer = req.body.address;
const message = req.body.message;
this.web3.eth.personal.sign(message, signer).then(signature => {
res.send({signer, signature, message})
}).catch(e => res.send({ error: e.message }))
res.send({signer, signature, message});
}).catch(e => res.send({ error: e.message }));
}
);

View File

@ -4,7 +4,7 @@ const EmbarkJS = require('embarkjs');
const IpfsApi = require('ipfs-api');
const Web3 = require('web3');
const stringify = require('json-stringify-safe');
const Suggestions = require('./suggestions')
const Suggestions = require('./suggestions');
class Console {
constructor(embark, options) {

View File

@ -7,35 +7,35 @@ class Suggestions {
this.plugins = options.plugins;
this.registerApi();
this.listenToEvents();
this.contracts = {}
this.contracts = {};
}
registerApi() {
this.embark.registerAPICall('post', '/embark-api/suggestions', (req, res) => {
let suggestions = this.getSuggestions(req.body.command)
res.send({result: suggestions})
let suggestions = this.getSuggestions(req.body.command);
res.send({result: suggestions});
});
}
listenToEvents() {
this.events.on("deploy:contract:deployed", (contract) => {
this.contracts[contract.className] = contract
})
this.contracts[contract.className] = contract;
});
}
getSuggestions(cmd) {
if (!cmd) return []
cmd = cmd.toLowerCase()
let suggestions = []
if (!cmd) return [];
cmd = cmd.toLowerCase();
let suggestions = [];
suggestions.push({value: 'web3.eth', command_type: "web3 object", description: "module for interacting with the Ethereum network"})
suggestions.push({value: 'web3.net', command_type: "web3 object", description: "module for interacting with network properties"})
suggestions.push({value: 'web3.shh', command_type: "web3 object", description: "module for interacting with the whisper protocol"})
suggestions.push({value: 'web3.bzz', command_type: "web3 object", description: "module for interacting with the swarm network"})
suggestions.push({value: 'web3.eth.getAccounts()', command_type: "web3 object", description: "get list of accounts"})
suggestions.push({value: 'web3.eth', command_type: "web3 object", description: "module for interacting with the Ethereum network"});
suggestions.push({value: 'web3.net', command_type: "web3 object", description: "module for interacting with network properties"});
suggestions.push({value: 'web3.shh', command_type: "web3 object", description: "module for interacting with the whisper protocol"});
suggestions.push({value: 'web3.bzz', command_type: "web3 object", description: "module for interacting with the swarm network"});
suggestions.push({value: 'web3.eth.getAccounts()', command_type: "web3 object", description: "get list of accounts"});
for (let contractName in this.contracts) {
let contract = this.contracts[contractName]
let contract = this.contracts[contractName];
suggestions.push({value: contract.className, command_type: "web3 object", description: "contract deployed at " + contract.deployedAddress});
suggestions.push({value: "profile " + contract.className, command_type: "embark command", description: "profile " + contract.className + " contract"});
@ -51,8 +51,8 @@ class Suggestions {
suggestions.push({value: 'EmbarkJS', command_type: "javascript object", description: "EmbarkJS static functions for Storage, Messages, Names, etc."});
// sort first the ones that match the command at the beginning of the string, then prefer smaller commands first
return utils.fuzzySearch(cmd, suggestions, (result) => { return result.value + " " + result.description }).map((x) => x.original).sort((x,y) => {
let diff = x.value.indexOf(cmd) - y.value.indexOf(cmd)
return utils.fuzzySearch(cmd, suggestions, (result) => { return result.value + " " + result.description; }).map((x) => x.original).sort((x,y) => {
let diff = x.value.indexOf(cmd) - y.value.indexOf(cmd);
if (diff !== 0) return diff;
return x.value.length - y.value.length;
});

View File

@ -37,7 +37,7 @@ class ContractsManager {
});
self.events.setCommandHandler("contracts:contract:byTxHash", (txHash, cb) => {
self.getContractByTxHash(txHash, cb)
self.getContractByTxHash(txHash, cb);
});
self.events.setCommandHandler("contracts:build", (configOnly, cb) => {

View File

@ -5,85 +5,85 @@ const async = require('async');
class DebuggerManager {
constructor(nodeUrl) {
this.nodeUrl = nodeUrl
this.outputJson = {}
this.inputJson = {}
this.nodeUrl = nodeUrl;
this.outputJson = {};
this.inputJson = {};
}
setInputJson(inputJson) {
this.inputJson = inputJson
this.inputJson = inputJson;
}
setOutputJson(outputJson) {
this.outputJson = outputJson
this.outputJson = outputJson;
}
createDebuggerSession(txHash, filename, cb) {
return this.debug(txHash, filename, cb)
return this.debug(txHash, filename, cb);
}
debug(txHash, filename, cb) {
console.dir("debugging tx " + txHash)
console.dir("debugging tx " + txHash);
var cmd_line = new CmdLine()
this.cmd_line = cmd_line
cmd_line.connect("http", this.nodeUrl)
cmd_line.loadCompilationData(this.inputJson, this.outputJson)
var cmd_line = new CmdLine();
this.cmd_line = cmd_line;
cmd_line.connect("http", this.nodeUrl);
cmd_line.loadCompilationData(this.inputJson, this.outputJson);
cmd_line.initDebugger(() => {
this.isDebugging = true
this.isDebugging = true;
cmd_line.startDebug(txHash, filename, () => {
if (cb) {
cmd_line.triggerSourceUpdate()
cb()
cmd_line.triggerSourceUpdate();
cb();
}
})
})
return cmd_line
});
});
return cmd_line;
}
getLastLine(txHash, filename, outputCb) {
const self = this;
let cmd_line = new CmdLine()
let cmd_line = new CmdLine();
async.waterfall([
function initDebugger(next) {
cmd_line = new CmdLine()
cmd_line.connect("http", self.nodeUrl)
cmd_line.loadCompilationData(self.inputJson, self.outputJson)
cmd_line = new CmdLine();
cmd_line.connect("http", self.nodeUrl);
cmd_line.loadCompilationData(self.inputJson, self.outputJson);
cmd_line.initDebugger(() => {
// self.isDebugging = true
next()
})
next();
});
},
function startDebug(next) {
let debuggerData = {}
let debuggerData = {};
cmd_line.events.on("locals", (data) => {
debuggerData.locals = self.simplifyDebuggerVars(data)
debuggerData.locals = self.simplifyDebuggerVars(data);
});
cmd_line.events.on("globals", (data) => {
debuggerData.contract = self.simplifyDebuggerVars(data)
})
debuggerData.contract = self.simplifyDebuggerVars(data);
});
cmd_line.startDebug(txHash, filename, () => {
cmd_line.events.on("source", () => {
let lines = cmd_line.getSource()
let lines = cmd_line.getSource();
// TODO: this is a bit of a hack
let line = lines.filter((x) => x.indexOf("=>") === 0)[0];
outputCb(lines, line, debuggerData)
})
outputCb(lines, line, debuggerData);
});
let total_size = cmd_line.getTraceLength()
cmd_line.jumpTo(total_size - 1)
cmd_line.unload()
let total_size = cmd_line.getTraceLength();
cmd_line.jumpTo(total_size - 1);
cmd_line.unload();
next()
})
next();
});
}
], () => {
})
});
}
// TODO: this is duplicated in debugger/index.js
@ -92,10 +92,10 @@ class DebuggerManager {
for (let key in data) {
let field = data[key];
new_data[`${key} (${field.type})`] = field.value
new_data[`${key} (${field.type})`] = field.value;
}
return new_data
return new_data;
}
}

View File

@ -4,47 +4,47 @@ var DebuggerManager = require('./debugger_manager.js');
class TransactionDebugger {
constructor(embark, _options) {
const self = this
this.embark = embark
const self = this;
this.embark = embark;
this.debugger_manager = new DebuggerManager("http://localhost:8545")
embark.events.on('contracts:compile:solc', this.debugger_manager.setInputJson.bind(this.debugger_manager))
embark.events.on('contracts:compiled:solc', this.debugger_manager.setOutputJson.bind(this.debugger_manager))
this.debugger_manager = new DebuggerManager("http://localhost:8545");
embark.events.on('contracts:compile:solc', this.debugger_manager.setInputJson.bind(this.debugger_manager));
embark.events.on('contracts:compiled:solc', this.debugger_manager.setOutputJson.bind(this.debugger_manager));
this.tx_tracker = {}
this.last_tx = ""
this.tx_tracker = {};
this.last_tx = "";
this.isDebugging = false
this.listenToEvents()
this.listenToCommands()
this.listentoAPI()
this.isDebugging = false;
this.listenToEvents();
this.listenToCommands();
this.listentoAPI();
}
listenToEvents() {
const self = this
const self = this;
this.embark.events.on('blockchain:tx', (tx) => {
this.embark.events.request("contracts:contract", tx.name, (contract) => {
self.tx_tracker[tx.transactionHash] = {tx: tx, contract: contract}
self.last_tx = tx.transactionHash
if (tx.status !== '0x0') return
self.tx_tracker[tx.transactionHash] = {tx: tx, contract: contract};
self.last_tx = tx.transactionHash;
if (tx.status !== '0x0') return;
self.embark.logger.info("Transaction failed");
self.debugger_manager.getLastLine(tx.transactionHash, contract.filename, (lines, line, known_vars) => {
lines.forEach((line) => {
self.embark.logger.error(line)
})
self.embark.logger.error(line);
});
self.find_vars_in_line(tx.transactionHash, line, known_vars, (found_vars) => {
if (!found_vars) return
self.embark.logger.info("vars:")
if (!found_vars) return;
self.embark.logger.info("vars:");
found_vars.forEach((variable) => {
self.embark.logger.info(`${variable.name}: ${variable.value}`)
})
self.embark.logger.info(`${variable.name}: ${variable.value}`);
});
});
})
})
})
});
});
});
}
find_vars_in_line(txHash, line, known_vars, cb) {
@ -52,7 +52,7 @@ class TransactionDebugger {
this.getGlobals(txHash, (err, globals) => {
if (err) return cb([]);
for (let variable in globals) {
let value = globals[variable]
let value = globals[variable];
if (line.indexOf(variable) >= 0) {
found_vars.push({name: variable, value: value});
}
@ -60,7 +60,7 @@ class TransactionDebugger {
for (let variable in known_vars.locals) {
let value = known_vars.locals[variable];
let variable_name = variable.split(' ')[0]
let variable_name = variable.split(' ')[0];
if (line.indexOf(variable_name) >= 0) {
found_vars.push({name: variable, value: value});
}
@ -68,87 +68,87 @@ class TransactionDebugger {
for (let variable in known_vars.contract) {
let value = known_vars.contract[variable];
let variable_name = variable.split(' ')[0]
let variable_name = variable.split(' ')[0];
if (line.indexOf(variable_name) >= 0) {
found_vars.push({name: variable, value: value});
}
}
cb(found_vars);
})
});
}
listentoAPI() {
this.debuggerData = {}
this.apiDebugger = false
this.debuggerData = {};
this.apiDebugger = false;
this.embark.registerAPICall('post', '/embark-api/debugger/start', (req, res) => {
let txHash = req.body.params.txHash
let txHash = req.body.params.txHash;
this.embark.events.request("contracts:contract:byTxHash", txHash, (err, contract) => {
if (err) {
this.embark.logger.error(err);
return res.send({error: err})
return res.send({error: err});
}
let filename = contract.filename
let filename = contract.filename;
this.apiDebugger = this.debugger_manager.createDebuggerSession(txHash, filename, () => {
this.getGlobals(txHash, (err, globals) => {
if (err) return res.send({ok: false});
this.debuggerData.globals = globals;
res.send({ok :true})
})
})
})
res.send({ok :true});
});
});
});
});
this.embark.registerAPICall('post', '/embark-api/debugger/JumpBack', (req, res) => {
this.apiDebugger.stepJumpNextBreakpoint()
res.send({ok :true})
})
this.apiDebugger.stepJumpNextBreakpoint();
res.send({ok :true});
});
this.embark.registerAPICall('post', '/embark-api/debugger/JumpForward', (req, res) => {
this.apiDebugger.stepJumpPreviousBreakpoint()
res.send({ok :true})
})
this.apiDebugger.stepJumpPreviousBreakpoint();
res.send({ok :true});
});
this.embark.registerAPICall('post', '/embark-api/debugger/StepOverForward', (req, res) => {
this.apiDebugger.stepOverForward(true)
res.send({ok :true})
})
this.apiDebugger.stepOverForward(true);
res.send({ok :true});
});
this.embark.registerAPICall('post', '/embark-api/debugger/StepOverBackward', (req, res) => {
this.apiDebugger.stepOverBack(true)
res.send({ok :true})
})
this.apiDebugger.stepOverBack(true);
res.send({ok :true});
});
this.embark.registerAPICall('post', '/embark-api/debugger/StepIntoForward', (req, res) => {
this.apiDebugger.stepIntoForward(true)
res.send({ok :true})
})
this.apiDebugger.stepIntoForward(true);
res.send({ok :true});
});
this.embark.registerAPICall('post', '/embark-api/debugger/StepIntoBackward', (req, res) => {
this.apiDebugger.stepIntoBack(true)
res.send({ok :true})
this.apiDebugger.stepIntoBack(true);
res.send({ok :true});
});
this.embark.registerAPICall('post', '/embark-api/debugger/breakpoint', (req, res) => {
console.dir("new breakpoint")
res.send({ok :true})
console.dir("new breakpoint");
res.send({ok :true});
});
this.embark.registerAPICall('ws', '/embark-api/debugger', (ws, _req) => {
if (!this.apiDebugger) return
if (!this.apiDebugger) return;
this.apiDebugger.events.on("source", (lineColumnPos, rawLocation) => {
this.debuggerData.sources = {lineColumnPos, rawLocation}
ws.send(JSON.stringify(this.debuggerData), () => {})
})
this.debuggerData.sources = {lineColumnPos, rawLocation};
ws.send(JSON.stringify(this.debuggerData), () => {});
});
this.apiDebugger.events.on("locals", (data) => {
this.debuggerData.locals = this.simplifyDebuggerVars(data)
ws.send(JSON.stringify(this.debuggerData), () => {})
this.debuggerData.locals = this.simplifyDebuggerVars(data);
ws.send(JSON.stringify(this.debuggerData), () => {});
});
this.apiDebugger.events.on("globals", (data) => {
this.debuggerData.contract = this.simplifyDebuggerVars(data)
ws.send(JSON.stringify(this.debuggerData), () => {})
})
this.debuggerData.contract = this.simplifyDebuggerVars(data);
ws.send(JSON.stringify(this.debuggerData), () => {});
});
});
}
@ -157,20 +157,20 @@ class TransactionDebugger {
for (let key in data) {
let field = data[key];
new_data[`${key} (${field.type})`] = field.value
new_data[`${key} (${field.type})`] = field.value;
}
return new_data
return new_data;
}
listenToCommands() {
const self = this
this.cmdDebugger = false
this.currentCmdTxHash = ""
const self = this;
this.cmdDebugger = false;
this.currentCmdTxHash = "";
this.embark.registerConsoleCommand((cmd, _options) => {
let cmdName = cmd.split(" ")[0]
let txHash = cmd.split(" ")[1]
let cmdName = cmd.split(" ")[0];
let txHash = cmd.split(" ")[1];
return {
match: () => cmdName === 'debug',
process: (cb) => {
@ -180,76 +180,76 @@ class TransactionDebugger {
this.embark.logger.error(err);
return;
}
let filename = contract.filename
self.currentCmdTxHash = txHash
let filename = contract.filename;
self.currentCmdTxHash = txHash;
self.cmdDebugger = self.debugger_manager.createDebuggerSession(txHash, filename, () => {
self.cmdDebugger.getSource().forEach((line) => {
console.dir(line)
})
})
console.dir(line);
});
});
});
return
return;
}
self.currentCmdTxHash = self.last_tx
let filename = self.tx_tracker[self.last_tx].contract.filename
self.currentCmdTxHash = self.last_tx;
let filename = self.tx_tracker[self.last_tx].contract.filename;
self.cmdDebugger = self.debugger_manager.createDebuggerSession(self.last_tx, filename, () => {
self.cmdDebugger.getSource().forEach((line) => {
console.dir(line)
})
})
console.dir(line);
});
});
}
};
})
});
this.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => (cmd === 'next' || cmd === 'n'),
process: (cb) => {
if (!self.cmdDebugger.currentStep()) {
console.dir("end of execution reached")
return self.cmdDebugger.unload()
console.dir("end of execution reached");
return self.cmdDebugger.unload();
}
self.cmdDebugger.stepOverForward(true)
self.cmdDebugger.stepOverForward(true);
self.cmdDebugger.getSource().forEach((line) => {
console.dir(line)
})
console.dir(line);
});
}
};
})
});
this.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => (cmd === 'previous' || cmd === 'p'),
process: (cb) => {
if (!self.cmdDebugger.currentStep()) {
console.dir("end of execution reached")
return self.cmdDebugger.unload()
console.dir("end of execution reached");
return self.cmdDebugger.unload();
}
self.cmdDebugger.stepOverBack(true)
self.cmdDebugger.stepOverBack(true);
self.cmdDebugger.getSource().forEach((line) => {
console.dir(line)
})
console.dir(line);
});
}
};
})
});
this.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => (cmd === 'var local' || cmd === 'v l' || cmd === 'vl'),
process: (cb) => {
self.cmdDebugger.displayLocals()
self.cmdDebugger.displayLocals();
}
};
})
});
this.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => (cmd === 'var global' || cmd === 'v g' || cmd === 'vg'),
process: (cb) => {
self.cmdDebugger.displayGlobals()
self.cmdDebugger.displayGlobals();
}
};
})
});
this.embark.registerConsoleCommand((cmd, _options) => {
return {
@ -262,11 +262,11 @@ class TransactionDebugger {
});
}
};
})
});
}
getGlobals(txHash, cb) {
let globals = {}
let globals = {};
this.embark.events.request("blockchain:getTransaction", txHash, (err, tx) => {
if (err) return cb(err);
@ -286,10 +286,10 @@ class TransactionDebugger {
globals["now"] = block.timestamp;
cb(null, globals);
})
})
});
});
}
}
module.exports = TransactionDebugger
module.exports = TransactionDebugger;

View File

@ -27,8 +27,8 @@ class WebServer {
this.enableCatchAll = false; // FIXME when true, some Requests end up failing (eg: process-logs)
this.events.request('processes:register', 'webserver', {
launchFn: (cb) => { this.server.start(cb) },
stopFn: (cb) => { this.server.stop(cb) }
launchFn: (cb) => { this.server.start(cb); },
stopFn: (cb) => { this.server.stop(cb); }
});
this.events.emit("status", __("Starting Server"));

View File

@ -24,7 +24,7 @@ class Whisper {
this.connectToProvider();
this.events.request('processes:register', 'whisper', (cb) => {
this.setServiceCheck()
this.setServiceCheck();
this.addWhisperToEmbarkJS();
this.addSetProvider();
this.waitForWeb3Ready(() => {

View File

@ -521,7 +521,7 @@ function copyToClipboard(text) {
function fuzzySearch(text, list, filter) {
const fuzzy = require('fuzzy');
return fuzzy.filter(text, list, {extract: (filter || function () {})})
return fuzzy.filter(text, list, {extract: (filter || function () {})});
}
module.exports = {