commit 7314292ecf19fca3d6bba48e77ca6bc84d38ee26
parent 2b9de8eed1de0f4a138021db3daf0972ee90d186
Author: Kristaps Kaupe <kristaps@blogiem.lv>
Date: Mon, 21 Feb 2022 10:34:25 +0200
Support bitcoind rpc_cookie_file auth (#44)
Diffstat:
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/config.py b/config.py
@@ -23,6 +23,7 @@ host = get_opt("host", "127.0.0.1")
rpcport = get_opt("rpcport", "8332")
username = get_opt("username", "bitcoinrpc")
password = get_opt("password", "rpcpassword")
+rpc_cookie_file = get_opt("rpc_cookie_file", "")
wallet = get_opt("wallet", "")
api_key_path = get_opt("api_key_path", "SatSale_API_key")
tunnel_host = get_opt("tunnel_host", None)
diff --git a/config.toml b/config.toml
@@ -6,8 +6,10 @@ host = "127.0.0.1"
rpcport = "8332"
# From ~/.bitcoin/bitcoin.conf
+# Use either username / password pair or rpc_cookie_file
username = "bitcoinrpc"
password = "rpcpassword"
+#rpc_cookie_file =
# Wallet (empty "" if your node has a single wallet, OR wallet name/path as shown in `biitcoin-cli listwallets`)
wallet = ""
diff --git a/node/bitcoind.py b/node/bitcoind.py
@@ -1,8 +1,9 @@
-import time
-import uuid
-import qrcode
import json
import logging
+import os
+import qrcode
+import time
+import uuid
import config
from payments.price_feed import get_btc_value
@@ -29,12 +30,23 @@ class btcd:
def __init__(self):
from bitcoinrpc.authproxy import AuthServiceProxy
+ if config.rpc_cookie_file:
+ if os.path.isfile(config.rpc_cookie_file):
+ rpc_credentials_str = open(config.rpc_cookie_file, "r").read()
+ (username, password) = rpc_credentials_str.split(":")
+ else:
+ raise Exception("rpc_cookie_file {} not found".format(
+ config.rpc_cookie_file))
+ else:
+ username = config.username
+ password = config.password
+
for i in range(config.connection_attempts):
if config.tor_bitcoinrpc_host is None:
self.tor = False
connection_str = "http://{}:{}@{}:{}/wallet/{}".format(
- config.username,
- config.password,
+ username,
+ password,
config.host,
config.rpcport,
config.wallet,