crytic_compile.utils.natspec

  1"""
  2Natspec module https://solidity.readthedocs.io/en/latest/natspec-format.html
  3"""
  4from typing import Dict, Optional, Union
  5
  6
  7class UserMethod:
  8    """
  9    Model the user method
 10    """
 11
 12    def __init__(self, method: Union[Dict, str]) -> None:
 13        """Init the object
 14
 15        Args:
 16            method (Union[Dict, str]): Method info (notice)
 17        """
 18        # Constructors dont have "notice: '..'"
 19        if isinstance(method, str):
 20            self._notice: Optional[str] = method
 21        else:
 22            self._notice = method.get("notice", None)
 23
 24    @property
 25    def notice(self) -> Optional[str]:
 26        """Return the method notice
 27
 28        Returns:
 29            Optional[str]: method notice
 30        """
 31        return self._notice
 32
 33    def export(self) -> Dict:
 34        """Export to a python dict
 35
 36        Returns:
 37            Dict: Exported user method
 38        """
 39        return {"notice": self.notice}
 40
 41
 42class DevMethod:
 43    """
 44    Model the dev method
 45    """
 46
 47    def __init__(self, method: Dict) -> None:
 48        """Init the object
 49
 50        Args:
 51            method (Dict): Method infos (author, details, params, return)
 52        """
 53        self._author: Optional[str] = method.get("author", None)
 54        self._details: Optional[str] = method.get("details", None)
 55        self._params: Dict[str, str] = method.get("params", {})
 56        self._return: Optional[str] = method.get("return", None)
 57
 58    @property
 59    def author(self) -> Optional[str]:
 60        """Return the method author
 61
 62        Returns:
 63            Optional[str]: method author
 64        """
 65        return self._author
 66
 67    @property
 68    def details(self) -> Optional[str]:
 69        """Return the method details
 70
 71        Returns:
 72            Optional[str]: method details
 73        """
 74        return self._details
 75
 76    @property
 77    def method_return(self) -> Optional[str]:
 78        """Return the method return
 79
 80        Returns:
 81            Optional[str]: method return
 82        """
 83        return self._return
 84
 85    @property
 86    def params(self) -> Dict[str, str]:
 87        """Return the method params
 88
 89        Returns:
 90            Dict[str, str]: method_name => params
 91        """
 92        return self._params
 93
 94    def export(self) -> Dict:
 95        """Export to a python dict
 96
 97        Returns:
 98            Dict: Exported dev method
 99        """
100        return {
101            "author": self.author,
102            "details": self.details,
103            "params": self.params,
104            "return": self.method_return,
105        }
106
107
108class UserDoc:
109    """
110    Model the user doc
111    """
112
113    def __init__(self, userdoc: dict):
114        """Init the object
115
116        Args:
117            userdoc (dict): User doc (notice, methods)
118        """
119        self._notice: Optional[str] = userdoc.get("notice", None)
120        self._methods: Dict[str, UserMethod] = {
121            k: UserMethod(item) for k, item in userdoc.get("methods", {}).items()
122        }
123
124    @property
125    def notice(self) -> Optional[str]:
126        """Return the user notice
127
128        Returns:
129            Optional[str]: user notice
130        """
131        return self._notice
132
133    @property
134    def methods(self) -> Dict[str, UserMethod]:
135        """Return the user methods
136
137        Returns:
138            Optional[str]: method_name => UserMethod
139        """
140        return self._methods
141
142    def export(self) -> Dict:
143        """Export to a python dict
144
145        Returns:
146            Dict: Exported user doc
147        """
148        return {
149            "methods": {k: items.export() for k, items in self.methods.items()},
150            "notice": self.notice,
151        }
152
153
154class DevDoc:
155    """
156    Model the dev doc
157    """
158
159    def __init__(self, devdoc: Dict):
160        """Init the object
161
162        Args:
163            devdoc (Dict): dev doc (author, details, methods, title)
164        """
165        self._author: Optional[str] = devdoc.get("author", None)
166        self._details: Optional[str] = devdoc.get("details", None)
167        self._methods: Dict[str, DevMethod] = {
168            k: DevMethod(item) for k, item in devdoc.get("methods", {}).items()
169        }
170        self._title: Optional[str] = devdoc.get("title", None)
171
172    @property
173    def author(self) -> Optional[str]:
174        """Return the dev author
175
176        Returns:
177            Optional[str]: dev author
178        """
179        return self._author
180
181    @property
182    def details(self) -> Optional[str]:
183        """Return the dev details
184
185        Returns:
186            Optional[str]: dev details
187        """
188        return self._details
189
190    @property
191    def methods(self) -> Dict[str, DevMethod]:
192        """Return the dev methods
193
194        Returns:
195            Dict[str, DevMethod]: method_name => DevMethod
196        """
197        return self._methods
198
199    @property
200    def title(self) -> Optional[str]:
201        """Return the dev title
202
203        Returns:
204            Optional[str]: dev title
205        """
206        return self._title
207
208    def export(self) -> Dict:
209        """Export to a python dict
210
211        Returns:
212            Dict: Exported dev doc
213        """
214        return {
215            "methods": {k: items.export() for k, items in self.methods.items()},
216            "author": self.author,
217            "details": self.details,
218            "title": self.title,
219        }
220
221
222class Natspec:
223    """
224    Model natspec
225    """
226
227    def __init__(self, userdoc: Dict, devdoc: Dict):
228        """Init the object
229
230        Args:
231            userdoc (Dict): user doc
232            devdoc (Dict): dev doc
233        """
234        self._userdoc: UserDoc = UserDoc(userdoc)
235        self._devdoc: DevDoc = DevDoc(devdoc)
236
237    @property
238    def userdoc(self) -> UserDoc:
239        """Return the userdoc
240
241        Returns:
242            UserDoc: user documentation
243        """
244        return self._userdoc
245
246    @property
247    def devdoc(self) -> DevDoc:
248        """Return the devdoc
249
250        Returns:
251            DevDoc: dev documentation
252        """
253        return self._devdoc
class UserMethod:
 8class UserMethod:
 9    """
10    Model the user method
11    """
12
13    def __init__(self, method: Union[Dict, str]) -> None:
14        """Init the object
15
16        Args:
17            method (Union[Dict, str]): Method info (notice)
18        """
19        # Constructors dont have "notice: '..'"
20        if isinstance(method, str):
21            self._notice: Optional[str] = method
22        else:
23            self._notice = method.get("notice", None)
24
25    @property
26    def notice(self) -> Optional[str]:
27        """Return the method notice
28
29        Returns:
30            Optional[str]: method notice
31        """
32        return self._notice
33
34    def export(self) -> Dict:
35        """Export to a python dict
36
37        Returns:
38            Dict: Exported user method
39        """
40        return {"notice": self.notice}

Model the user method

UserMethod(method: Union[Dict, str])
13    def __init__(self, method: Union[Dict, str]) -> None:
14        """Init the object
15
16        Args:
17            method (Union[Dict, str]): Method info (notice)
18        """
19        # Constructors dont have "notice: '..'"
20        if isinstance(method, str):
21            self._notice: Optional[str] = method
22        else:
23            self._notice = method.get("notice", None)

Init the object

Args: method (Union[Dict, str]): Method info (notice)

notice: Union[str, NoneType]
25    @property
26    def notice(self) -> Optional[str]:
27        """Return the method notice
28
29        Returns:
30            Optional[str]: method notice
31        """
32        return self._notice

Return the method notice

Returns: Optional[str]: method notice

def export(self) -> Dict:
34    def export(self) -> Dict:
35        """Export to a python dict
36
37        Returns:
38            Dict: Exported user method
39        """
40        return {"notice": self.notice}

Export to a python dict

Returns: Dict: Exported user method

class DevMethod:
 43class DevMethod:
 44    """
 45    Model the dev method
 46    """
 47
 48    def __init__(self, method: Dict) -> None:
 49        """Init the object
 50
 51        Args:
 52            method (Dict): Method infos (author, details, params, return)
 53        """
 54        self._author: Optional[str] = method.get("author", None)
 55        self._details: Optional[str] = method.get("details", None)
 56        self._params: Dict[str, str] = method.get("params", {})
 57        self._return: Optional[str] = method.get("return", None)
 58
 59    @property
 60    def author(self) -> Optional[str]:
 61        """Return the method author
 62
 63        Returns:
 64            Optional[str]: method author
 65        """
 66        return self._author
 67
 68    @property
 69    def details(self) -> Optional[str]:
 70        """Return the method details
 71
 72        Returns:
 73            Optional[str]: method details
 74        """
 75        return self._details
 76
 77    @property
 78    def method_return(self) -> Optional[str]:
 79        """Return the method return
 80
 81        Returns:
 82            Optional[str]: method return
 83        """
 84        return self._return
 85
 86    @property
 87    def params(self) -> Dict[str, str]:
 88        """Return the method params
 89
 90        Returns:
 91            Dict[str, str]: method_name => params
 92        """
 93        return self._params
 94
 95    def export(self) -> Dict:
 96        """Export to a python dict
 97
 98        Returns:
 99            Dict: Exported dev method
100        """
101        return {
102            "author": self.author,
103            "details": self.details,
104            "params": self.params,
105            "return": self.method_return,
106        }

Model the dev method

DevMethod(method: Dict)
48    def __init__(self, method: Dict) -> None:
49        """Init the object
50
51        Args:
52            method (Dict): Method infos (author, details, params, return)
53        """
54        self._author: Optional[str] = method.get("author", None)
55        self._details: Optional[str] = method.get("details", None)
56        self._params: Dict[str, str] = method.get("params", {})
57        self._return: Optional[str] = method.get("return", None)

Init the object

Args: method (Dict): Method infos (author, details, params, return)

author: Union[str, NoneType]
59    @property
60    def author(self) -> Optional[str]:
61        """Return the method author
62
63        Returns:
64            Optional[str]: method author
65        """
66        return self._author

Return the method author

Returns: Optional[str]: method author

details: Union[str, NoneType]
68    @property
69    def details(self) -> Optional[str]:
70        """Return the method details
71
72        Returns:
73            Optional[str]: method details
74        """
75        return self._details

Return the method details

Returns: Optional[str]: method details

method_return: Union[str, NoneType]
77    @property
78    def method_return(self) -> Optional[str]:
79        """Return the method return
80
81        Returns:
82            Optional[str]: method return
83        """
84        return self._return

Return the method return

Returns: Optional[str]: method return

params: Dict[str, str]
86    @property
87    def params(self) -> Dict[str, str]:
88        """Return the method params
89
90        Returns:
91            Dict[str, str]: method_name => params
92        """
93        return self._params

Return the method params

Returns: Dict[str, str]: method_name => params

def export(self) -> Dict:
 95    def export(self) -> Dict:
 96        """Export to a python dict
 97
 98        Returns:
 99            Dict: Exported dev method
100        """
101        return {
102            "author": self.author,
103            "details": self.details,
104            "params": self.params,
105            "return": self.method_return,
106        }

Export to a python dict

Returns: Dict: Exported dev method

class UserDoc:
109class UserDoc:
110    """
111    Model the user doc
112    """
113
114    def __init__(self, userdoc: dict):
115        """Init the object
116
117        Args:
118            userdoc (dict): User doc (notice, methods)
119        """
120        self._notice: Optional[str] = userdoc.get("notice", None)
121        self._methods: Dict[str, UserMethod] = {
122            k: UserMethod(item) for k, item in userdoc.get("methods", {}).items()
123        }
124
125    @property
126    def notice(self) -> Optional[str]:
127        """Return the user notice
128
129        Returns:
130            Optional[str]: user notice
131        """
132        return self._notice
133
134    @property
135    def methods(self) -> Dict[str, UserMethod]:
136        """Return the user methods
137
138        Returns:
139            Optional[str]: method_name => UserMethod
140        """
141        return self._methods
142
143    def export(self) -> Dict:
144        """Export to a python dict
145
146        Returns:
147            Dict: Exported user doc
148        """
149        return {
150            "methods": {k: items.export() for k, items in self.methods.items()},
151            "notice": self.notice,
152        }

Model the user doc

UserDoc(userdoc: dict)
114    def __init__(self, userdoc: dict):
115        """Init the object
116
117        Args:
118            userdoc (dict): User doc (notice, methods)
119        """
120        self._notice: Optional[str] = userdoc.get("notice", None)
121        self._methods: Dict[str, UserMethod] = {
122            k: UserMethod(item) for k, item in userdoc.get("methods", {}).items()
123        }

Init the object

Args: userdoc (dict): User doc (notice, methods)

notice: Union[str, NoneType]
125    @property
126    def notice(self) -> Optional[str]:
127        """Return the user notice
128
129        Returns:
130            Optional[str]: user notice
131        """
132        return self._notice

Return the user notice

Returns: Optional[str]: user notice

methods: Dict[str, UserMethod]
134    @property
135    def methods(self) -> Dict[str, UserMethod]:
136        """Return the user methods
137
138        Returns:
139            Optional[str]: method_name => UserMethod
140        """
141        return self._methods

Return the user methods

Returns: Optional[str]: method_name => UserMethod

def export(self) -> Dict:
143    def export(self) -> Dict:
144        """Export to a python dict
145
146        Returns:
147            Dict: Exported user doc
148        """
149        return {
150            "methods": {k: items.export() for k, items in self.methods.items()},
151            "notice": self.notice,
152        }

Export to a python dict

Returns: Dict: Exported user doc

class DevDoc:
155class DevDoc:
156    """
157    Model the dev doc
158    """
159
160    def __init__(self, devdoc: Dict):
161        """Init the object
162
163        Args:
164            devdoc (Dict): dev doc (author, details, methods, title)
165        """
166        self._author: Optional[str] = devdoc.get("author", None)
167        self._details: Optional[str] = devdoc.get("details", None)
168        self._methods: Dict[str, DevMethod] = {
169            k: DevMethod(item) for k, item in devdoc.get("methods", {}).items()
170        }
171        self._title: Optional[str] = devdoc.get("title", None)
172
173    @property
174    def author(self) -> Optional[str]:
175        """Return the dev author
176
177        Returns:
178            Optional[str]: dev author
179        """
180        return self._author
181
182    @property
183    def details(self) -> Optional[str]:
184        """Return the dev details
185
186        Returns:
187            Optional[str]: dev details
188        """
189        return self._details
190
191    @property
192    def methods(self) -> Dict[str, DevMethod]:
193        """Return the dev methods
194
195        Returns:
196            Dict[str, DevMethod]: method_name => DevMethod
197        """
198        return self._methods
199
200    @property
201    def title(self) -> Optional[str]:
202        """Return the dev title
203
204        Returns:
205            Optional[str]: dev title
206        """
207        return self._title
208
209    def export(self) -> Dict:
210        """Export to a python dict
211
212        Returns:
213            Dict: Exported dev doc
214        """
215        return {
216            "methods": {k: items.export() for k, items in self.methods.items()},
217            "author": self.author,
218            "details": self.details,
219            "title": self.title,
220        }

Model the dev doc

DevDoc(devdoc: Dict)
160    def __init__(self, devdoc: Dict):
161        """Init the object
162
163        Args:
164            devdoc (Dict): dev doc (author, details, methods, title)
165        """
166        self._author: Optional[str] = devdoc.get("author", None)
167        self._details: Optional[str] = devdoc.get("details", None)
168        self._methods: Dict[str, DevMethod] = {
169            k: DevMethod(item) for k, item in devdoc.get("methods", {}).items()
170        }
171        self._title: Optional[str] = devdoc.get("title", None)

Init the object

Args: devdoc (Dict): dev doc (author, details, methods, title)

author: Union[str, NoneType]
173    @property
174    def author(self) -> Optional[str]:
175        """Return the dev author
176
177        Returns:
178            Optional[str]: dev author
179        """
180        return self._author

Return the dev author

Returns: Optional[str]: dev author

details: Union[str, NoneType]
182    @property
183    def details(self) -> Optional[str]:
184        """Return the dev details
185
186        Returns:
187            Optional[str]: dev details
188        """
189        return self._details

Return the dev details

Returns: Optional[str]: dev details

methods: Dict[str, DevMethod]
191    @property
192    def methods(self) -> Dict[str, DevMethod]:
193        """Return the dev methods
194
195        Returns:
196            Dict[str, DevMethod]: method_name => DevMethod
197        """
198        return self._methods

Return the dev methods

Returns: Dict[str, DevMethod]: method_name => DevMethod

title: Union[str, NoneType]
200    @property
201    def title(self) -> Optional[str]:
202        """Return the dev title
203
204        Returns:
205            Optional[str]: dev title
206        """
207        return self._title

Return the dev title

Returns: Optional[str]: dev title

def export(self) -> Dict:
209    def export(self) -> Dict:
210        """Export to a python dict
211
212        Returns:
213            Dict: Exported dev doc
214        """
215        return {
216            "methods": {k: items.export() for k, items in self.methods.items()},
217            "author": self.author,
218            "details": self.details,
219            "title": self.title,
220        }

Export to a python dict

Returns: Dict: Exported dev doc

class Natspec:
223class Natspec:
224    """
225    Model natspec
226    """
227
228    def __init__(self, userdoc: Dict, devdoc: Dict):
229        """Init the object
230
231        Args:
232            userdoc (Dict): user doc
233            devdoc (Dict): dev doc
234        """
235        self._userdoc: UserDoc = UserDoc(userdoc)
236        self._devdoc: DevDoc = DevDoc(devdoc)
237
238    @property
239    def userdoc(self) -> UserDoc:
240        """Return the userdoc
241
242        Returns:
243            UserDoc: user documentation
244        """
245        return self._userdoc
246
247    @property
248    def devdoc(self) -> DevDoc:
249        """Return the devdoc
250
251        Returns:
252            DevDoc: dev documentation
253        """
254        return self._devdoc

Model natspec

Natspec(userdoc: Dict, devdoc: Dict)
228    def __init__(self, userdoc: Dict, devdoc: Dict):
229        """Init the object
230
231        Args:
232            userdoc (Dict): user doc
233            devdoc (Dict): dev doc
234        """
235        self._userdoc: UserDoc = UserDoc(userdoc)
236        self._devdoc: DevDoc = DevDoc(devdoc)

Init the object

Args: userdoc (Dict): user doc devdoc (Dict): dev doc

userdoc: UserDoc
238    @property
239    def userdoc(self) -> UserDoc:
240        """Return the userdoc
241
242        Returns:
243            UserDoc: user documentation
244        """
245        return self._userdoc

Return the userdoc

Returns: UserDoc: user documentation

devdoc: DevDoc
247    @property
248    def devdoc(self) -> DevDoc:
249        """Return the devdoc
250
251        Returns:
252            DevDoc: dev documentation
253        """
254        return self._devdoc

Return the devdoc

Returns: DevDoc: dev documentation