Skip to content

Commit c86b9ac

Browse files
committed
Default location of bitcoin dir on various platforms
1 parent ddfc189 commit c86b9ac

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
@@ -128,6 +128,14 @@ class InWarmupError(JSONRPCError):
128128
RPC_ERROR_CODE = -28
129129

130130

131+
def default_btc_dir():
132+
if platform.system() == 'Darwin':
133+
return os.path.expanduser('~/Library/Application Support/Bitcoin/')
134+
elif platform.system() == 'Windows':
135+
return os.path.join(os.environ['APPDATA'], 'Bitcoin')
136+
return os.path.expanduser('~/.bitcoin')
137+
138+
131139
class BaseProxy(object):
132140
"""Base JSON-RPC proxy class. Contains only private methods; do not use
133141
directly."""
@@ -148,13 +156,7 @@ def __init__(self,
148156
if service_url is None:
149157
# Figure out the path to the bitcoin.conf file
150158
if btc_conf_file is None:
151-
if platform.system() == 'Darwin':
152-
btc_conf_file = os.path.expanduser('~/Library/Application Support/Bitcoin/')
153-
elif platform.system() == 'Windows':
154-
btc_conf_file = os.path.join(os.environ['APPDATA'], 'Bitcoin')
155-
else:
156-
btc_conf_file = os.path.expanduser('~/.bitcoin')
157-
btc_conf_file = os.path.join(btc_conf_file, 'bitcoin.conf')
159+
btc_conf_file = os.path.join(default_btc_dir(), 'bitcoin.conf')
158160

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

0 commit comments

Comments
 (0)