@@ -13,8 +13,8 @@ Let's get to it then!
13
13
14
14
.. py :currentmodule :: iota
15
15
16
- Hello Node
17
- ----------
16
+ 1. Hello Node
17
+ -------------
18
18
In this example, you will learn how to:
19
19
20
20
- **Import the ** ``iota `` **package into your application. **
@@ -73,8 +73,8 @@ we could list the ``features`` of the node::
73
73
74
74
pprint(response['features'])
75
75
76
- Send Data
77
- ---------
76
+ 2. Send Data
77
+ ------------
78
78
In this example, you will learn how to:
79
79
80
80
- **Encode data to be stored on the Tangle. **
@@ -167,6 +167,66 @@ Observe how we extract the transaction hash from the response ``dict``. We take
167
167
the first element of the bundle, as it is just a sequence of transactions, and
168
168
access its ``hash `` attribute.
169
169
170
+ 3. Fetch Data
171
+ -------------
172
+ In this example, you will learn how to:
173
+
174
+ - **Fetch transaction objects from the Tangle based on a criteria. **
175
+ - **Decode messages from transactions. **
176
+
177
+ Code
178
+ ~~~~
179
+ .. literalinclude :: ../examples/tutorials/03_fetch_data.py
180
+ :linenos:
181
+
182
+ Discussion
183
+ ~~~~~~~~~~
184
+ .. literalinclude :: ../examples/tutorials/03_fetch_data.py
185
+ :lines: 1-5
186
+ :lineno-start: 1
187
+
188
+ The usual part again, but we also import ``TrytesDecodeError `` from
189
+ ``iota.codec ``. We will use this to detect if the fetched trytes contain
190
+ encoded text.
191
+
192
+ .. literalinclude :: ../examples/tutorials/03_fetch_data.py
193
+ :lines: 7-10
194
+ :lineno-start: 7
195
+
196
+ We declare an IOTA address on the Tangle to fetch data from. You can replace
197
+ this address with your own from the previous example `2. Send Data `_, or just
198
+ run it as it is.
199
+
200
+ .. literalinclude :: ../examples/tutorials/03_fetch_data.py
201
+ :lines: 12-14
202
+ :lineno-start: 12
203
+
204
+ We use :py:meth: `~Iota.find_transaction_objects ` extended API method to gather
205
+ the transactions that belong to our address. This method is also capable of
206
+ returning :py:class: `Transaction ` objects for bundle hashes, tags or approving
207
+ transactions. Note that you can supply multiple of these, the method always
208
+ returns a ``dict `` with a list of transactions.
209
+
210
+ .. note ::
211
+
212
+ Remember, that the parameters need to be supplied as lists, even if
213
+ there is only one value.
214
+
215
+ .. literalinclude :: ../examples/tutorials/03_fetch_data.py
216
+ :lines: 16-29
217
+ :lineno-start: 16
218
+
219
+ Finally, we extract the data we our looking for from the transaction objects.
220
+ A :py:class: `Transaction ` has several attributes, one of which is the
221
+ ``signature_message_fragment ``. This contains the payload message for zero-value
222
+ transactions, and the digital signature that authorizes spending for value
223
+ transactions.
224
+
225
+ Since we are interested in data now, we try to decode its content (raw trytes)
226
+ into text. We make use of ``TrytesDecodeError `` to detect if the attribute can
227
+ be interpreted as text, and ``UnicodeDecodeError `` to filter out invalid
228
+ text encoding.
229
+
170
230
.. _PyOTA Bug Tracker : https://github.com/iotaledger/iota.py/issues
171
231
.. _bytestring : https://docs.python.org/3/library/stdtypes.html#bytes
172
232
.. _tryte alphabet : https://docs.iota.org/docs/getting-started/0.1/introduction/ternary#tryte-encoding
0 commit comments