-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbtc_wallet.py
91 lines (66 loc) · 3.29 KB
/
btc_wallet.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
85
86
87
88
89
import subprocess
import time
import json
bwallets = ['/home/bitrail/.electrum/wallets/segwit']
btcbinpath = '/usr/local/bin/electrum'
def bstartd():
dproc = subprocess.Popen([btcbinpath, 'daemon', 'start'], stdout=subprocess.PIPE)
time.sleep(5)
print(dproc.stdout);
output = list()
for wal in bwallets:
dproc2 = subprocess.run([btcbinpath, 'daemon', 'load_wallet', '-w', wal], stdout=subprocess.PIPE)
time.sleep(1)
print('loading wallet: ' + wal)
print(dproc2.stdout.decode('utf-8'))
return True
def bstopd():
dproc = subprocess.run([btcbinpath, 'daemon', 'stop'], stdout=subprocess.PIPE)
print(dproc.stdout);
def bgetstatus(wallet):
result = subprocess.run([btcbinpath, 'history', '-w', wallet], stdout=subprocess.PIPE)
response = json.loads(result.stdout.decode('utf-8'))
return response
def bgetaddrtx(addr, wallet):
result = subprocess.run([btcbinpath, 'getaddresshistory', addr, '-w', wallet], stdout=subprocess.PIPE)
#print(result.stdout.decode('utf-8'))
response = json.loads(result.stdout.decode('utf-8'))
return response
def bgettxinfo(txid, wallet):
result = subprocess.run([btcbinpath, 'gettransaction', txid, '-w', wallet], stdout=subprocess.PIPE)
response = json.loads(result.stdout.decode('utf-8'))
return response
def bgetfeerate():
result = subprocess.run([btcbinpath, 'getfeerate'], stdout=subprocess.PIPE)
response = json.loads(result.stdout.decode('utf-8'))
return response
def bbalance(wallet):
result = subprocess.run([btcbinpath, 'getbalance', '-w', wallet], stdout=subprocess.PIPE)
print(result.stdout.decode('utf-8'))
response = json.loads(result.stdout.decode('utf-8'))
return response
def btopup(wallet):
result = subprocess.run([btcbinpath, 'createnewaddress', '-w', wallet], stdout=subprocess.PIPE)
response = result.stdout.decode('utf-8').rstrip()
return response
def bvalidate(addr, wallet):
result = subprocess.run([btcbinpath, 'validateaddress', addr, '-w', wallet], stdout=subprocess.PIPE)
response = result.stdout.decode('utf-8').rstrip()
return response
def btx(addr, amount, wallet, btcfee):
#result = subprocess.run([btcbinpath, 'payto', addr, amount, '-f', btcfee, '-w', wallet], stdout=subprocess.PIPE)
#unsigned = json.loads(result.stdout.decode('utf-8'))
#result = subprocess.run([btcbinpath, 'signtransaction', unsigned['hex'], '-w', wallet], stdout=subprocess.PIPE)
#signed = json.loads(result.stdout.decode('utf-8'))
#result = subprocess.run([btcbinpath, 'broadcast', signed['hex'], '-w', wallet], stdout=subprocess.PIPE)
ps = subprocess.Popen((btcbinpath, 'payto', addr, amount, '-f', btcfee, '-w', wallet), stdout=subprocess.PIPE)
result = subprocess.run((btcbinpath, 'broadcast', '-w', wallet, '-'), stdin=ps.stdout, stdout=subprocess.PIPE)
ps.wait()
response = json.loads(result.stdout.decode('utf-8'))
return response
def btx_many(recipient_pool, wallet, btcfee):
ps = subprocess.Popen((btcbinpath, 'paytomany', recipient_pool, '-f', btcfee, '-w', wallet), stdout=subprocess.PIPE)
result = subprocess.run((btcbinpath, 'broadcast', '-w', wallet, '-'), stdin=ps.stdout, stdout=subprocess.PIPE)
ps.wait()
#response = json.loads(result.stdout.decode('utf-8'))
return result.stdout