-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.py
143 lines (110 loc) · 3.39 KB
/
deploy.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import base64
from algosdk.v2client import algod
from algosdk.transaction import *
def create_asa(
client: algod.AlgodClient,
addr: str,
pk: str,
name: str,
unit_name: str,
total: int,
decimals: int,
) -> int:
# Get suggested params from network
sp = client.suggested_params()
# Create the transaction
create_txn = AssetCreateTxn(
addr,
sp,
total,
decimals,
False,
unit_name=unit_name,
asset_name=name,
)
# Sign it
signed_txn = create_txn.sign(pk)
# Send it
txid = client.send_transaction(signed_txn)
# Wait for the result so we can return the asset id
result = wait_for_confirmation(client, txid, 4)
return result["asset-index"]
def create_app(
client: algod.AlgodClient,
addr: str,
pk: str,
approval: str,
clear: str,
global_schema,
local_schema,
) -> int:
# Get suggested params from network
sp = client.suggested_params()
# Read in approval teal source && compile
app_result = client.compile(approval)
app_bytes = base64.b64decode(app_result["result"])
# Read in clear teal source && compile
clear_result = client.compile(clear)
clear_bytes = base64.b64decode(clear_result["result"])
# Create the transaction
create_txn = ApplicationCreateTxn(
addr,
sp,
0,
app_bytes,
clear_bytes,
global_schema,
local_schema,
)
# Sign it
signed_txn = create_txn.sign(pk)
# Ship it
txid = client.send_transaction(signed_txn)
# Wait for the result so we can return the app id
result = wait_for_confirmation(client, txid, 4)
app_id = result["application-index"]
app_addr = logic.get_application_address(app_id)
# Make sure the app address is funded with at least min balance
ptxn = PaymentTxn(addr, sp, app_addr, int(1e8))
txid = client.send_transaction(ptxn.sign(pk))
wait_for_confirmation(client, txid, 4)
return app_id, app_addr
def update_app(
client: algod.AlgodClient, app_id: int, addr: str, pk: str, get_approval, get_clear
) -> int:
# Get suggested params from network
sp = client.suggested_params()
# Read in approval teal source && compile
app_result = client.compile(get_approval())
app_bytes = base64.b64decode(app_result["result"])
# Read in clear teal source && compile
clear_result = client.compile(get_clear())
clear_bytes = base64.b64decode(clear_result["result"])
# Create the transaction
create_txn = ApplicationUpdateTxn(
addr,
sp,
app_id,
app_bytes,
clear_bytes,
)
# Sign it
signed_txn = create_txn.sign(pk)
# Ship it
txid = client.send_transaction(signed_txn)
wait_for_confirmation(client, txid, 4)
def delete_app(client: algod.AlgodClient, app_id: int, addr: str, pk: str):
# Get suggested params from network
sp = client.suggested_params()
# Create the transaction
txn = ApplicationDeleteTxn(addr, sp, app_id)
# sign it
signed = txn.sign(pk)
# Ship it
txid = client.send_transaction(signed)
return wait_for_confirmation(client, txid, 4)
def destroy_apps(client: algod.AlgodClient, addr: str, pk: str):
acct = client.account_info(addr)
# Delete all apps created by this account
for app in acct["created-apps"]:
delete_app(client, app["id"], addr, pk)