commit 7c2eb861500bad27bb9e9918fc99125953d41c22
parent 1c561c5c7a6351521f87cc7603868ad5efdd587c
Author: Nick <nicholas.w.farrow@gmail.com>
Date: Mon, 29 Mar 2021 01:45:29 +1100
Merge pull request #3 from Kixunil/refactoring
Lightning macaroon loading & API key in config
Diffstat:
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/config.py b/config.py
@@ -9,6 +9,9 @@ rpcport = "8332"
username = "bitcoinrpc"
password = "RPAPASSWORD"
+# File in which API key will be stored
+api_key_path = "BTCPyment_API_key"
+
# SSH tunnel to node (raspberry pi!)
# Make sure this command works `ssh HOST@IP -q -N -L 8332:localhost:8332`
# This forwards the ports required to talk to the node via RPC (or gRPC in the case of lightning)
@@ -34,8 +37,11 @@ redirect = None
pay_method = "bitcoind"
# Switch payment_method to lnd if you want to use lightning payments instead. And uncomment lnd_dir.
#pay_method = "lnd"
+# lnd_dir is only needed if you want to copy macaroon and TLS cert locally
#lnd_dir = "~/.lnd/"
#lnd_rpcport = "10009"
+#lnd_macaroon = "invoice.macaroon"
+#lnd_cert = "tls.cert"
# DO NOT CHANGE THIS TO TRUE UNLESS YOU WANT ALL PAYMENTS TO AUTOMATICALLY
# BE CONSIDERED AS PAID.
diff --git a/pay/lnd.py b/pay/lnd.py
@@ -17,7 +17,7 @@ class lnd(invoice):
from lndgrpc import LNDClient
- # Copy admin macaroon and tls cert to local machine
+ # Copy invoice macaroon and tls cert to local machine
self.copy_certs()
# Conect to lightning node
@@ -40,8 +40,7 @@ class lnd(invoice):
if test:
print("Getting lnd info...")
- info = self.lnd.get_info()
- print(info)
+ self.lnd.list_invoices()
print("Successfully contacted lnd.")
break
@@ -64,20 +63,22 @@ class lnd(invoice):
# Copy tls and macaroon certs from remote machine.
def copy_certs(self):
- self.certs = {'tls' : 'tls.cert', 'macaroon' : 'admin.macaroon'}
+ self.certs = {'tls' : config.lnd_cert, 'macaroon' : config.lnd_macaroon}
- if (not os.path.isfile("tls.cert")) or (not os.path.isfile("admin.macaroon")):
+ if (not os.path.isfile(config.lnd_cert)) or (not os.path.isfile(config.lnd_macaroon)):
try:
tls_file = os.path.join(config.lnd_dir, "tls.cert")
macaroon_file = os.path.join(
- config.lnd_dir, "data/chain/bitcoin/mainnet/admin.macaroon"
+ config.lnd_dir, "data/chain/bitcoin/mainnet/invoice.macaroon"
)
# SSH copy
if config.tunnel_host is not None:
print(
- "Could not find tls.cert or admin.macaroon in BTCPyment folder. \
- Attempting to download from remote lnd directory."
+ "Could not find {} or {} \
+ Attempting to download from remote lnd directory.".format(
+ config.lnd_cert, config.lnd_macaroon
+ )
)
subprocess.run(
@@ -100,7 +101,7 @@ class lnd(invoice):
print(e)
print("Failed to copy tls and macaroon files to local machine.")
else:
- print("Found tls.cert and admin.macaroon.")
+ print("Found tls.cert and invoice.macaroon.")
return
# Create lightning invoice
diff --git a/server.py b/server.py
@@ -16,10 +16,10 @@ app = Flask(__name__)
# Load an API key or create a new one
if os.path.exists("BTCPyment_API_key"):
- with open("BTCPyment_API_key", "r") as f:
+ with open(config.api_key_path, "r") as f:
app.config["SECRET_KEY"] = f.read().strip()
else:
- with open("BTCPyment_API_key", "w") as f:
+ with open(config.api_key_path, "w") as f:
app.config["SECRET_KEY"] = os.urandom(64).hex()
f.write(app.config["SECRET_KEY"])