From a704635de3ab1a204648d6f41e9b4350d5100ff6 Mon Sep 17 00:00:00 2001 From: Josselin Date: Fri, 4 Jan 2019 17:32:08 +0000 Subject: [PATCH] API: - Add contract.derived_contracts --- slither/core/declarations/contract.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/slither/core/declarations/contract.py b/slither/core/declarations/contract.py index 724d3b035..51ed5e6ce 100644 --- a/slither/core/declarations/contract.py +++ b/slither/core/declarations/contract.py @@ -68,6 +68,14 @@ class Contract(ChildSlither, SourceMapping): def setInheritance(self, inheritance): self._inheritance = inheritance + @property + def derived_contracts(self): + ''' + list(Contract): Return the list of contracts derived from self + ''' + candidates = self.slither.contracts + return [c for c in candidates if self in c.inheritance] + @property def structures(self): ''' @@ -163,6 +171,18 @@ class Contract(ChildSlither, SourceMapping): ''' 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 = [c.functions_not_inherited for c in self.inheritance] + candidates = [candidate for sublist in candidates for candidate in sublist] + return [f for f in candidates if f.full_name == function.full_name] @property def all_functions_called(self):