-
Notifications
You must be signed in to change notification settings - Fork 26
/
runPayments.py
54 lines (39 loc) · 1.56 KB
/
runPayments.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
import redis
import json
import requests
import time
r = redis.StrictRedis(password="PASSWORD HERE")
ethToWei = 1000000000000000000
def sendTx(fromAddr, to, wei):
url = "http://localhost:8079"
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
txObject = {"from" : fromAddr, "to" : to, "value" : hex( int(wei) - int((0.01 * ethToWei)) )}
message = {"jsonrpc" : "2.0", "method" : "eth_sendTransaction", "params" : [txObject], "id" : 1}
response = requests.post(url,headers=headers, json=message)
print response.text
a = json.loads(response.text)
return a["result"]
def waitForTx(txId):
message = {"jsonrpc" : "2.0", "method" : "eth_getTransactionReceipt", "params" : [txId], "id" : 1}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
url = "http://localhost:8079"
done = False
while(not done):
print "waiting for tx recept "
time.sleep(3)
response = requests.post(url,headers=headers, json=message)
a = json.loads(response.text)
if(a['result'] is not None):
done = True
r.set("lastpayout", int(round(time.time() * 1000)))
myAddress = "POOLADDRESS"
balances = r.hgetall("balances")
for address, value in balances.iteritems():
if(int(value) > 0.2 * ethToWei and len(address) == 42):
txId = sendTx(myAddress, address, value)
print "sent " + str(int(value)/1000000000000000000.) + " to " + address
waitForTx(txId)
r.zadd("payments:" + address, int(round(time.time() * 1000)), value)
r.hdel("balances", address)
else:
print "Too low or bad address " + address + " " + str(int(value)/1000000000000000000.)