embark-mythx/index.js

83 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-04-15 10:11:43 +02:00
const mythx = require('./mythx')
module.exports = function(embark) {
let contracts;
// Register for compilation results
embark.events.on("contracts:compiled:solc", (res) => {
2019-04-22 17:47:01 +02:00
//console.log("contracts:compiled:solc", JSON.stringify(res));
contracts = res;
});
2019-04-15 10:11:43 +02:00
embark.registerConsoleCommand({
description: "Run MythX analysis",
matches: (cmd) => {
embark.logger.info('cmd', cmd)
const cmdName = cmd.match(/".*?"|\S+/g)
embark.logger.info("cmd === 'verify': " + cmd === 'verify')
//embark.logger.info('cmdName.length === 1', cmdName.length === 1)
return (cmd === 'verify' && cmdName.length === 1)
},
usage: "verify [options]",
process: async (cmd, callback) => {
//embark.logger.info("embark.logger", JSON.stringify(embark.logger))
let cfg = parseOptions(cmd)
embark.logger.info('cmd', cmd)
embark.logger.info('cfg', JSON.stringify(cfg))
try {
2019-04-22 17:47:01 +02:00
embark.logger.info("Running MythX analysis in background.")
const result = await mythx(contracts, cfg, embark)
2019-04-22 17:47:01 +02:00
//embark.logger.info("result", result)
2019-04-15 10:11:43 +02:00
if (returnCode === 0) {
return callback(null, "returnCode: " + returnCode)
} else if (returnCode === 1) {
embark.logger.error("Analysis returned with exit code 1.")
return callback()
} else {
//TODO: Figure out how to use error with callback properly.
return callback(new Error("Unexpected Error: return value of `analyze` should be either 0 or 1."), null)
}
2019-04-22 17:47:01 +02:00
2019-04-15 10:11:43 +02:00
} catch (e) {
embark.logger.error("error", e)
return callback(e, "ERR: " + e.message)
}
}
})
embark.registerConsoleCommand({
description: "Help",
matches: (cmd) => {
embark.logger.info('cmd', cmd)
const cmdName = cmd.match(/".*?"|\S+/g)
embark.logger.info('cmdName', cmdName)
//embark.logger.info("cmdName[0] === 'verify' && cmdName[1] === 'help'", cmdName[0] === 'verify' && cmdName[1] === 'help')
return (Array.isArray(cmdName) &&
(cmdName[0] === 'verify' &&
cmdName[1] === 'help'))
},
usage: "verify help",
process: (cmd, callback) => {
return callback(null, help())
}
})
function help() {
return (
"Usage: ...\n" +
"\n" +
"Commands:\n" +
"\thelp\t\tThis help."
)
}
function parseOptions(options) {
let config = {}
//TODO
return config
}
}