1010from iota .crypto import Curl , HASH_LENGTH
1111from iota .json import JsonSerializable
1212from iota .transaction .types import BundleHash , Fragment , TransactionHash , \
13- TransactionTrytes
13+ TransactionTrytes , Nonce
1414from iota .types import Address , Hash , Tag , TryteString , TrytesCompatible , \
1515 int_from_trits , trits_from_int
1616
@@ -53,14 +53,18 @@ def from_tryte_string(cls, trytes, hash_=None):
5353 signature_message_fragment = Fragment (tryte_string [0 :2187 ]),
5454 address = Address (tryte_string [2187 :2268 ]),
5555 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 ]),
5757 timestamp = int_from_trits (tryte_string [2322 :2331 ].as_trits ()),
5858 current_index = int_from_trits (tryte_string [2331 :2340 ].as_trits ()),
5959 last_index = int_from_trits (tryte_string [2340 :2349 ].as_trits ()),
6060 bundle_hash = BundleHash (tryte_string [2349 :2430 ]),
6161 trunk_transaction_hash = TransactionHash (tryte_string [2430 :2511 ]),
6262 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 ]),
6468 )
6569
6670 def __init__ (
@@ -69,16 +73,20 @@ def __init__(
6973 signature_message_fragment ,
7074 address ,
7175 value ,
72- tag ,
7376 timestamp ,
7477 current_index ,
7578 last_index ,
7679 bundle_hash ,
7780 trunk_transaction_hash ,
7881 branch_transaction_hash ,
82+ tag ,
83+ attachment_timestamp ,
84+ attachment_timestamp_lower_bound ,
85+ attachment_timestamp_upper_bound ,
7986 nonce ,
87+ legacy_tag = None
8088 ):
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
8290 self .hash = hash_ # type: Optional[TransactionHash]
8391 """
8492 Transaction ID, generated by taking a hash of the transaction
@@ -104,12 +112,12 @@ def __init__(
104112 Can be negative (i.e., for spending inputs).
105113 """
106114
107- self .tag = tag # type: Optional[Tag]
115+ self ._legacy_tag = legacy_tag # type: Optional[Tag]
108116 """
109- Optional classification tag applied to this transaction.
117+ Optional classification legacy_tag applied to this transaction.
110118 """
111119
112- self .nonce = nonce # type: Optional[Hash ]
120+ self .nonce = nonce # type: Optional[Nonce ]
113121 """
114122 Unique value used to increase security of the transaction hash.
115123 """
@@ -154,6 +162,17 @@ def __init__(
154162
155163 The branch transaction generally has no significance.
156164 """
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
157176
158177 self .signature_message_fragment = signature_message_fragment # type: Optional[Fragment]
159178 """
@@ -227,6 +246,36 @@ def last_index_as_trytes(self):
227246 """
228247 # Note that we are padding to 27 _trits_.
229248 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 ))
230279
231280 def as_json_compatible (self ):
232281 # type: () -> dict
@@ -237,18 +286,22 @@ def as_json_compatible(self):
237286 - :py:class:`iota.json.JsonEncoder`.
238287 """
239288 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 ,
252305 }
253306
254307 def as_tryte_string (self ):
@@ -260,13 +313,17 @@ def as_tryte_string(self):
260313 self .signature_message_fragment
261314 + self .address .address
262315 + self .value_as_trytes
263- + self .tag
316+ + self .legacy_tag
264317 + self .timestamp_as_trytes
265318 + self .current_index_as_trytes
266319 + self .last_index_as_trytes
267320 + self .bundle_hash
268321 + self .trunk_transaction_hash
269322 + 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
270327 + self .nonce
271328 )
272329
@@ -279,11 +336,20 @@ def get_signature_validation_trytes(self):
279336 return (
280337 self .address .address
281338 + self .value_as_trytes
282- + self .tag
339+ + self .legacy_tag
283340 + self .timestamp_as_trytes
284341 + self .current_index_as_trytes
285342 + self .last_index_as_trytes
286343 )
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
287353
288354
289355class Bundle (JsonSerializable , Sequence [Transaction ]):
0 commit comments