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

ABI Router implementation and test #170

Merged
merged 223 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
223 commits
Select commit Hold shift + click to select a range
c73a2d9
init commit
ahangsu Jan 25, 2022
897ff6a
minor
ahangsu Jan 25, 2022
90fcfef
minor
ahangsu Jan 25, 2022
01c114e
rm decorator
ahangsu Jan 26, 2022
46daf5c
update ABI router design, seems we are still working on previous design
ahangsu Jan 26, 2022
8ea2bcb
minor
ahangsu Jan 26, 2022
0208800
update condition parser here
ahangsu Jan 27, 2022
9adec41
skeleton for handler wrapping, need to tweak on subroutine to expose …
ahangsu Jan 27, 2022
3953180
module
ahangsu Jan 27, 2022
ed874fa
Merge branch 'master' into abi-router
ahangsu Jan 27, 2022
2bf75c3
use subroutine fn wrapper
ahangsu Jan 27, 2022
5115383
update dummy method return class
ahangsu Jan 28, 2022
2d1c6e3
unify ast construct way
ahangsu Jan 28, 2022
0f8be9e
minor
ahangsu Jan 28, 2022
92d3242
update notes for tasks and todos
ahangsu Feb 1, 2022
bb204bf
update handler wrapping for bare app call
ahangsu Feb 1, 2022
ea66a6f
minor
ahangsu Feb 1, 2022
09bd24c
update redirecting args to method registered
ahangsu Feb 1, 2022
dfbec9b
minor
ahangsu Feb 1, 2022
88a565f
minor
ahangsu Feb 1, 2022
8c54acc
update router src
ahangsu Feb 1, 2022
1d6fa03
update program node
ahangsu Feb 1, 2022
7d683c3
add questions in build prog
ahangsu Feb 1, 2022
28c3a46
update executing method branch
ahangsu Feb 1, 2022
0633c88
minor
ahangsu Feb 1, 2022
e5cbdc7
minor
ahangsu Feb 2, 2022
e8d54d8
minor
ahangsu Feb 2, 2022
52cd87c
hide other methods, set MethodAppArgNumLimit, keyword args on exposed…
ahangsu Feb 3, 2022
fb544fe
minor
ahangsu Feb 3, 2022
096d693
update notes
ahangsu Feb 3, 2022
26c3ea0
update
ahangsu Feb 8, 2022
541b707
add a default for no registered ast gen
ahangsu Feb 9, 2022
ad50f67
Merge branch 'master' into abi-router
ahangsu Feb 10, 2022
f959cba
update ast construction to conds
ahangsu Mar 1, 2022
2794fa4
need some documentations
ahangsu Mar 1, 2022
2f6408a
Merge branch 'feature/abi' into abi-router
ahangsu Mar 2, 2022
47e684c
move abi-router in abi dir
ahangsu Mar 2, 2022
0d2dfcd
minor
ahangsu Mar 3, 2022
50a15e2
Merge branch 'feature/abi' into abi-router
ahangsu Mar 3, 2022
af0edbb
Merge branch 'master' into feature/abi
ahangsu Mar 3, 2022
0f06507
Merge branch 'feature/abi' into abi-router
ahangsu Mar 3, 2022
dd9abff
wtf
ahangsu Mar 30, 2022
d33e26c
update
ahangsu Mar 30, 2022
cd7632e
update to f-str
ahangsu Mar 31, 2022
a21ce2c
define void type
ahangsu Mar 31, 2022
480ece7
update instantiated computed type returnedType for ABI return in subr…
ahangsu Mar 31, 2022
ff0d275
minor
ahangsu Mar 31, 2022
6929922
update stuffs to help infer type annotation of return ABI
ahangsu Mar 31, 2022
c24e0bd
minor
ahangsu Mar 31, 2022
9e3989b
minor
ahangsu Mar 31, 2022
a1e138e
minor
ahangsu Mar 31, 2022
0d617ff
minor
ahangsu Mar 31, 2022
081bfb6
minor
ahangsu Mar 31, 2022
e8e481e
try my best to save stuffs
ahangsu Mar 31, 2022
bd29b95
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
ahangsu Mar 31, 2022
616968d
simplify decorator to single function
ahangsu Mar 31, 2022
12e3ee4
tear it down
ahangsu Mar 31, 2022
f6af8fa
minor
ahangsu Mar 31, 2022
fee70a6
sheeeesh emacs
ahangsu Mar 31, 2022
92b4db4
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 1, 2022
ce425d3
Merge branch 'feature/abi' into abi-router
ahangsu Apr 7, 2022
aa938f9
update with latest abi impl
ahangsu Apr 7, 2022
80c4d50
minors
ahangsu Apr 7, 2022
79492e7
minor
ahangsu Apr 7, 2022
41ba233
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 12, 2022
f0101d0
updates
ahangsu Apr 12, 2022
2c724be
Merge branch 'feature/abi' into abi-router
ahangsu Apr 14, 2022
1b5cd6a
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 14, 2022
a2d9ea2
minor, renaming something
ahangsu Apr 14, 2022
91c87b7
new design, start over
ahangsu Apr 14, 2022
3fb7374
updates
ahangsu Apr 15, 2022
2e27f82
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 21, 2022
cf3106d
abi fn wrapper for now
ahangsu Apr 23, 2022
6969622
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 23, 2022
dec018f
minor
ahangsu Apr 23, 2022
54fe3bc
minor update on subroutine def
ahangsu Apr 24, 2022
4e5e1e5
minor fixes
ahangsu Apr 24, 2022
287ba71
minor fixes
ahangsu Apr 24, 2022
fa33095
changes
ahangsu Apr 25, 2022
43212b7
more constraint on void ret
ahangsu Apr 25, 2022
31cf527
update comment examples
ahangsu Apr 25, 2022
87c34d8
import from abi
ahangsu Apr 25, 2022
b0baea5
update some error msg and comments
ahangsu Apr 25, 2022
1c48d0c
testcases partial
ahangsu Apr 26, 2022
319b953
upgrade testscripts
ahangsu Apr 27, 2022
67831ff
merging feature/abi to abi-router (#305)
barnjamin Apr 28, 2022
a18c47d
Export Router (#306)
barnjamin Apr 28, 2022
8ff5cc8
Merge branch 'feature/abi' into abi-router
barnjamin Apr 28, 2022
5d78129
fix spacing issue
barnjamin Apr 28, 2022
96f7ede
Bundle optional refactorings to subroutine.py (#308)
michaeldiamant Apr 29, 2022
79d787b
storing local changes
ahangsu May 2, 2022
ae7b552
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
ahangsu May 2, 2022
9422ea3
pr review partly
ahangsu May 2, 2022
02f442a
pr review partly
ahangsu May 2, 2022
c9ed2b2
update test script
ahangsu May 2, 2022
21447bb
Abi subroutine feature merge (#315)
tzaffi May 3, 2022
d43905e
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 3, 2022
d0737ef
resolve conflicts
May 3, 2022
0e776a4
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
May 3, 2022
73b595f
lint
May 3, 2022
6557649
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 3, 2022
7ace3fc
minor reconstruct
ahangsu May 3, 2022
1479959
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
May 3, 2022
386d57b
missing imports
May 3, 2022
939dea4
missing requirements from bad merge
May 3, 2022
87eafdd
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 4, 2022
4512c96
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 4, 2022
69d389b
cooperate with typespec n var def change
ahangsu May 4, 2022
5378983
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 4, 2022
f42339d
update comments
ahangsu May 4, 2022
59226b2
some comments resolving?
ahangsu May 5, 2022
44003d6
trim
ahangsu May 5, 2022
9f13409
update some comments
ahangsu May 5, 2022
5941108
bring testcase back
ahangsu May 5, 2022
c161e22
restriction on output kwarg name
ahangsu May 5, 2022
d2caed3
stop ci! i am reformatting
ahangsu May 5, 2022
cdd1e73
Merge branch 'feature/abi' into abi-router
ahangsu May 6, 2022
a262e3d
squash merge abi subroutine atm, merge again after abi subroutine int…
ahangsu May 6, 2022
2690233
conform to pep8, reconstructing
ahangsu May 6, 2022
c0c37f8
update json generator
ahangsu May 6, 2022
bba1709
simplify name constrain
ahangsu May 9, 2022
4c0858f
resolving comments
ahangsu May 9, 2022
dc2e060
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 9, 2022
95caac5
Use deferred subroutine expression for ABI returns (#328)
jasonpaulos May 9, 2022
d21e281
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
ahangsu May 9, 2022
4706832
Merge branch 'abi-subroutine' into abi-router
ahangsu May 9, 2022
3416b75
Merge branch 'feature/abi' into abi-router
ahangsu May 11, 2022
0169078
updating wrap handler
ahangsu May 12, 2022
a04a897
change how to de-tuple args
ahangsu May 12, 2022
bc6b8dc
update checkbox
ahangsu May 12, 2022
5516d89
minor
ahangsu May 12, 2022
b8e8d1f
bug fixes
ahangsu May 12, 2022
16199ec
Method sig for router (#340)
barnjamin May 13, 2022
d8b7b3d
minor, renaming
ahangsu May 13, 2022
d911e42
minor
ahangsu May 13, 2022
6eded9f
Merge branch 'feature/abi' into abi-router
ahangsu May 13, 2022
179ac5d
simplify
ahangsu May 13, 2022
1e7d779
compiler test adding...
ahangsu May 13, 2022
377cb22
documentation
ahangsu May 16, 2022
407f3d1
start testcases
ahangsu May 16, 2022
9fbdfec
update router testcase
ahangsu May 16, 2022
b348c65
docstring tweak
ahangsu May 16, 2022
d95ae32
update testcases
ahangsu May 16, 2022
e8a43a7
update testcases
ahangsu May 16, 2022
19460c0
formatting
ahangsu May 16, 2022
fa28de4
branch cond testing
ahangsu May 17, 2022
9961c1a
router contract test
ahangsu May 17, 2022
95f90c7
subroutine branch wrapper bare call case tested
ahangsu May 17, 2022
8923ef5
more testcases to barecall
ahangsu May 17, 2022
3576223
minor, need to work on method call wrapper
ahangsu May 17, 2022
b8ea59a
half done on method call wrapper
ahangsu May 17, 2022
a940f5e
update on abi method wrapper with return
ahangsu May 17, 2022
648d075
detuple testcase
ahangsu May 17, 2022
7a1c456
compiler test need to see csp
ahangsu May 17, 2022
818e839
rm redundant type annotation
ahangsu May 17, 2022
5fc8610
more error msg
ahangsu May 17, 2022
8f73760
renaming
ahangsu May 18, 2022
c598217
renaming is_registrable -> is_abi_routable
ahangsu May 18, 2022
a1d2c21
reording imports, eliminate anti patterns
ahangsu May 18, 2022
a0a7648
remove anti-pattern
ahangsu May 18, 2022
4d2e57e
section it out
ahangsu May 18, 2022
e162275
non_empty_power_set -> power_set
ahangsu May 18, 2022
2dafe23
add conflict detection to protect AST from overshadowing
ahangsu May 18, 2022
11f4cff
error message
ahangsu May 18, 2022
241e7ee
shrinked commits on pr review
ahangsu May 19, 2022
9b1205a
add compile_program
ahangsu May 19, 2022
fca1fb3
Merge branch 'feature/abi' into abi-router
ahangsu May 19, 2022
912b16b
fixup subroutine testcase
ahangsu May 19, 2022
d28fdc6
remove method signature specifying, directly infer from ABIReturnSubr…
ahangsu May 19, 2022
e8b4765
remove method sign field, directly infer from ABIReturnSubroutine
ahangsu May 19, 2022
e350220
relaxation of bare app call arg num restriction
ahangsu May 19, 2022
0b63f78
add barecall class, api change following
ahangsu May 19, 2022
f198857
rename barecall to OnCompleteAction
ahangsu May 20, 2022
d5f75d3
remove outdated comments
ahangsu May 20, 2022
bf58a10
Merge branch 'feature/abi' into abi-router
ahangsu May 20, 2022
0dd7208
start changing router api
ahangsu May 20, 2022
89f137b
eliminate contradiction for oc and creation
ahangsu May 23, 2022
ecd2767
remove restriction on cond
ahangsu May 23, 2022
4e8efe2
new interface: add bare-calls on init, register method-call more fine…
ahangsu May 24, 2022
89ab167
documentation for new interface from last discussion
ahangsu May 24, 2022
0ecfd62
Merge branch 'feature/abi' into abi-router
ahangsu May 24, 2022
59c86d1
Refactor #170 to reduce visibility and mutation (#362)
michaeldiamant May 25, 2022
2d203ff
hide wrap handler method
ahangsu May 25, 2022
a99b964
Merge branch 'abi-router' of github.com:algorand/pyteal into abi-router
ahangsu May 25, 2022
2557efc
adding comment changes
ahangsu May 25, 2022
a65d66e
pr review partly
ahangsu May 25, 2022
f38caed
partition into two methods
ahangsu May 25, 2022
0f10534
hide all these methods
ahangsu May 25, 2022
2323920
arc4 compliant CallConfigs classmethod
ahangsu May 25, 2022
9cea65d
arc4 compliant CallConfigs documentation
ahangsu May 25, 2022
065a797
disclaimer comments
ahangsu May 25, 2022
f1bb613
Merge branch 'feature/abi' into abi-router
ahangsu May 25, 2022
e0dc4bd
update new abi return hash prefix
ahangsu May 26, 2022
34ee8dc
review comments partly
ahangsu May 26, 2022
94d618b
OnCompleteActions -> BareCallActions
ahangsu May 26, 2022
f7185b9
disclaimer change, rename CallConfigs -> MethodConfig
ahangsu May 26, 2022
2958bc0
disclaimer move to docstring
ahangsu May 26, 2022
6f386dd
better naming for naming prefix
ahangsu May 26, 2022
aa69b0f
new ast builder
ahangsu May 26, 2022
e7a49f1
review comments
ahangsu May 27, 2022
22cf520
An attempt to add decorator syntax to abi-router (#370)
ahangsu May 27, 2022
f66b7e4
minor fix
ahangsu May 27, 2022
c42da1e
per pr comment on on-complete-action
ahangsu May 27, 2022
c0af62e
eliminate potential issue
ahangsu May 27, 2022
78ca6fb
update call config testcase
ahangsu May 27, 2022
4aa69c6
add testcase for on complete action
ahangsu May 27, 2022
7df0996
per comments
ahangsu May 27, 2022
1753a94
Add a check in `method_signature` to disallow reference return types …
barnjamin May 31, 2022
5b9c547
add new compiler tests for router
ahangsu May 31, 2022
3a76144
fix one test for wrapping bare calls
ahangsu May 31, 2022
eee9545
comments fixing
ahangsu May 31, 2022
b2c025e
simplified oc-action post_init check
ahangsu May 31, 2022
c6019b0
naming variables
ahangsu May 31, 2022
5e41d13
comments
ahangsu May 31, 2022
197a9d3
comments
ahangsu May 31, 2022
2128874
Merge branch 'feature/abi' into abi-router
ahangsu May 31, 2022
dbffe61
testcase for method config update
ahangsu Jun 1, 2022
a3a8601
add router method only in clearstate prog
ahangsu Jun 1, 2022
f6ad9ad
closeout -> clearstate
ahangsu Jun 1, 2022
4e95c20
removing is_arc4_compliant
ahangsu Jun 1, 2022
00376a6
update add method handler and method interface
ahangsu Jun 1, 2022
c56d837
remove arc4_compliant
ahangsu Jun 1, 2022
c8ef39a
Add manual test for 15+ args in abi router (#375)
jasonpaulos Jun 1, 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
3 changes: 2 additions & 1 deletion pyteal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from .types import TealType
from .errors import TealInternalError, TealTypeError, TealInputError, TealCompileError
from .config import MAX_GROUP_SIZE, NUM_SLOTS
from .config import MAX_GROUP_SIZE, NUM_SLOTS, RETURN_EVENT_SELECTOR

# begin __all__
__all__ = (
Expand All @@ -30,6 +30,7 @@
"TealCompileError",
"MAX_GROUP_SIZE",
"NUM_SLOTS",
"RETURN_EVENT_SELECTOR",
]
)
# end __all__
4 changes: 3 additions & 1 deletion pyteal/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from .compiler import (
)
from .types import TealType
from .errors import TealInternalError, TealTypeError, TealInputError, TealCompileError
from .config import MAX_GROUP_SIZE, NUM_SLOTS
from .config import MAX_GROUP_SIZE, NUM_SLOTS, RETURN_EVENT_SELECTOR

__all__ = [
"Expr",
Expand Down Expand Up @@ -110,6 +110,7 @@ __all__ = [
"Return",
"Approve",
"Reject",
"ABIRouter",
"Subroutine",
"SubroutineDefinition",
"SubroutineDeclaration",
Expand Down Expand Up @@ -166,4 +167,5 @@ __all__ = [
"TealCompileError",
"MAX_GROUP_SIZE",
"NUM_SLOTS",
"RETURN_EVENT_SELECTOR",
]
5 changes: 3 additions & 2 deletions pyteal/ast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from .addr import Addr
from .bytes import Bytes
from .int import Int, EnumInt
from .methodsig import MethodSignature

# properties
from .arg import Arg
Expand Down Expand Up @@ -116,12 +115,13 @@
from .for_ import For
from .break_ import Break
from .continue_ import Continue

from .abirouter import ABIRouter

# misc
from .scratch import ScratchSlot, ScratchLoad, ScratchStore, ScratchStackStore
from .scratchvar import ScratchVar
from .maybe import MaybeValue
from .methodsig import MethodSignature

__all__ = [
"Expr",
Expand Down Expand Up @@ -217,6 +217,7 @@
"Return",
"Approve",
"Reject",
"ABIRouter",
"Subroutine",
"SubroutineDefinition",
"SubroutineDeclaration",
Expand Down
133 changes: 133 additions & 0 deletions pyteal/ast/abirouter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
from typing import Callable, List, Tuple, Union, cast

from pyteal.errors import TealInputError
from pyteal.config import RETURN_EVENT_SELECTOR

from .app import OnComplete
from .bytes import Bytes
from .expr import Expr
from .int import EnumInt, Int
from .if_ import If
from .methodsig import MethodSignature
from .naryexpr import And, Or
from .return_ import Approve, Reject
from .seq import Seq
from .subroutine import Subroutine, SubroutineDefinition
from .txn import Txn

"""
Implementing a Method
çAn ARC-4 app implementing a method:
ahangsu marked this conversation as resolved.
Show resolved Hide resolved

MUST check if txn NumAppArgs equals 0. If true, then this is a bare application call. If the Contract supports bare application calls for the current transaction parameters (it SHOULD check the OnCompletion action and whether the transaction is creating the application), it MUST handle the call appropriately and either approve or reject the transaction. The following steps MUST be ignored in this case. Otherwise, if the Contract does not support this bare application call, the Contract MUST reject the transaction.

MUST examine txna ApplicationArgs 0 to identify the selector of the method being invoked. If the contract does not implement a method with that selector, the Contract MUST reject the transaction.

MUST execute the actions required to implement the method being invoked. In general, this works by branching to the body of the method indicated by the selector.

The code for that method MAY extract the arguments it needs, if any, from the application call arguments as described in the Encoding section. If the method has more than 15 arguments and the contract needs to extract an argument beyond the 14th, it MUST decode txna ApplicationArgs 15 as a tuple to access the arguments contained in it.

If the method is non-void, the application MUST encode the return value as described in the Encoding section and then log it with the prefix 151f7c75. Other values MAY be logged before the return value, but other values MUST NOT be logged after the return value.
"""


"""
onBareAppCall can be used to register a bare app call (defined in the ABI as a call with no arguments or return value). The allowed on completion actions must be specified, as well as whether the bare call can be invoked during creation or not.

onMethodCall can be used to register a method call. By default OnComplete.NoOp will be the only allowed on completion action, but others may be specified. Additionally, you can pass in a value for creation if this method call should be invoked during app creation or not.

Ideally the router would also unpack the arguments and pass them to the handler function, as well as take any return value from the handler function and prefix and log it appropriately. Though this might require some more thought to implement properly.

buildPrograms would construct ASTs for both the approval and clear programs based on the inputs to the router. If any routes can be accessed with OnComplete.ClearState, these routes will be added to the clear state program.
"""


class ABIRouter:
def __init__(self) -> None:
self.approvalIfThen: List[Tuple[Expr, Expr]] = []
self.clearStateIfThen: List[Tuple[Expr, Expr]] = []

@staticmethod
def approvalCondition(
methodName: Union[str, None], onCompletes: List[EnumInt], creation: bool
) -> Union[Expr, None]:
condList: List[Expr] = [] if not creation else [Txn.application_id() == Int(0)]
if methodName != None:
condList.append(
Txn.application_args[0] == MethodSignature(cast(str, methodName))
)
ocCondList: List[Expr] = []
for oc in onCompletes:
if oc != OnComplete.ClearState:
ocCondList.append(Txn.on_completion() == oc)
if len(ocCondList) == 0:
return None
condList.append(Or(*ocCondList))
return And(*condList)

@staticmethod
def clearStateCondition(
methodName: Union[str, None], onCompletes: List[EnumInt]
) -> Union[Expr, None]:
if not any(map(lambda x: x == OnComplete.ClearState, onCompletes)):
return None
return (
Txn.application_args[0] == MethodSignature(cast(str, methodName))
if methodName != None
else Txn.application_args.length() == Int(0)
)

def onBareAppCall(
self,
bareAppCall: Union[Callable[..., Expr], Expr],
onCompletes: Union[EnumInt, List[EnumInt]],
creation: bool = False,
) -> None:
ocList: List[EnumInt] = (
cast(List[EnumInt], onCompletes)
if isinstance(onCompletes, list)
else [cast(EnumInt, onCompletes)]
)
approvalCond = ABIRouter.approvalCondition(
methodName=None, onCompletes=ocList, creation=creation
)
clearStateCond = ABIRouter.clearStateCondition(
methodName=None, onCompletes=ocList
)
# execBareAppCall: Expr = bareAppCall() if isinstance(bareAppCall, Subroutine) else cast(Expr, bareAppCall)
# TODO update then branch (either activate subroutine or run seq of expr), then approve
thenBranch = Seq([Approve()])
# self.approvalIfThen.append((triggerCond, thenBranch))

def onMethodCall(
self,
methodSig: str,
methodAppCall: Callable[..., Expr],
onComplete: EnumInt = OnComplete.NoOp,
creation: bool = False,
) -> None:
ocList: List[EnumInt] = [cast(EnumInt, onComplete)]
approvalCond = ABIRouter.approvalCondition(
methodName=methodSig, onCompletes=ocList, creation=creation
)
clearStateCond = ABIRouter.clearStateCondition(
methodName=methodSig, onCompletes=ocList
)
# TODO unpack the arguments and pass them to handler function
# TODO take return value from handler and prefix + log: Log(Concat(return_event_selector, ...))
# TODO update then branch (either activate subroutine or run seq of expr), then approve
thenBranch = Seq([Approve()])
# self.approvalIfThen.append((triggerCond, thenBranch))

def buildProgram(self) -> Expr:
approvalProgram: If = If(self.approvalIfThen[0][0]).Then(
self.approvalIfThen[0][1]
)
for i in range(1, len(self.approvalIfThen)):
approvalProgram.ElseIf(self.approvalIfThen[i][0]).Then(
self.approvalIfThen[i][1]
)
approvalProgram.Else(Reject())

# TODO clear program
return approvalProgram
1 change: 1 addition & 0 deletions pyteal/ast/abirouter_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
5 changes: 1 addition & 4 deletions pyteal/ast/return_.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def __teal__(self, options: "CompileOptions"):
)
op = Op.return_

args = []
if self.value is not None:
args.append(self.value)

args = [] if self.value is None else [self.value]
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
return TealBlock.FromOp(options, TealOp(self, op), *args)

def __str__(self):
Expand Down
6 changes: 6 additions & 0 deletions pyteal/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from .ast.bytes import Bytes


# Maximum size of an atomic transaction group.
MAX_GROUP_SIZE = 16

# Number of scratch space slots available.
NUM_SLOTS = 256

# Bytes to prepend in log for ABI method return
RETURN_EVENT_SELECTOR = Bytes("base16", "151f7c75")
2 changes: 1 addition & 1 deletion pyteal/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, TYPE_CHECKING
from typing import Optional, TYPE_CHECKING

if TYPE_CHECKING:
from .ast import Expr
Expand Down