From b549a3ed53f6503d23f87cc27390c8650a8dc0e2 Mon Sep 17 00:00:00 2001 From: Josselin Date: Fri, 4 Jan 2019 15:41:02 +0000 Subject: [PATCH] Add new APIs to core.contract: - functions_inherited - functions_not_inherited - modifiers_inherited - modifiers_not_inherited - functions_and_modifiers_inherited - functions_and_modifiers_not_inherited - functions_entry_points - get_functions_overridden_by --- slither/core/declarations/contract.py | 74 ++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/slither/core/declarations/contract.py b/slither/core/declarations/contract.py index c2c9983f7..a4e5bbc90 100644 --- a/slither/core/declarations/contract.py +++ b/slither/core/declarations/contract.py @@ -85,12 +85,6 @@ class Contract(ChildSlither, SourceMapping): def enums_as_dict(self): return self._enums - @property - def modifiers(self): - ''' - list(Modifier): List of the modifiers - ''' - return list(self._modifiers.values()) def modifiers_as_dict(self): return self._modifiers @@ -113,6 +107,74 @@ class Contract(ChildSlither, SourceMapping): ''' return [f for f in self.functions if f.contract != self] + @property + def functions_not_inherited(self): + ''' + list(Function): List of the functions defined within the contract (not inherited) + ''' + return [f for f in self.functions if f.contract == self] + + @property + def functions_entry_points(self): + ''' + list(Functions): List of public and external functions + ''' + return [f for f in self.functions if f.visibility in ['public', 'external']] + + @property + def modifiers(self): + ''' + list(Modifier): List of the modifiers + ''' + return list(self._modifiers.values()) + + @property + def modifiers_inherited(self): + ''' + list(Modifier): List of the inherited modifiers + ''' + return [m for m in self.modifiers if m.contract != self] + + @property + def modifiers_not_inherited(self): + ''' + list(Modifier): List of the modifiers defined within the contract (not inherited) + ''' + return [m for m in self.modifiers if m.contract == self] + + @property + def functions_and_modifiers(self): + ''' + list(Function|Modifier): List of the functions and modifiers + ''' + return self.functions + self.modifiers + + @property + def functions_and_modifiers_inherited(self): + ''' + list(Function|Modifier): List of the inherited functions and modifiers + ''' + return self.functions_inherited + self.modifiers_inherited + + @property + def functions_and_modifiers_not_inherited(self): + ''' + list(Function|Modifier): List of the functions and modifiers defined within the contract (not inherited) + ''' + return self.functions_not_inherited + self.modifiers_not_inherited + + def get_functions_overridden_by(self, function): + ''' + Return the list of functions overriden by the function + Args: + (core.Function) + Returns: + list(core.Function) + + ''' + candidates = self.functions_inherited + return [f for f in candidates if f.name == function] + @property def all_functions_called(self): '''