forked from emg110/demo-local-state-expansion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sig.py
55 lines (42 loc) · 1.69 KB
/
sig.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from pyteal import *
def sig_tmpl():
# We encode the app id as an 8 byte integer to ensure its a known size
# Otherwise the uvarint encoding may produce a different byte offset
# for the template variables
admin_app_id = Tmpl.Int("TMPL_APP_ID")
admin_address = Tmpl.Bytes("TMPL_APP_ADDRESS")
seed_amt = Tmpl.Int("TMPL_SEED_AMT")
@Subroutine(TealType.uint64)
def init():
algo_seed = Gtxn[0]
optin = Gtxn[1]
rekey = Gtxn[2]
return And(
Global.group_size() == Int(3),
algo_seed.type_enum() == TxnType.Payment,
algo_seed.amount() == seed_amt,
algo_seed.rekey_to() == Global.zero_address(),
algo_seed.close_remainder_to() == Global.zero_address(),
optin.type_enum() == TxnType.ApplicationCall,
optin.on_completion() == OnComplete.OptIn,
optin.application_id() == admin_app_id,
optin.rekey_to() == Global.zero_address(),
rekey.type_enum() == TxnType.Payment,
rekey.amount() == Int(0),
rekey.rekey_to() == admin_address,
rekey.close_remainder_to() == Global.zero_address(),
)
return Seq(
# Just putting adding this as a tmpl var to make the address unique and deterministic
# We don't actually care what the value is, pop it
Pop(Tmpl.Int("TMPL_ADDR_IDX")),
Pop(Tmpl.Bytes("TMPL_EMITTER_ID")),
init(),
)
def get_sig_tmpl(**kwargs):
return compileTeal(
sig_tmpl(**kwargs), mode=Mode.Signature, version=6, assembleConstants=True
)
if __name__ == "__main__":
with open("sig.tmpl.teal", "w") as f:
f.write(get_sig_tmpl())