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