Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Vara Prasad Bandaru committed Feb 21, 2023
1 parent 03bf7f7 commit dec93b8
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 29 deletions.
12 changes: 11 additions & 1 deletion examples/printers/call-graph.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from pyteal import *
# pylint: disable=undefined-variable
# type: ignore[name-defined]
from pyteal import * # pylint: disable=wildcard-import, unused-wildcard-import


@Subroutine(TealType.none)
def my_subroutine():
return Approve()


@Subroutine(TealType.none)
def recursive_subroutine(n: Expr) -> Expr:
return If(
Expand All @@ -12,27 +16,33 @@ def recursive_subroutine(n: Expr) -> Expr:
recursive_subroutine(n + Int(1)),
)


@Subroutine(TealType.none)
def main_subroutine() -> Expr:
return Seq([my_subroutine(), recursive_subroutine(Int(0))])


router = Router(
name="CallGraphExample",
bare_calls=BareCallActions(),
)


@router.method(no_op=CallConfig.CALL)
def method_a() -> Expr:
return Seq([my_subroutine()])


@router.method(no_op=CallConfig.CALL)
def method_b() -> Expr:
return Seq([main_subroutine()])


@router.method(no_op=CallConfig.CALL)
def method_c() -> Expr:
return Approve()


pragma(compiler_version="0.22.0")
application_approval_program, _, _ = router.compile_program(version=7)

Expand Down
6 changes: 5 additions & 1 deletion examples/printers/cfg.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from pyteal import *
# pylint: disable=undefined-variable
# type: ignore[name-defined]
from pyteal import * # pylint: disable=wildcard-import,unused-wildcard-import

router = Router(
name="CFGExample",
bare_calls=BareCallActions(),
)


@router.method(no_op=CallConfig.CREATE)
def create() -> Expr:
return Return()


@router.method(opt_in=CallConfig.CALL)
def opt_in() -> Expr:
return Return()
Expand Down
11 changes: 10 additions & 1 deletion examples/printers/human-summary.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
from pyteal import *
# pylint: disable=undefined-variable
# type: ignore[name-defined]
from pyteal import * # pylint: disable=wildcard-import, unused-wildcard-import


router = Router(
name="HumanSummaryExample",
bare_calls=BareCallActions(),
)


@Subroutine(TealType.none)
def is_creator() -> Expr:
return Assert(Txn.sender() == Global.creator_address())


@router.method(no_op=CallConfig.CREATE)
def create() -> Expr:
return Return()


@router.method(update_application=CallConfig.CALL)
def update_application() -> Expr:
return is_creator()


@router.method(delete_application=CallConfig.CALL)
def delete_application() -> Expr:
return is_creator()


@Subroutine(TealType.none)
def greet() -> Expr:
return Log(Bytes("Hello"))


@router.method(no_op=CallConfig.CALL)
def hello() -> Expr:
return greet()
Expand Down
7 changes: 6 additions & 1 deletion examples/printers/subroutine-cfg.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from pyteal import *
# pylint: disable=undefined-variable
# type: ignore[name-defined]
from pyteal import * # pylint: disable=wildcard-import, unused-wildcard-import


@Subroutine(TealType.none) # type: ignore[misc]
def foo_bar(n: Expr) -> Expr:
return If((n % Int(2)) == Int(0), Log(Bytes("Foo")), Log(Bytes("Bar")))


router = Router(
name="SubroutineCFGExample",
bare_calls=BareCallActions(),
)


@router.method(no_op=CallConfig.ALL)
def method_foo_bar() -> Expr:
return foo_bar(Int(0))
Expand Down
77 changes: 52 additions & 25 deletions examples/printers/transaction-context.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
from pyteal import *
# pylint: disable=undefined-variable
# type: ignore[name-defined]
from pyteal import * # pylint: disable=wildcard-import, unused-wildcard-import


def on_create() -> Expr:
return Approve()


def op_a() -> Expr:
return Seq([
return Seq(
[
Assert(And(Txn.group_index() == Int(0), Global.group_size() < Int(3))),
Approve(),
])
]
)


def op_b() -> Expr:
return Seq([
If(
Global.group_size() <= Int(4),
return Seq(
[
If(
Global.group_size() == Int(3),
Assert(Txn.group_index() == Int(1)),
Global.group_size() <= Int(4),
If(
Global.group_size() == Int(2),
Return(Txn.group_index() == Int(0)),
Global.group_size() == Int(3),
Assert(Txn.group_index() == Int(1)),
If(
Global.group_size() == Int(2),
Return(Txn.group_index() == Int(0)),
),
),
Assert(
And(
Global.group_size() > Int(5),
Global.group_size() < Int(11),
Txn.group_index() == Int(2),
)
),
),
Assert(And(Global.group_size() > Int(5), Global.group_size() < Int(11), Txn.group_index() == Int(2)))
),
Approve()
])
Approve(),
]
)


# def approval_program() -> Expr:
# return Cond(
Expand All @@ -33,19 +49,30 @@ def op_b() -> Expr:
# [Txn.application_args[Int(0)] == Bytes("b"), op_b()],
# )


def approval_program() -> Expr:
# return op_2()
return Seq([
If(
Global.group_size() <= Int(4),
Seq([
Assert(Global.group_size() == Int(3)),
Assert(Txn.group_index() == Int(1)),
]),
Assert(And(Global.group_size() > Int(5), Global.group_size() < Int(11), Txn.group_index() == Int(2)))
),
Approve()
])
return Seq(
[
If(
Global.group_size() <= Int(4),
Seq(
[
Assert(Global.group_size() == Int(3)),
Assert(Txn.group_index() == Int(1)),
]
),
Assert(
And(
Global.group_size() > Int(5),
Global.group_size() < Int(11),
Txn.group_index() == Int(2),
)
),
),
Approve(),
]
)


pragma(compiler_version="0.22.0")
Expand Down

0 comments on commit dec93b8

Please sign in to comment.