-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.js
87 lines (77 loc) · 2.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const parser = require("solidity-parser");
const asciiTable = require('ascii-table');
if(process.argv.length < 3) {
console.log("Error: Missing argument for sol file to scan");
process.exit(1);
}
var target = process.argv[2],
contract = parser.parseFile(target);
generateReport(target, contract);
function generateReport(target, contract) {
var table = new asciiTable(target);
table.setHeading('Contract', 'Function', 'Visibility', 'Constant', 'Returns', 'Modifiers');
contract.body.forEach(function(contract) {
if(contract.type == 'ContractStatement') {
contract.body.forEach(function(part) {
if(part.type == "FunctionDeclaration" && part.is_abstract == false) {
var func = parseFunctionPart(contract, part);
table.addRow(func.contract, func.function, func.visibility, func.constant, func.returns, func.modifiers);
}
})
}
})
console.log(table.toString());
}
function parseFunctionPart(contract, part) {
var contractName = contract.name,
funcName = part.name || "",
params = [];
if(part.params) {
part.params.forEach(function(param) {
params.push(param.literal.literal);
});
funcName += "(" + params.join(',') + ")"
} else {
funcName += "()"
}
// Default is public
var visibility = "public"
isConstant = false,
returns = [],
custom = [];
if(part.modifiers) {
part.modifiers.forEach(function(mod) {
switch(mod.name) {
case "public":
break;
case "private":
visibility = "private";
break;
case "internal":
visibility = "internal";
break;
case "external":
visibility = "external";
break;
case "constant":
isConstant = true;
break;
case "returns":
mod.params.forEach(function(param) {
returns.push(param.name);
});
break;
default:
custom.push(mod.name);
}
});
}
return {
contract: contractName,
function: funcName,
visibility: visibility,
constant: isConstant,
returns: returns,
modifiers: custom
}
}