-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
85 lines (62 loc) · 2.59 KB
/
functions.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
import requests
from config import INDEXER_CLIENT,ALGOD_CLIENT,ACCOUNT_PRIVATE_KEY, NETWORK
from algosdk import future
################################################
def get_min_balance(account_public_key):
if NETWORK == 'testnet':
response = requests.get("https://indexer.testnet.algoexplorerapi.io/v2/accounts/"+account_public_key)
else:
response = requests.get("https://indexer.algoexplorerapi.io/v2/accounts/"+account_public_key)
min_balance = response.json()['account']['min-balance']
return min_balance
################################################
def app_clear_state(account_public_key,appid):
params = ALGOD_CLIENT.suggested_params()
unsigned_tx = future.transaction.ApplicationClearStateTxn(account_public_key, params, appid)
signed_tx = unsigned_tx.sign(ACCOUNT_PRIVATE_KEY)
txid = ALGOD_CLIENT.send_transaction(signed_tx)
# wait for confirmation
try:
future.transaction.wait_for_confirmation(ALGOD_CLIENT, txid, 4)
ALGOD_CLIENT.pending_transaction_info(txid)
#print("Cleared app-id: ",transaction_response['txn']['txn']['apid'])
return True
except Exception as err:
print("\nError: ",err,"\n")
return False
################################################
def get_apps_list(account_public_key):
response = INDEXER_CLIENT.account_info(account_public_key)
if not 'apps-local-state' in response['account']:
return False
applist = {}
count = 0;
for app in response['account']['apps-local-state']:
if(app['deleted']==False):
count = count + 1
applist[count] = app['id']
if (count > 0):
return applist
else:
return False
################################################
def app_menu(account_public_key):
choice=True
while choice:
applist = get_apps_list(account_public_key)
if not applist:
return False
for appid in applist:
print(f"{appid}. {applist[appid]}")
print("0. EXIT")
choice=input(f"\nWhat app do you want to clear? [0-{len(applist)}]")
ichoice=int(choice)
if ichoice in range(1,len(applist)+1):
result = app_clear_state(account_public_key,applist[ichoice])
if result:
print(f"\nApp ID {applist[ichoice]} cleared\n")
elif ichoice==0:
#choice = None
return True
else:
print("\nNot Valid Choice Try again\n")