-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
138 lines (115 loc) · 4.76 KB
/
main.py
File metadata and controls
138 lines (115 loc) · 4.76 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from rpc_connection import RPC_Connection
import math
import time
# we need math for the fee calculation
# we need time to sleep (wait for next block)
# rpc_connection wraps our calls nicely
if __name__ == '__main__':
# I assume the node runs local (127.0.0.1)
# This should match your dogecoin.conf
testnet = 1 # optional if "dogecoin-qt.texe -testnet" is used
server = 1
rpcuser = "YourRPCUser"
rpcpassword = "YourRPCPassword"
# port standard values if not defined
# use them if you or dont assign those variables at all
# if you are not merged mining on this node
# rpcport = 44555
# port = 44556
# my non standard ports for merged mining
rpcport = 7332
port = 7333
# End of dogecoin.conf
rpc = RPC_Connection(rpcuser, rpcpassword, "127.0.0.1", rpcport)
# Get List of UTXOs
data = {}
data = rpc.command("listunspent")
# only send n transactions
maxloops = 1
# declare some vars
loops = 0
sumamount = 0
counter = 0
param = ""
txin = []
# verbose output (for debugging)
verbose = 0
# aggregate n (txcount) inputs into one output, sent to nformntrCCWRSRApRFJDQs2YcrMEoy49CL (aggAddress)
txcount = 100
aggAddress = "YOUR_DOGECOIN_ADDRESS" #"nformntrCCWRSRApRFJDQs2YcrMEoy49CL"
for line in data:
# each line is one UTXO
# print (line)
if line["address"] == aggAddress:
# this is the address we want to aggregate to (sitting in the same wallet)
# in that case we don't want to do anything...
if verbose == 1:
print ("UTXO from aggregate ("+aggAddress+") address")
else:
counter = counter +1
if verbose == 1:
print ("txid: " + line["txid"])
print ("vout: " +str(line["vout"]))
print ("amount: " + str(line["amount"]))
# cummulate inputs to use it as one output
sumamount = sumamount + line["amount"]
if verbose == 1:
print ("sumamount:" + str(sumamount))
print ("counter: " + str(counter))
# comma separator only after the first tx
comma = ""
if counter > 1:
comma = ","
# create the tx
# template
# dogecoin-cli createrawtransaction "[{\"txid\":\"myid\",\"vout\":0}]" "{\"address\":0.01}"
txin.append({"txid": line["txid"], "vout": line["vout"]})
param = param + comma + "{\"txid\":\""+line["txid"]+"\",\"vout\":"+str(line["vout"])+"}"
if verbose == 1:
print (param)
# amount of inputs to aggregate is satisfied
if counter == txcount:
# build output of the tx
# remove tx count as fee (=5 Doges for 5 TXs)
# just add 1 Doge fee per TX input, will be overwritten later...
sumamountorg = sumamount
sumamount = round(sumamount - txcount, 0)
# create raw transaction to get size of tx
rawtx = {}
param = [txin, {aggAddress: sumamount}]
rawtx = rpc.command("createrawtransaction" , params=param)
# decode to extract size data
decodedtx = {}
decodedtx = rpc.command("decoderawtransaction", params=[rawtx])
# 1 Doge per kB - if you want to handle dust you need to add 1 Doge per dust output
fee = math.ceil(decodedtx["size"]/1000)
# create raw transaction again with correct fee
sumamount = round(sumamountorg - fee, 0)
rawtx = {}
param = [txin, {aggAddress: sumamount}]
rawtx = rpc.command("createrawtransaction", params=param)
# sign raw transaction
signtx = rpc.command("signrawtransaction", params=[rawtx])
"""try:
print ("sign: "+signtx["hex"])
except:
print ("no hex?")
print ("return")
print (signtx)
print ("rawtx")
print (rawtx)
print("param")
print(param)"""
# not more txs then we defined erlier
if loops < maxloops:
sendtx = rpc.command("sendrawtransaction", params=[signtx["hex"]])
print("send: " + sendtx)
# wait 20 sec to add a ~3 txs to a block
if maxloops > 1:
time.sleep(20)
# reset vars and counters
counter = 0
param = ""
sumamount = 0
txin = []
loops = loops + 1