-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoracle.py
More file actions
123 lines (106 loc) · 4.49 KB
/
Copy pathoracle.py
File metadata and controls
123 lines (106 loc) · 4.49 KB
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
import requests
import json
import base64
from algosdk.v2client import algod
from algosdk import transaction
def wait_for_confirmation(client, txid):
last_round = client.status().get('last-round')
txinfo = client.pending_transaction_info(txid)
while not (txinfo.get('confirmed-round') and txinfo.get('confirmed-round') > 0):
print('Waiting for confirmation')
last_round += 1
client.status_after_block(last_round)
txinfo = client.pending_transaction_info(txid)
print('Transaction confirmed in round', txinfo.get('confirmed-round'))
return txinfo
def show_messages(init_address):
retlist = []
# set up query parameters
address = init_address
headers = {
"X-API-Key": "1xxSTImRIS7YrSc6GQeTc1XILcoh8faP5F3o1rVA",
}
# construct query URL
base_url = "https://algoindexer.testnet.algoexplorerapi.io/v2/accounts/"
query_url = f"{base_url}{address}/transactions"
# submit query and parse JSON response
response = requests.get(query_url)
response_json = json.loads(response.text)
# process response data
transactions = response_json["transactions"]
tx = transactions[0]
note = "empty"
if("note" in tx):
note = tx['note']
base64_bytes = note.encode('ascii')
message_bytes = base64.b64decode(base64_bytes)
message = message_bytes.decode('ascii')
retlist.append([message, tx["sender"]])
# for tx in transactions:
# print( tx['id'])
# if(tx["sender"] == address):
# continue
# if(tx["id"] == 'T5GCMHM3QIMMVA2CPKIKYS2UGS7ON4FHGQMX4PLBO6W6WCA6MN6A' or tx["id"] == 'U6YDTAMEUTEZDJELHEUEUJP3LECWSMHW3JNKINO5U25FDLBT7DMQ'):
# continue
# note = "empty"
# if("note" in tx):
# note = tx['note']
# base64_bytes = note.encode('ascii')
# message_bytes = base64.b64decode(base64_bytes)
# message = message_bytes.decode('ascii')
# retlist.append([message, tx["sender"]])
return retlist
def runner(init_address):
# set up query parameters
address = init_address
headers = {
"X-API-Key": "1xxSTImRIS7YrSc6GQeTc1XILcoh8faP5F3o1rVA",
}
# construct query URL
base_url = "https://algoindexer.testnet.algoexplorerapi.io/v2/accounts/"
query_url = f"{base_url}{address}/transactions"
# submit query and parse JSON response
response = requests.get(query_url)
response_json = json.loads(response.text)
# process response data
transactions = response_json["transactions"]
for tx in transactions:
tx_id = tx["id"]
if(tx_id == '7H6KASJRX6KOXWYNLGGPIQOYH3EU7OPCE4WMYE4M3IBU3HAZ3QSA'):
continue
amount = 0
if("payment-transaction" in tx):
amount = tx["payment-transaction"]["amount"]
note = "empty"
if("note" in tx):
note = tx['note']
base64_bytes = note.encode('ascii')
message_bytes = base64.b64decode(base64_bytes)
message = message_bytes.decode('ascii')
# do something with tx_id and amount
if(len(message) > 4 and message[0:4] == 'DATA'):
# data received
sender = tx['sender']
algodclient = algod.AlgodClient("", 'https://testnet-algorand.api.purestake.io/ps2', headers)
# get suggested parameters from Algod
params = algodclient.suggested_params()
gh = params.gh
first_valid_round = params.first
last_valid_round = params.last
fee = params.min_fee
send_amount = 10000
note = "Data received"
existing_account = address
send_to_address = sender
# Create and sign transaction
tx = transaction.PaymentTxn(existing_account, params, send_to_address, send_amount, note=note)
signed_tx = tx.sign('sSX9btZ71Wgz9yHXEFzxEhsK0vxBLDW0z3ekzH/00BnrGVHiS34LHhuaUbkeIHIo+MRKFc2xVLd7KgSzXLQgeg==')
try:
tx_confirm = algodclient.send_transaction(signed_tx)
#print('Transaction sent with ID', signed_tx.transaction.get_txid())
wait_for_confirmation(algodclient, txid=signed_tx.transaction.get_txid())
except Exception as e:
print(e)
print(tx_id, amount, message)
message = 'empty'
# runner("BU5IN3BOIYVWD3TW2XQFOQJ3EGFFYCMHN24JBNMR5IU2LWST74TPZAQYBI")