forked from komodoservices/pos64splitter
-
Notifications
You must be signed in to change notification settings - Fork 30
/
EQsendmany64.py
executable file
·53 lines (49 loc) · 1.93 KB
/
EQsendmany64.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
#!/usr/bin/env python3
import sys
import json
import stakerlib
CHAIN = input('Please specify chain: ')
try:
rpc_connection = stakerlib.def_credentials(CHAIN)
except Exception as e:
sys.exit(e)
balance = float(rpc_connection.getbalance())
print('Balance: ' + str(balance))
CHANGE = input("Please specify how much change you want to keep unlocked: ")
if int(CHANGE) < 1:
sys.exit('Cant have negative change. Try again.')
UTXOS = input("Please specify the amount of UTXOs to send to each segid: ")
AMOUNT = int((float(balance)-float(CHANGE))/(int(UTXOS)*64))
print('Amount per UTXO'+str(AMOUNT))
total = float(AMOUNT) * int(UTXOS) * 64
print('Total amount: ' + str(total))
if total > balance:
print('Total sending is ' + str(total-balance) + ' more than your balance. Try again.')
segidTotal = balance / 64
sys.exit('Total avalible per segid is: ' + str(segidTotal))
# function to do sendmany64 UTXOS times, locking all UTXOs except change
def sendmanyloop(rpc_connection, amount, utxos):
txid_list = []
for i in range(int(utxos)):
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)
sendmanyloop_result = sendmanyloop(rpc_connection, AMOUNT, UTXOS)
# unlock all locked utxos
stakerlib.unlockunspent(rpc_connection)
for i in sendmanyloop_result:
print(i)
print('Success!')