-
Notifications
You must be signed in to change notification settings - Fork 24
/
btcrpcfunctions.py
45 lines (39 loc) · 1.68 KB
/
btcrpcfunctions.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
from imports import *
import variables as v
from formating import *
home = os.getenv("HOME")
def BTCprogress():
if not (os.path.exists(home + "/.bitcoin")):
return 0
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli getblockchaininfo'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
if not (len(response[0]) == 0):
bitcoinprogress = json.loads(response[0].decode("utf-8"))['verificationprogress']
bitcoinprogress = bitcoinprogress * 100
bitcoinprogress = round(bitcoinprogress, 3)
else:
bitcoinprogress = 0
return bitcoinprogress
def BTCFinished():
if not (os.path.exists(home + "/.bitcoin")):
return False
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli getblockchaininfo'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
if not (len(response[0]) == 0):
bitcoinprogress = json.loads(response[0].decode("utf-8"))['initialblockdownload']
else:
bitcoinprogress = True
return not bitcoinprogress
def BTCClosed():
if (subprocess.call('lsof -n -i :8332', shell=True) != 1):
return False
return True
def BTCRunning():
if not (BTCprogress() == 0):
return True
return False
def blockheight():
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli getblockchaininfo'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
Blockinfo = json.loads(response[0].decode("utf-8"))
blockheight = 0
if Blockinfo['pruned']:
blockheight = Blockinfo['pruneheight']
return str(blockheight)