|
|
|
@ -3,11 +3,10 @@ |
|
|
|
|
""" |
|
|
|
|
import collections |
|
|
|
|
from slither.printers.abstract_printer import AbstractPrinter |
|
|
|
|
from slither.utils import json_utils |
|
|
|
|
from slither.utils.colors import blue, green, magenta |
|
|
|
|
|
|
|
|
|
class ContractSummary(AbstractPrinter): |
|
|
|
|
|
|
|
|
|
class ContractSummary(AbstractPrinter): |
|
|
|
|
ARGUMENT = 'contract-summary' |
|
|
|
|
HELP = 'Print a summary of the contracts' |
|
|
|
|
|
|
|
|
@ -21,42 +20,42 @@ class ContractSummary(AbstractPrinter): |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
txt = "" |
|
|
|
|
result = {} |
|
|
|
|
|
|
|
|
|
all_contracts = [] |
|
|
|
|
for c in self.contracts: |
|
|
|
|
(name, _inheritance, _var, func_summaries, _modif_summaries) = c.get_summary(False) |
|
|
|
|
txt += blue("\n+ Contract %s\n"%name) |
|
|
|
|
result[name] = {} |
|
|
|
|
# (c_name, f_name, visi, _, _, _, _, _) in func_summaries |
|
|
|
|
public = [(elem[0], (elem[1], elem[2]) ) for elem in func_summaries] |
|
|
|
|
txt += blue("\n+ Contract %s\n" % c.name) |
|
|
|
|
additional_fields = {"elements": []} |
|
|
|
|
|
|
|
|
|
# Order the function with |
|
|
|
|
# contract_declarer -> list_functions |
|
|
|
|
public = [(f.contract_declarer.name, f) for f in c.functions if (not f.is_shadowed)] |
|
|
|
|
collect = collections.defaultdict(list) |
|
|
|
|
for a,b in public: |
|
|
|
|
for a, b in public: |
|
|
|
|
collect[a].append(b) |
|
|
|
|
public = list(collect.items()) |
|
|
|
|
|
|
|
|
|
for contract, functions in public: |
|
|
|
|
txt += blue(" - From {}\n".format(contract)) |
|
|
|
|
result[name]['from'] = str(contract) |
|
|
|
|
functions = sorted(functions) |
|
|
|
|
result[name]['functions'] = {} |
|
|
|
|
result[name]['functions']['visible'] = [] |
|
|
|
|
result[name]['functions']['invisible'] = [] |
|
|
|
|
result[name]['functions']['others'] = [] |
|
|
|
|
for (function, visi) in functions: |
|
|
|
|
if visi in ['external', 'public']: |
|
|
|
|
result[name]['functions']['visible'].append({'function': function, 'visi': visi}) |
|
|
|
|
txt += green(" - {} ({})\n".format(function, visi)) |
|
|
|
|
for (function, visi) in functions: |
|
|
|
|
if visi in ['internal', 'private']: |
|
|
|
|
result[name]['functions']['invisible'].append({'function': function, 'visi': visi}) |
|
|
|
|
txt += magenta(" - {} ({})\n".format(function, visi)) |
|
|
|
|
for (function, visi) in functions: |
|
|
|
|
if visi not in ['external', 'public', 'internal', 'private']: |
|
|
|
|
result[name]['functions']['others'].append({'function': function, 'visi': visi}) |
|
|
|
|
txt += " - {} ({})\n".format(function, visi) |
|
|
|
|
|
|
|
|
|
functions = sorted(functions, key=lambda f: f.full_name) |
|
|
|
|
|
|
|
|
|
for function in functions: |
|
|
|
|
if function.visibility in ['external', 'public']: |
|
|
|
|
txt += green(" - {} ({})\n".format(function, function.visibility)) |
|
|
|
|
if function.visibility in ['internal', 'private']: |
|
|
|
|
txt += magenta(" - {} ({})\n".format(function, function.visibility)) |
|
|
|
|
if function.visibility not in ['external', 'public', 'internal', 'private']: |
|
|
|
|
txt += " - {} ({})\n".format(function, function.visibility) |
|
|
|
|
|
|
|
|
|
self.add_function_to_json(function, additional_fields, additional_fields={"visibility": |
|
|
|
|
function.visibility}) |
|
|
|
|
|
|
|
|
|
all_contracts.append((c, additional_fields)) |
|
|
|
|
|
|
|
|
|
self.info(txt) |
|
|
|
|
|
|
|
|
|
json = self.generate_json_result(txt, additional_fields=result) |
|
|
|
|
json = self.generate_json_result(txt) |
|
|
|
|
for contract, additional_fields in all_contracts: |
|
|
|
|
self.add_contract_to_json(contract, json, additional_fields=additional_fields) |
|
|
|
|
|
|
|
|
|
return json |
|
|
|
|
return json |
|
|
|
|