Skip to content

Commit 0cea63f

Browse files
authored
Update storage.md
1 parent 27d06fb commit 0cea63f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

docs/concepts/storage.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Variable(Datum):
8686
#### \_\_init\_\_(self, contract, name, driver, t)
8787
The \_\_init\_\_ arguments are automatically filled in for you during compilation and runtime. You do not have to provide any of them.
8888

89-
some_contract.py
89+
some_contract.py (Smart Contract)
9090
```python
9191
owner = Variable()
9292
```
@@ -100,7 +100,7 @@ Driver is pulled from the Runtime (`rt`) module when the contract is being execu
100100

101101
#### set(self, value)
102102

103-
some_contract.py
103+
some_contract.py (Smart Contract)
104104
```python
105105
owner = Variable()
106106
owner.set('stu')
@@ -126,7 +126,7 @@ owner
126126

127127
#### get(self)
128128

129-
some_contract.py
129+
some_contract.py (Smart Contract)
130130
```python
131131
owner = Variable()
132132
owner.set('stu')
@@ -179,7 +179,7 @@ class Hash(Datum):
179179

180180
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.
181181

182-
some_contract.py
182+
some_contract.py (Smart Contract)
183183
```python
184184
balances = Hash(default_value=0)
185185
balances['stu'] = 1_000_000
@@ -192,7 +192,7 @@ balances['raghu'] == 0 # True
192192

193193
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.
194194

195-
some_contract.py
195+
some_contract.py (Smart Contract)
196196
```python
197197
balances = Hash(default_value=0)
198198
balances.set('stu', 1_000_000)
@@ -210,7 +210,7 @@ balances.set('tejas', 777)
210210

211211
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:
212212

213-
subaccounts.py
213+
subaccounts.py (Smart Contract)
214214
```python
215215
balances = Hash(default_value=0)
216216
balances.set('stu', 1_000_000)
@@ -232,7 +232,7 @@ This will create the following state space:
232232

233233
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.
234234

235-
some_contract.py
235+
some_contract.py (Smart Contract)
236236
```python
237237
balances = Hash(default_value=0)
238238
balances.set('stu', 1_000_000)
@@ -249,7 +249,7 @@ The same caveat applies here
249249
#### Multihashes
250250
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.
251251

252-
subaccounts.py
252+
subaccounts.py (Smart Contract)
253253
```python
254254
balances = Hash(default_value=0)
255255
balances.set('stu', 1_000_000)
@@ -301,7 +301,7 @@ d['complex'] == e['complex'] # True!
301301
#### \_\_setitem\_\_(self, key, value):
302302
Equal functionality to `set`, but allows slice notation for convenience. __This is less verbose and the preferred method of setting storage on a Hash.__
303303

304-
subaccounts.py
304+
subaccounts.py (Smart Contract)
305305
```python
306306
balances = Hash(default_value=0)
307307
balances['stu'] = 1_000_000
@@ -321,7 +321,7 @@ owner['stu']
321321
#### \_\_getitem\_\_(self, key):
322322
Equal functionality to `set`, but allows slice notation for convenience. __This is less verbose and the preferred method of setting storage on a Hash.__
323323

324-
subaccounts.py
324+
subaccounts.py (Smart Contract)
325325
```python
326326
balances = Hash(default_value=0)
327327
balances['stu'] = 1_000_000

0 commit comments

Comments
 (0)