Skip to content

Commit 39a3133

Browse files
committed
Default location of bitcoin dir on various platforms
1 parent 16810f4 commit 39a3133

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

bitcoin/rpc.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ class InWarmupError(JSONRPCError):
115115
RPC_ERROR_CODE = -28
116116

117117

118+
def default_btc_dir():
119+
if platform.system() == 'Darwin':
120+
return os.path.expanduser('~/Library/Application Support/Bitcoin/')
121+
elif platform.system() == 'Windows':
122+
return os.path.join(os.environ['APPDATA'], 'Bitcoin')
123+
return os.path.expanduser('~/.bitcoin')
124+
125+
118126
class BaseProxy(object):
119127
"""Base JSON-RPC proxy class. Contains only private methods; do not use
120128
directly."""
@@ -135,13 +143,7 @@ def __init__(self,
135143
if service_url is None:
136144
# Figure out the path to the bitcoin.conf file
137145
if btc_conf_file is None:
138-
if platform.system() == 'Darwin':
139-
btc_conf_file = os.path.expanduser('~/Library/Application Support/Bitcoin/')
140-
elif platform.system() == 'Windows':
141-
btc_conf_file = os.path.join(os.environ['APPDATA'], 'Bitcoin')
142-
else:
143-
btc_conf_file = os.path.expanduser('~/.bitcoin')
144-
btc_conf_file = os.path.join(btc_conf_file, 'bitcoin.conf')
146+
btc_conf_file = os.path.join(default_btc_dir(), 'bitcoin.conf')
145147

146148
# Bitcoin Core accepts empty rpcuser, not specified in btc_conf_file
147149
conf = {'rpcuser': ""}

0 commit comments

Comments
 (0)