-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendFrom.py
More file actions
73 lines (60 loc) · 2.55 KB
/
sendFrom.py
File metadata and controls
73 lines (60 loc) · 2.55 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
from rpc_connection import RPC_Connection
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)
sendToAddress = "nformntrCCWRSRApRFJDQs2YcrMEoy49CL"
sendAmount = 6000
sendFromAddress = "nZ3pBsb9ykUktJHqW5coo2ZkUa1WgZKK61"
# Get List of UTXOs
data = {}
#"params": [1, 9999999, [] , true, { "minimumAmount": 5 } ]
data = rpc.command("listunspent", params=[1, 9999999, [sendFromAddress] ])
txin = []
# verbose output (for debugging)
verbose = 1
curAmount = 0
for line in data:
if line["spendable"] is True:
curAmount = curAmount + line["amount"]
txin.append({"txid": line["txid"], "vout": line["vout"]})
if curAmount > sendAmount:
rawtx = {}
change = (curAmount - sendAmount - 0.01)
param = [txin, {sendToAddress: sendAmount, sendFromAddress: change}]
rawtx = rpc.command("createrawtransaction", params=param)
if verbose == 1:
print ("RAW TRANSACTION")
print (rawtx)
# decode to extract size data
decodedtx = {}
decodedtx = rpc.command("decoderawtransaction", params=[rawtx])
if verbose == 1:
print ("DECODED TRANSACTION")
print(json.dumps(decodedtx, indent=4))
# print(decodedtx)
# rather decode in the core wallet console for debugging
signrawtx = rpc.command("signrawtransaction", params=[rawtx])
if verbose == 1:
print ("SIGNED TRANSACTION")
print(json.dumps(signrawtx, indent=4))
#print(signrawtx)
sendtx =""
sendtx = rpc.command("sendrawtransaction", params=[signrawtx["hex"]])
if verbose == 1:
print ("SENT TRANSACTION")
print(json.dumps(sendtx, indent=4))
break