forked from KMDLabs/pos64staker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNDsendmany64.py
executable file
·84 lines (76 loc) · 2.6 KB
/
RNDsendmany64.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
#!/usr/bin/env python3
import random
import sys
import json
import stakerlib
# function to do sendmany64 UTXOS times, locking all UTXOs except change
def RNDsendmanyloop(rpc_connection, amounts):
txid_list = []
for amount in amounts:
sendmany64_txid = stakerlib.sendmany64(rpc_connection, amount)
txid_list.append(sendmany64_txid)
getrawtx_result = rpc_connection.getrawtransaction(sendmany64_txid, 1)
lockunspent_list = []
# find change output, lock all other outputs
for vout in getrawtx_result['vout']:
if vout['value'] != float(amount):
change_output = vout['n']
else:
output_dict = {
"txid": sendmany64_txid,
"vout": vout['n']
}
lockunspent_list.append(output_dict)
lockunspent_result = rpc_connection.lockunspent(False, lockunspent_list)
return(txid_list)
CHAIN = input('Please specify chain: ')
try:
rpc_connection = stakerlib.def_credentials(CHAIN)
except Exception as e:
sys.exit(e)
try:
balance = float(rpc_connection.getbalance())
except Exception as e:
sys.exit(e)
print('Balance: ' + str(balance))
while True:
UTXOS = int(input("Please specify the amount of UTXOs to send to each segid: "))
if UTXOS < 3:
print('Must have more than 3 utxos per segid, try again.')
continue
TUTXOS = UTXOS * 64
print('Total number of UTXOs: ' + str(TUTXOS))
average = float(balance) / int(TUTXOS)
print('Average utxo size: ' + str(average))
variance = int(input('Enter percentage of variance: '))
minsize = round(float(average) * (1-(variance/100)),2)
if minsize < 1:
print('Cant stake coin amounts less than 1 coin, try again.')
continue
maxsize = round(average + float(average) * (variance/100),2)
print('Min size: ' + str(minsize))
print('Max size: ' + str(maxsize))
ret = input('Are you happy with these? ').lower()
if ret.startswith('y'):
break
total = 0
totalamnt = 0
AMOUNTS = []
finished = False
while finished == False:
for i in range(UTXOS):
amnt = round(random.uniform(minsize,maxsize),2)
totalamnt += amnt * 64
AMOUNTS.append(amnt)
if totalamnt > balance-(balance*0.01):
totalamnt = 0
AMOUNTS.clear()
break
if totalamnt > balance-(balance*0.02):
finished = True
sendmanyloop_result = RNDsendmanyloop(rpc_connection, AMOUNTS)
# unlock all locked utxos
stakerlib.unlockunspent(rpc_connection)
for i in sendmanyloop_result:
print(i)
print('Success!')