-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmassPayment.py
78 lines (70 loc) · 2.27 KB
/
massPayment.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
import json
import time
import pywaves as pw
import time
'''
Configuration section:
privateKey: the private key of the address you want to distribute from
file: the calculated payout file
timeout: timeout between requests send to nodes in ms
assetId: the id of the asset you want to distribute, '' for Waves
nodes: a list of nodes to which the signed transactions should be send to, in the format: http://host:port
'''
config = {
'privateKey': '',
'file': '',
# timeout between requests in ms
'timeout': 20,
'assetId': '',
'nodes': [
]
}
startTime = time.time()
totalPayments = 0
paid = 0
counter = 0
pw.setNode(config['nodes'][1], 'mainnet')
print(config['nodes'][0])
address = pw.Address(privateKey = config['privateKey'])
'''
Method that actually generates the signed transactions and sends them to
the configured nodes.
'''
def pay(batch):
global paid
global address
global counter
node = config['nodes'][counter % len(config['nodes'])]
counter += 1
pw.setNode(node, 'mainnet')
print('number of payouts in batch: ' + str(len(batch)))
print('batch: ' + str(batch))
print('paid from address: ' + address.address)
print('paid via node: ' + node)
paid += len(batch)
if (config['assetId'] != ''):
print('paying in asset: ' + config['assetId'])
tx = address.massTransferAssets(batch, pw.Asset(config['assetId']))
else:
print('paying in Waves!')
tx = address.massTransferWaves(batch)
print('tx: ' + str(tx))
with open(config['file']) as json_data:
payments = json.load(json_data)
currentBatch = []
totalPayments = len(payments)
for payment in payments:
if (len(currentBatch) < 100):
if (('assetId' in payment and payment['assetId'] != config['assetId']) or ('assetId' not in payment and config['assetId'] != '')):
print('transaction with wrong assetId found!')
exit()
currentBatch.append({ 'recipient': payment['recipient'], 'amount': payment['amount'] })
if (len(currentBatch) == 100):
pay(currentBatch)
currentBatch = []
time.sleep(config['timeout'] / 1000)
if (len(currentBatch) > 0):
pay(currentBatch)
print('planned payouts: ' + str(totalPayments) + ', paid: ' + str(paid))
usedTime = time.time() - startTime
print('time: ' + str(usedTime) + ' (' + str(totalPayments / usedTime) + 'transfers/s)')