Skip to content

Commit

Permalink
Support FirstValidTime transaction field (#424)
Browse files Browse the repository at this point in the history
* Add first valid time factory and update min version

* Include FirstValidTime in txn tests

* Add transaction field docs
  • Loading branch information
jdtzmn authored Jun 30, 2022
1 parent cc544aa commit 6e83ae6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/accessing_transaction_field.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Operator
:any:`Txn.sender() <TxnObject.sender>` :code:`TealType.bytes` 2 32 byte address
:any:`Txn.fee() <TxnObject.fee>` :code:`TealType.uint64` 2 in microAlgos
:any:`Txn.first_valid() <TxnObject.first_valid>` :code:`TealType.uint64` 2 round number
:any:`Txn.first_valid_time() <TxnObject.first_valid_time>` :code:`TealType.uint64` 7 UNIX timestamp of block before :code:`Txn.first_valid()`. Fails if negative
:any:`Txn.last_valid() <TxnObject.last_valid>` :code:`TealType.uint64` 2 round number
:any:`Txn.note() <TxnObject.note>` :code:`TealType.bytes` 2 transaction note in bytes
:any:`Txn.lease() <TxnObject.lease>` :code:`TealType.bytes` 2 transaction lease in bytes
Expand Down
9 changes: 8 additions & 1 deletion pyteal/ast/txn.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TxnField(Enum):
sender = (0, "Sender", TealType.bytes, False, 2)
fee = (1, "Fee", TealType.uint64, False, 2)
first_valid = (2, "FirstValid", TealType.uint64, False, 2)
first_valid_time = (3, "FirstValidTime", TealType.uint64, False, 2)
first_valid_time = (3, "FirstValidTime", TealType.uint64, False, 7)
last_valid = (4, "LastValid", TealType.uint64, False, 2)
note = (5, "Note", TealType.bytes, False, 2)
lease = (6, "Lease", TealType.bytes, False, 2)
Expand Down Expand Up @@ -319,6 +319,13 @@ def first_valid(self) -> TxnExpr:
"""
return self.makeTxnExpr(TxnField.first_valid)

def first_valid_time(self) -> TxnExpr:
"""Get the UNIX timestamp of block before txn.FirstValid. Fails if negative.
For more information, see https://developer.algorand.org/docs/reference/transactions/#firstvalidtime
"""
return self.makeTxnExpr(TxnField.first_valid_time)

def last_valid(self) -> TxnExpr:
"""Get the last valid round number.
Expand Down
1 change: 1 addition & 0 deletions pyteal/ast/txn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
pt.TxnField.sender: lambda txn: txn.sender(),
pt.TxnField.fee: lambda txn: txn.fee(),
pt.TxnField.first_valid: lambda txn: txn.first_valid(),
pt.TxnField.first_valid_time: lambda txn: txn.first_valid_time(),
pt.TxnField.last_valid: lambda txn: txn.last_valid(),
pt.TxnField.note: lambda txn: txn.note(),
pt.TxnField.lease: lambda txn: txn.lease(),
Expand Down

0 comments on commit 6e83ae6

Please sign in to comment.