-
Notifications
You must be signed in to change notification settings - Fork 16
/
util.py
33 lines (31 loc) · 1.29 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from algopy import (
Bytes,
OnCompleteAction,
OpUpFeeSource,
TransactionType,
UInt64,
op,
subroutine,
)
@subroutine
def ensure_budget(required_budget: UInt64, fee_source: OpUpFeeSource) -> None:
# A budget buffer is necessary to deal with an edge case of ensure_budget():
# if the current budget is equal to or only slightly higher than the
# required budget then it's possible for ensure_budget() to return with a
# current budget less than the required budget. The buffer prevents this
# from being the case.
required_budget_with_buffer = required_budget + 10
while required_budget_with_buffer > op.Global.opcode_budget():
op.ITxnCreate.begin()
op.ITxnCreate.set_type_enum(TransactionType.ApplicationCall)
op.ITxnCreate.set_on_completion(OnCompleteAction.DeleteApplication)
op.ITxnCreate.set_approval_program(Bytes.from_hex("068101"))
op.ITxnCreate.set_clear_state_program(Bytes.from_hex("068101"))
match fee_source:
case OpUpFeeSource.GroupCredit:
op.ITxnCreate.set_fee(0)
case OpUpFeeSource.AppAccount:
op.ITxnCreate.set_fee(op.Global.min_txn_fee)
# case OpUpFeeSource.Any:
# any means no fee set
op.ITxnCreate.submit()