10
10
from iota .crypto import Curl , HASH_LENGTH
11
11
from iota .json import JsonSerializable
12
12
from iota .transaction .types import BundleHash , Fragment , TransactionHash , \
13
- TransactionTrytes
13
+ TransactionTrytes , Nonce
14
14
from iota .types import Address , Hash , Tag , TryteString , TrytesCompatible , \
15
15
int_from_trits , trits_from_int
16
16
@@ -53,14 +53,18 @@ def from_tryte_string(cls, trytes, hash_=None):
53
53
signature_message_fragment = Fragment (tryte_string [0 :2187 ]),
54
54
address = Address (tryte_string [2187 :2268 ]),
55
55
value = int_from_trits (tryte_string [2268 :2295 ].as_trits ()),
56
- tag = Tag (tryte_string [2295 :2322 ]),
56
+ legacy_tag = Tag (tryte_string [2295 :2322 ]),
57
57
timestamp = int_from_trits (tryte_string [2322 :2331 ].as_trits ()),
58
58
current_index = int_from_trits (tryte_string [2331 :2340 ].as_trits ()),
59
59
last_index = int_from_trits (tryte_string [2340 :2349 ].as_trits ()),
60
60
bundle_hash = BundleHash (tryte_string [2349 :2430 ]),
61
61
trunk_transaction_hash = TransactionHash (tryte_string [2430 :2511 ]),
62
62
branch_transaction_hash = TransactionHash (tryte_string [2511 :2592 ]),
63
- nonce = Hash (tryte_string [2592 :2673 ]),
63
+ tag = Tag (tryte_string [2592 :2619 ]),
64
+ attachment_timestamp = int_from_trits (tryte_string [2619 :2628 ].as_trits ()),
65
+ attachment_timestamp_lower_bound = int_from_trits (tryte_string [2628 :2637 ].as_trits ()),
66
+ attachment_timestamp_upper_bound = int_from_trits (tryte_string [2637 :2646 ].as_trits ()),
67
+ nonce = Nonce (tryte_string [2646 :2673 ]),
64
68
)
65
69
66
70
def __init__ (
@@ -69,16 +73,20 @@ def __init__(
69
73
signature_message_fragment ,
70
74
address ,
71
75
value ,
72
- tag ,
73
76
timestamp ,
74
77
current_index ,
75
78
last_index ,
76
79
bundle_hash ,
77
80
trunk_transaction_hash ,
78
81
branch_transaction_hash ,
82
+ tag ,
83
+ attachment_timestamp ,
84
+ attachment_timestamp_lower_bound ,
85
+ attachment_timestamp_upper_bound ,
79
86
nonce ,
87
+ legacy_tag = None
80
88
):
81
- # type: (Optional[TransactionHash], Optional[Fragment], Address, int, Optional[Tag], int, Optional[int], Optional[int], Optional[BundleHash], Optional[TransactionHash], Optional[TransactionHash], Optional[Hash]) -> None
89
+ # type: (Optional[TransactionHash], Optional[Fragment], Address, int, int, Optional[int], Optional[int], Optional[BundleHash], Optional[TransactionHash], Optional[TransactionHash], Optional[Tag], Optional[int], Optional[int], Optional[int] Optional[Hash]) -> None
82
90
self .hash = hash_ # type: Optional[TransactionHash]
83
91
"""
84
92
Transaction ID, generated by taking a hash of the transaction
@@ -104,12 +112,12 @@ def __init__(
104
112
Can be negative (i.e., for spending inputs).
105
113
"""
106
114
107
- self .tag = tag # type: Optional[Tag]
115
+ self ._legacy_tag = legacy_tag # type: Optional[Tag]
108
116
"""
109
- Optional classification tag applied to this transaction.
117
+ Optional classification legacy_tag applied to this transaction.
110
118
"""
111
119
112
- self .nonce = nonce # type: Optional[Hash ]
120
+ self .nonce = nonce # type: Optional[Nonce ]
113
121
"""
114
122
Unique value used to increase security of the transaction hash.
115
123
"""
@@ -154,6 +162,17 @@ def __init__(
154
162
155
163
The branch transaction generally has no significance.
156
164
"""
165
+
166
+ self .tag = tag # type: Optional[Tag]
167
+ """
168
+ Optional classification tag applied to this transaction.
169
+ """
170
+
171
+ self .attachment_timestamp = attachment_timestamp # type: int
172
+
173
+ self .attachment_timestamp_lower_bound = attachment_timestamp_lower_bound # type: int
174
+
175
+ self .attachment_timestamp_upper_bound = attachment_timestamp_upper_bound # type: int
157
176
158
177
self .signature_message_fragment = signature_message_fragment # type: Optional[Fragment]
159
178
"""
@@ -227,6 +246,36 @@ def last_index_as_trytes(self):
227
246
"""
228
247
# Note that we are padding to 27 _trits_.
229
248
return TryteString .from_trits (trits_from_int (self .last_index , pad = 27 ))
249
+
250
+ @property
251
+ def attachment_timestamp_as_trytes (self ):
252
+ # type: () -> TryteString
253
+ """
254
+ Returns a TryteString representation of the transaction's
255
+ attachment timestamp.
256
+ """
257
+ #Note that we are padding to 27 _trits_.
258
+ return TryteString .from_trits (trits_from_int (self .attachment_timestamp , pad = 27 ))
259
+
260
+ @property
261
+ def attachment_timestamp_lower_bound_as_trytes (self ):
262
+ # type: () -> TryteString
263
+ """
264
+ Returns a TryteString representation of the transaction's
265
+ attachment timestamp lower bound.
266
+ """
267
+ #Note that we are padding to 27 _trits_.
268
+ return TryteString .from_trits (trits_from_int (self .attachment_timestamp_lower_bound , pad = 27 ))
269
+
270
+ @property
271
+ def attachment_timestamp_upper_bound_as_trytes (self ):
272
+ # type: () -> TryteString
273
+ """
274
+ Returns a TryteString representation of the transaction's
275
+ attachment timestamp upper bound.
276
+ """
277
+ #Note that we are padding to 27 _trits_.
278
+ return TryteString .from_trits (trits_from_int (self .attachment_timestamp_upper_bound , pad = 27 ))
230
279
231
280
def as_json_compatible (self ):
232
281
# type: () -> dict
@@ -237,18 +286,22 @@ def as_json_compatible(self):
237
286
- :py:class:`iota.json.JsonEncoder`.
238
287
"""
239
288
return {
240
- 'hash_' : self .hash ,
241
- 'signature_message_fragment' : self .signature_message_fragment ,
242
- 'address' : self .address ,
243
- 'value' : self .value ,
244
- 'tag' : self .tag ,
245
- 'timestamp' : self .timestamp ,
246
- 'current_index' : self .current_index ,
247
- 'last_index' : self .last_index ,
248
- 'bundle_hash' : self .bundle_hash ,
249
- 'trunk_transaction_hash' : self .trunk_transaction_hash ,
250
- 'branch_transaction_hash' : self .branch_transaction_hash ,
251
- 'nonce' : self .nonce ,
289
+ 'hash_' : self .hash ,
290
+ 'signature_message_fragment' : self .signature_message_fragment ,
291
+ 'address' : self .address ,
292
+ 'value' : self .value ,
293
+ 'legacy_tag' : self .legacy_tag ,
294
+ 'timestamp' : self .timestamp ,
295
+ 'current_index' : self .current_index ,
296
+ 'last_index' : self .last_index ,
297
+ 'bundle_hash' : self .bundle_hash ,
298
+ 'trunk_transaction_hash' : self .trunk_transaction_hash ,
299
+ 'branch_transaction_hash' : self .branch_transaction_hash ,
300
+ 'tag' : self .tag ,
301
+ 'attachment_timestamp' : self .attachment_timestamp ,
302
+ 'attachment_timestamp_lower_bound' : self .attachment_timestamp_lower_bound ,
303
+ 'attachment_timestamp_upper_bound' : self .attachment_timestamp_upper_bound ,
304
+ 'nonce' : self .nonce ,
252
305
}
253
306
254
307
def as_tryte_string (self ):
@@ -260,13 +313,17 @@ def as_tryte_string(self):
260
313
self .signature_message_fragment
261
314
+ self .address .address
262
315
+ self .value_as_trytes
263
- + self .tag
316
+ + self .legacy_tag
264
317
+ self .timestamp_as_trytes
265
318
+ self .current_index_as_trytes
266
319
+ self .last_index_as_trytes
267
320
+ self .bundle_hash
268
321
+ self .trunk_transaction_hash
269
322
+ self .branch_transaction_hash
323
+ + self .tag
324
+ + self .attachment_timestamp_as_trytes
325
+ + self .attachment_timestamp_lower_bound_as_trytes
326
+ + self .attachment_timestamp_upper_bound_as_trytes
270
327
+ self .nonce
271
328
)
272
329
@@ -279,11 +336,20 @@ def get_signature_validation_trytes(self):
279
336
return (
280
337
self .address .address
281
338
+ self .value_as_trytes
282
- + self .tag
339
+ + self .legacy_tag
283
340
+ self .timestamp_as_trytes
284
341
+ self .current_index_as_trytes
285
342
+ self .last_index_as_trytes
286
343
)
344
+
345
+ @property
346
+ def legacy_tag (self ):
347
+ # type: () -> Tag
348
+ """
349
+ Return the legacy tag of the transaction.
350
+ If no legacy tag was set, returns the tag instead.
351
+ """
352
+ return self ._legacy_tag or self .tag
287
353
288
354
289
355
class Bundle (JsonSerializable , Sequence [Transaction ]):
0 commit comments