Skip to content

Commit f45dc20

Browse files
authored
Merge pull request #87 from ConsenSys/mythx-analysis-improvements
AST should include import information and ...
2 parents 59f5855 + c37ddcb commit f45dc20

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

example/mythx-analysis

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ function requireOrExit(modName) {
1414
}
1515
}
1616

17+
function getFileContent(filepath) {
18+
const stats = fs.statSync(filepath);
19+
if (stats.isFile()) {
20+
return fs.readFileSync(filepath).toString();
21+
} else {
22+
throw new Error `File ${filepath} not found`;
23+
}
24+
}
25+
26+
function findImports(pathName) {
27+
try {
28+
return { contents: getFileContent(pathName) };
29+
} catch (e) {
30+
return { error: e.message };
31+
}
32+
}
33+
1734
// Compiles solidityFile returning JSON object.
1835
// Taken from b-mueller's sabre.
1936
function compileSolidity(solidityFile) {
@@ -41,7 +58,7 @@ function compileSolidity(solidityFile) {
4158
}
4259
};
4360
let solc = requireOrExit('solc')
44-
const compiled = JSON.parse(solc.compile(JSON.stringify(input)))
61+
const compiled = JSON.parse(solc.compile(JSON.stringify(input), findImports))
4562
for (const mess of compiled.errors) {
4663
}
4764

@@ -115,14 +132,17 @@ Options:
115132
Limit MythX analyses time to *s* seconds.
116133
The default is 300 seconds (5 minutes) for
117134
a quick analysis and 5 hours for a
118-
full analysis
119-
--no-cache-lookup
120-
force a new analysis even if there is a cached
121-
result which matches that passed data
135+
full analysis.
136+
--cache-lookup, --no-cache-lookup
137+
Force a new analysis even if there is a cached
138+
result which matches that passed data. The default
139+
is cached.
140+
--yaml Dump result in YAML format rather than JSON.
122141
123-
--help Show this help and exit
124-
--version show armlet version and exit
142+
--help Show this help and exit.
143+
--version show armlet version and exit.
125144
145+
See also sabre-mythx.
126146
`)
127147
process.exit(1)
128148
}
@@ -134,7 +154,7 @@ Options:
134154
const minimist = requireOrExit('minimist')
135155
let args = minimist(process.argv.slice(2), {
136156
boolean: [ 'debug', 'full', 'quick', 'timeout', 'version',
137-
'cache-lookup'],
157+
'cache-lookup', 'yaml'],
138158
alias: {
139159
h: 'help', '?': 'help',
140160
t: 'timeout',
@@ -224,7 +244,12 @@ const analyzeOptions = {
224244
client.analyzeWithStatus(analyzeOptions)
225245
.then(result => {
226246
const util = require('util')
227-
console.log(`${util.inspect(result, {depth: null})}`)
247+
if (args.yaml) {
248+
const yaml = requireOrExit('js-yaml')
249+
console.log(yaml.safeDump(result))
250+
} else {
251+
console.log(`${util.inspect(result, {depth: null})}`)
252+
}
228253
}).catch(err => {
229254
console.log(err)
230255
})

0 commit comments

Comments
 (0)