Using Global get Ex on Noop call giving error when deploying app

I’m running the counter applications in the docs, and I made a small change: I’d like to check that the count value exists in state.

Because count is initialized to 0, I figured I could call global get ex with the current application ID and use the Maybe Value to do the check. However, I get the following error:

File "/usr/local/lib/python3.9/site-packages/pyteal/compiler/compiler.py", line 215, in compileTeal
    localSlotAssignments = assignScratchSlotsToSubroutines(
  File "/usr/local/lib/python3.9/site-packages/pyteal/compiler/scratchslots.py", line 95, in assignScratchSlotsToSubroutines
    raise TealInternalError(msg) from errors[0]
pyteal.TealInternalError: Encountered 1 error when assigning slots to subroutine

Here is the code: The only change between this and the counter (add, deduct) example in the official algorand docs is the first line , and the third line in the And block.

   myStatus = App.globalGetEx(Txn.applications[0], Bytes("Count")).hasValue()
   handle_noop = Cond(
       [And(
            Global.group_size() == Int(1),
            Txn.application_args[0] == Bytes("Add"),
            myStatus > Int(0)
        ),add],
        [And(
            Global.group_size() == Int(1),
            Txn.application_args[0] == Bytes("Deduct"),
        ), deduct]
   )

Hi jjEvans,

This trips up a lot of folks. It has to do with the AppGlobalGetEx returning a MaybeValue which needs to be included in a Seq (or some other expression) prior to calling hasValue

You may try something like

   myStatus = App.globalGetEx(0, Bytes("Count"))
   handle_noop = Seq(
    myStatus,
    Cond(
       [And(
            Global.group_size() == Int(1),
            Txn.application_args[0] == Bytes("Add"),
            myStatus.hasValue()
        ),add],
        [And(
            Global.group_size() == Int(1),
            Txn.application_args[0] == Bytes("Deduct"),
        ), deduct]
   )
)

This is a strange way to offer this functionality so I hope will be tweaked in upcoming versions of PyTEAL.

Ben

1 Like