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
The \_\_init\_\_ arguments are automatically filled in for you during compilation and runtime. You do not have to provide any of them.
88
88
89
-
some_contract
89
+
some_contract.py
90
90
```python
91
91
owner = Variable()
92
92
```
@@ -100,17 +100,17 @@ Driver is pulled from the Runtime (`rt`) module when the contract is being execu
100
100
101
101
#### set(self, value)
102
102
103
-
some_contract
103
+
some_contract.py
104
104
```python
105
105
owner = Variable()
106
106
owner.set('stu')
107
107
```
108
108
109
109
Executes on contract runtime and sets the value for this variable. The above code causes the following key/value pair to be written into the state.
110
110
111
-
Key | Value
112
-
- | -
113
-
some_contract.owner | stu
111
+
|Key|Value|
112
+
|-------------------|-------|
113
+
|some_contract.owner | stu|
114
114
115
115
__NOTE:__ You have to use the `set` method to alter data. If you use standard `=`, it will just cause the object to be set to whatever you pass.
116
116
@@ -126,7 +126,7 @@ owner
126
126
127
127
#### get(self)
128
128
129
-
some_contract
129
+
some_contract.py
130
130
```python
131
131
owner = Variable()
132
132
owner.set('stu')
@@ -179,7 +179,7 @@ class Hash(Datum):
179
179
180
180
Similar to Variable's \_\_init\_\_ except that a different keyword argument `default_value` allows you to set a value to return when the key does not exist. This is good for ledgers or applications where you need to have a base value.
181
181
182
-
some_contract
182
+
some_contract.py
183
183
```python
184
184
balances = Hash(default_value=0)
185
185
balances['stu'] =1_000_000
@@ -192,7 +192,7 @@ balances['raghu'] == 0 # True
192
192
193
193
Equivalent to Variable's `get` but accepts an additional argument to specify the key. For example, the following code executed would result in the following state space.
194
194
195
-
some_contract
195
+
some_contract.py
196
196
```python
197
197
balances = Hash(default_value=0)
198
198
balances.set('stu', 1_000_000)
@@ -210,7 +210,7 @@ balances.set('tejas', 777)
210
210
211
211
You can provide an arbitrary number of keys (up to 16) to `set` and it will react accordingly, writing data to the dimension of keys that you provided. For example:
212
212
213
-
subaccounts
213
+
subaccounts.py
214
214
```python
215
215
balances = Hash(default_value=0)
216
216
balances.set('stu', 1_000_000)
@@ -232,7 +232,7 @@ This will create the following state space:
232
232
233
233
Inverse of `set`, where the value for a provided key is returned. If it is `None`, it will set it to the `default_value` provided on initialization.
234
234
235
-
some_contract
235
+
some_contract.py
236
236
```python
237
237
balances = Hash(default_value=0)
238
238
balances.set('stu', 1_000_000)
@@ -249,7 +249,7 @@ The same caveat applies here
249
249
#### Multihashes
250
250
Just like `set`, you retrieve data stored in multihashes by providing the list of keys used to write data to that location. Just like `get` with a single key, the default value will be returned if no value at the storage location is found.
Equal functionality to `set`, but allows slice notation for convenience. __This is less verbose and the preferred method of setting storage on a Hash.__
303
303
304
-
subaccounts
304
+
subaccounts.py
305
305
```python
306
306
balances = Hash(default_value=0)
307
307
balances['stu'] =1_000_000
@@ -321,7 +321,7 @@ owner['stu']
321
321
#### \_\_getitem\_\_(self, key):
322
322
Equal functionality to `set`, but allows slice notation for convenience. __This is less verbose and the preferred method of setting storage on a Hash.__
0 commit comments