From af6727c5610a38a326aecb73f887d48987c1ffa2 Mon Sep 17 00:00:00 2001 From: webthethird Date: Fri, 17 Mar 2023 09:52:29 -0500 Subject: [PATCH] Add `Contract.fallback_function` and `.receive_function` properties --- slither/core/declarations/contract.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/slither/core/declarations/contract.py b/slither/core/declarations/contract.py index 95b05aa6b..88405b98a 100644 --- a/slither/core/declarations/contract.py +++ b/slither/core/declarations/contract.py @@ -89,6 +89,9 @@ class Contract(SourceMapping): # pylint: disable=too-many-public-methods self._signatures: Optional[List[str]] = None self._signatures_declared: Optional[List[str]] = None + self._fallback_function: Optional["FunctionContract"] = None + self._receive_function: Optional["FunctionContract"] = None + self._is_upgradeable: Optional[bool] = None self._is_upgradeable_proxy: Optional[bool] = None self._upgradeable_version: Optional[str] = None @@ -649,6 +652,24 @@ class Contract(SourceMapping): # pylint: disable=too-many-public-methods """ return self.functions_declared + self.modifiers_declared # type: ignore + @property + def fallback_function(self) -> Optional["FunctionContract"]: + if self._fallback_function is None: + for f in self.functions: + if f.is_fallback: + self._fallback_function = f + break + return self._fallback_function + + @property + def receive_function(self) -> Optional["FunctionContract"]: + if self._receive_function is None: + for f in self.functions: + if f.is_receive: + self._receive_function = f + break + return self._receive_function + def available_elements_from_inheritances( self, elements: Dict[str, "Function"],