-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsig.py
66 lines (55 loc) · 2.06 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
56
57
58
59
60
61
62
63
64
65
66
from pyteal import *
def sig_tmpl(
admin_addr="PU2IEPAQDH5CCFWVRB3B5RU7APETCMF24574NA5PKMYSHM2ZZ3N3AIHJUI",
app_id=1,
seed_amt=int(1e9),
):
admin_addr = Addr(admin_addr)
seed_amt = Int(seed_amt)
# 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 = Btoi(Bytes(app_id.to_bytes(8, "big")))
@Subroutine(TealType.uint64)
def init():
algo_seed = Gtxn[0]
optin = Gtxn[1]
return And(
algo_seed.type_enum() == TxnType.Payment,
algo_seed.sender() == admin_addr,
algo_seed.amount() == seed_amt,
optin.type_enum() == TxnType.ApplicationCall,
optin.on_completion() == OnComplete.OptIn,
optin.application_id() == admin_app_id,
)
@Subroutine(TealType.uint64)
def close():
closeout = Gtxn[0]
algo_close = Gtxn[1]
return And(
closeout.type_enum() == TxnType.ApplicationCall,
closeout.on_completion() == OnComplete.CloseOut,
closeout.application_id() == admin_app_id,
algo_close.type_enum() == TxnType.Payment,
algo_close.receiver() == admin_addr,
algo_close.close_remainder_to() == admin_addr,
algo_close.sender() == admin_addr,
algo_close.amount() == Int(int(0)),
)
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")),
Cond(
[Global.group_size() != Int(2), Reject()],
[Int(1), Return(Or(init(), close()))],
),
)
def get_sig_tmpl(**kwargs):
return compileTeal(
sig_tmpl(**kwargs), mode=Mode.Signature, version=5, assembleConstants=True
)
if __name__ == "__main__":
with open("sig.tmpl.teal", "w") as f:
f.write(get_sig_tmpl())