Skip to content

Commit 4ecb416

Browse files
authored
Update storage.md
1 parent 5435884 commit 4ecb416

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

docs/concepts/storage.md

+13-13
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
89+
some_contract.py
9090
```python
9191
owner = Variable()
9292
```
@@ -100,17 +100,17 @@ Driver is pulled from the Runtime (`rt`) module when the contract is being execu
100100

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

103-
some_contract
103+
some_contract.py
104104
```python
105105
owner = Variable()
106106
owner.set('stu')
107107
```
108108

109109
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.
110110

111-
Key | Value
112-
- | -
113-
some_contract.owner | stu
111+
| Key | Value |
112+
|-------------------|-------|
113+
| some_contract.owner | stu |
114114

115115
__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.
116116

@@ -126,7 +126,7 @@ owner
126126

127127
#### get(self)
128128

129-
some_contract
129+
some_contract.py
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
182+
some_contract.py
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
195+
some_contract.py
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
213+
subaccounts.py
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
235+
some_contract.py
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
252+
subaccounts.py
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
304+
subaccounts.py
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
324+
subaccounts.py
325325
```python
326326
balances = Hash(default_value=0)
327327
balances['stu'] = 1_000_000

0 commit comments

Comments
 (0)