Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opcode support for itxnas and gitxnas #193

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
61ef1bf
Merge branch 'master' into more-teal6-ops
michaeldiamant Feb 11, 2022
cdd2f41
Add opcode support for itxnas and gitxnas
michaeldiamant Feb 12, 2022
515f3fd
Merge branch 'more-teal6-ops' of github.com:algorand/pyteal into more…
michaeldiamant Feb 14, 2022
cee11f9
Merge remote-tracking branch 'algo/more-teal6-ops' into more-teal6-op…
michaeldiamant Feb 14, 2022
dc5289f
Update stale reference to inner transaction limit
michaeldiamant Feb 14, 2022
1a78b6b
Fix allowed types for GitxnaExpr txnIndex
michaeldiamant Feb 14, 2022
1e94439
Remove obsolete logic for handling GitxnaExpr.teal construction
michaeldiamant Feb 14, 2022
57725e0
Remove unnecessary cast and fix gitxna runtime type checking
michaeldiamant Feb 14, 2022
5ee2179
Move type validation to constructors for gtxn and gitxn variants
michaeldiamant Feb 15, 2022
2344d12
Add missed tests from prior commit
michaeldiamant Feb 15, 2022
acd8f35
Fix duplicate test case
michaeldiamant Feb 16, 2022
4409cd1
Move index validation from subclasses to TxnaExpr
michaeldiamant Feb 16, 2022
3fe7f40
Inline validation functions per PR feedback
michaeldiamant Feb 16, 2022
5b87d47
Remove unused imports
michaeldiamant Feb 16, 2022
922ad26
Refactor to isinstance tupled check
michaeldiamant Feb 16, 2022
6d9cb3c
Remove TEAL v1 min version test per PR feedback
michaeldiamant Feb 16, 2022
4b3440a
Fix constructor type checking for GtxnExpr
michaeldiamant Feb 16, 2022
6201c46
Refactor to remove duplicate type check function
michaeldiamant Feb 16, 2022
fdb4833
Merge pull request #1 from michaeldiamant/more-teal6-ops_gitxnas_itxn…
michaeldiamant Feb 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions pyteal/ast/gitxn.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import TYPE_CHECKING, cast
from typing import TYPE_CHECKING, cast, Union

from pyteal.config import MAX_GROUP_SIZE

from ..errors import TealInputError, verifyFieldVersion, verifyTealVersion
from ..ir import TealOp, Op, TealBlock
from .expr import Expr
from .txn import TxnExpr, TxnField, TxnObject, TxnaExpr

if TYPE_CHECKING:
Expand Down Expand Up @@ -46,8 +47,8 @@ def __teal__(self, options: "CompileOptions"):
class GitxnaExpr(TxnaExpr):
"""An expression that accesses an inner transaction array field from an inner transaction in the last inner group."""

def __init__(self, txnIndex: int, field: TxnField, index: int) -> None:
super().__init__(Op.gitxna, None, "Gitxna", field, index)
def __init__(self, txnIndex: int, field: TxnField, index: Union[int, Expr]) -> None:
super().__init__(Op.gitxna, Op.gitxnas, "Gitxna", field, index)
self.txnIndex = txnIndex

def __str__(self):
Expand All @@ -57,18 +58,23 @@ def __str__(self):

def __teal__(self, options: "CompileOptions"):
verifyFieldVersion(self.field.arg_name, self.field.min_version, options.version)
if type(self.txnIndex) is not int or type(self.index) is not int:
raise TealInputError(
"Invalid gitxna syntax with immediate transaction index {}, transaction field {}, array index {}".format(
self.txnIndex, self.field, self.index
)
)

if type(self.index) is int:
opToUse = Op.gitxna
else:
opToUse = Op.gitxnas

verifyTealVersion(
Op.gitxna.min_version, options.version, "TEAL version too low to use gitxna"
opToUse.min_version,
options.version,
"TEAL version too low to use op {}".format(opToUse),
)
op = TealOp(self, Op.gitxna, self.txnIndex, self.field.arg_name, self.index)
return TealBlock.FromOp(options, op)

if type(self.index) is int:
op = TealOp(self, opToUse, self.txnIndex, self.field.arg_name, self.index)
return TealBlock.FromOp(options, op)
op = TealOp(self, opToUse, self.txnIndex, self.field.arg_name)
return TealBlock.FromOp(options, op, cast(Expr, self.index))


GitxnaExpr.__module__ = "pyteal"
Expand All @@ -85,7 +91,7 @@ def __getitem__(self, txnIndex: int) -> TxnObject:

if txnIndex < 0 or txnIndex >= MAX_GROUP_SIZE:
raise TealInputError(
"Invalid Gtxn index {}, shoud be in [0, {})".format(
"Invalid Gtxn index {}, should be in [0, {})".format(
txnIndex, MAX_GROUP_SIZE
)
)
Expand Down
5 changes: 3 additions & 2 deletions pyteal/ast/itxn.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def Submit(cls) -> Expr:
:any:`InnerTxnBuilder.Begin` and :any:`InnerTxnBuilder.SetField` must be called before
submitting an inner transaction.

This will fail fail if 16 inner transactions have already been executed, or if the
This will fail if 256 inner transactions have already been executed, or if the
inner transaction itself fails. Upon failure, the current program will immediately exit and
fail as well.

Expand Down Expand Up @@ -204,7 +204,8 @@ def SetFields(cls, fields: Dict[TxnField, Union[Expr, List[Expr]]]) -> Expr:
InnerTxnBuilder.__module__ = "pyteal"

InnerTxn: TxnObject = TxnObject(
TxnExprBuilder(Op.itxn, "InnerTxn"), TxnaExprBuilder(Op.itxna, None, "InnerTxna")
TxnExprBuilder(Op.itxn, "InnerTxn"),
TxnaExprBuilder(Op.itxna, Op.itxnas, "InnerTxna"),
)

InnerTxn.__module__ = "pyteal"
4 changes: 2 additions & 2 deletions pyteal/ast/txn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def test_txn_fields():
[],
[TealOp(dynamicGtxnArg, Op.int, 0)],
),
(InnerTxn, Op.itxn, Op.itxna, None, [], []),
(InnerTxn, Op.itxn, Op.itxna, Op.itxnas, [], []),
*[
(Gitxn[i], Op.gitxn, Op.gitxna, None, [i], [])
(Gitxn[i], Op.gitxn, Op.gitxna, Op.gitxnas, [i], [])
for i in range(MAX_GROUP_SIZE)
],
]
Expand Down