-
Notifications
You must be signed in to change notification settings - Fork 2
/
operations.py
100 lines (87 loc) · 3.08 KB
/
operations.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
from algosdk import account, encoding, mnemonic
from algosdk.future import transaction
from utilities import wait_for_confirmation
from algosdk.logic import get_application_address
from dotenv import load_dotenv
import os
load_dotenv()
def create_app(
algod_client,
creator_address,
private_key,
approval_program,
clear_program,
global_schema,
local_schema ):
#creator default address
#declare on_complete as no_op
on_complete = transaction.OnComplete.NoOpOC.real
#build transaction
params = algod_client.suggested_params()
#create unsigned Application Create Txn
unsigned_txn = transaction.ApplicationCreateTxn(
creator_address,
params,
on_complete,
approval_program,
clear_program,
global_schema,
local_schema
)
#sign txn
signed_txn = unsigned_txn.sign(private_key)
tx_id = signed_txn.transaction.get_txid()
#submit transaction
algod_client.send_transaction(signed_txn)
#wait for confirmation
pmtx = wait_for_confirmation(algod_client, tx_id, 5)
#display results
transaction_response = algod_client.pending_transaction_info(tx_id)
app_id = transaction_response['application-index']
print("created new appid : {}".format(app_id))
return app_id
def call_app(
algod_client,
app_id,
sender_private_key,
index_app_id,
oracle_app_id
):
#build transaction
params = algod_client.suggested_params()
sender = account.address_from_private_key(sender_private_key)
app_address = get_application_address(app_id)
update_price_call = transaction.ApplicationCallTxn(
sender = sender,
sp = params,
index = app_id,
on_complete = transaction.OnComplete.NoOpOC,
foreign_apps=[index_app_id, oracle_app_id]
)
update_price_call_signed_txn = update_price_call.sign(sender_private_key)
update_price_call_signed_txn_id = update_price_call_signed_txn.get_txid()
tx_id = algod_client.send_transaction( update_price_call_signed_txn)
tx = wait_for_confirmation(algod_client, tx_id, 5)
print('price has been updated to global state. Here is your transaction ID: ', tx_id)
return tx_id
# delete application
def delete_app(client, private_key, index):
# declare sender
sender = account.address_from_private_key(private_key)
# get node suggested parameters
params = client.suggested_params()
# comment out the next two (2) lines to use suggested fees
params.flat_fee = True
params.fee = 1000
# create unsigned transaction
txn = transaction.ApplicationDeleteTxn(sender, params, index)
# sign transaction
signed_txn = txn.sign(private_key)
tx_id = signed_txn.transaction.get_txid()
# send transaction
client.send_transactions([signed_txn])
# await confirmation
wait_for_confirmation(client, tx_id, 5)
# display results
transaction_response = client.pending_transaction_info(tx_id)
print("Thank your for using the price oracle. Your app has now been deleted. Deleted app-id:", transaction_response["txn"]["txn"]["apid"])