You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/concepts/imports.md
+29-29
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ The simplest use-case for imports is wanting to call a function that is an `@exp
4
4
5
5
__NOTE:__`from x import y` and starred imports are not supported at this time. Importing a smart contract imports all of the `@export` functions from it and none of the variables.
6
6
7
-
complex_app
7
+
complex_app.py
8
8
```python
9
9
@export
10
10
defreturn_1():
@@ -19,7 +19,7 @@ def return_3():
19
19
return3
20
20
```
21
21
22
-
import_example
22
+
import_example.py
23
23
```python
24
24
import complex_app
25
25
@@ -43,7 +43,7 @@ To do this, we have to use the `importlib` in the Contracting standard library.
43
43
44
44
This function behaves similar to the analogous `importlib` function included in the Python standard library. Calling it will return a module object that has only the `@export` functions available to call and pass arguments to.
45
45
46
-
token_1
46
+
token_1.py
47
47
```python
48
48
balances = Hash()
49
49
@construct
@@ -58,7 +58,7 @@ def send(amount, to):
58
58
balances[to] += amount
59
59
```
60
60
61
-
token_2
61
+
token_2.py
62
62
```python
63
63
balances = Hash()
64
64
@construct
@@ -73,7 +73,7 @@ def send(amount, to):
73
73
balances[to] += amount
74
74
```
75
75
76
-
exchange
76
+
exchange.py
77
77
```python
78
78
@export
79
79
defsend(token, amount, to):
@@ -87,7 +87,7 @@ Luckily, both contracts have the same interface and have a function called `send
87
87
88
88
A smart contract can define an interface to enforce contracts against. Enforcement can be on the functions and/or the variables. Enforcement is 'weak' in the sense that a contract can have additional functions or variables and still succeed an interface test.
89
89
90
-
exchange
90
+
exchange.py
91
91
```python
92
92
token_interface = [
93
93
importlib.Func('send', args=('amount', 'to')),
@@ -118,21 +118,21 @@ A variable definition for the name, a string, and the type, which is either Vari
118
118
119
119
```python
120
120
interface_1 = [
121
-
importlib.Func('something', private=True)
121
+
importlib.Func('something', private=True)
122
122
]
123
123
124
124
defvalid_contract():
125
-
defsomething(): # Correct name and private
126
-
return123
125
+
defsomething(): # Correct name and private
126
+
return123
127
127
128
-
@export
129
-
defsomething_else():
130
-
return456
128
+
@export
129
+
defsomething_else():
130
+
return456
131
131
132
132
definvalid_contract():
133
-
@export
134
-
defsomething(): # Correct name, but exported
135
-
return123
133
+
@export
134
+
defsomething(): # Correct name, but exported
135
+
return123
136
136
```
137
137
138
138
@@ -142,17 +142,17 @@ interface_2 = [
142
142
]
143
143
144
144
defvalid_contract():
145
-
@export
146
-
deffunc(a, b, c): # Exported function with same name and args in correct order
147
-
return a + b + c
145
+
@export
146
+
deffunc(a, b, c): # Exported function with same name and args in correct order
147
+
return a + b + c
148
148
149
149
definvalid_contract():
150
-
deffunc(a, c, b): # Correct name, but private, and keyword arguments are out of order
151
-
return a + b + c
150
+
deffunc(a, c, b): # Correct name, but private, and keyword arguments are out of order
151
+
return a + b + c
152
152
153
-
@export
154
-
defnot_func(a, b, c): # Exported and correct keyword args but not the right name
155
-
return a + b + c
153
+
@export
154
+
defnot_func(a, b, c): # Exported and correct keyword args but not the right name
0 commit comments