commit d282faea09e0decbe590cf5e5246cb88a2a5738e
parent 2c32f39d0b75535bbc8016e2c2238fc2b7e64dbe
Author: NicholasFarrow <nicholas.w.farrow@gmail.com>
Date: Wed, 27 Jan 2021 23:14:43 +1100
Formatting and deletion with flake8
Diffstat:
5 files changed, 39 insertions(+), 33 deletions(-)
diff --git a/config.py b/config.py
@@ -1,5 +1,5 @@
# Bitcoin node connection settings
-# This should point to your bitcoin/lnd node,
+# This should point to your bitcoin/lnd node,
# with the correct RPC port as set in your config.
# Connecting through local host as i'm running BTCPyment on the node
host = "127.0.0.1"
@@ -13,7 +13,7 @@ password = "RPAPASSWORD"
# 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)
# Use host = "127.0.0.1" and you will be able to see your node on 8332
-tunnel_host = None #"HOST@IP"
+tunnel_host = None # "HOST@IP"
# Check for payment every xx seconds
pollrate = 15
diff --git a/pay/bitcoind.py b/pay/bitcoind.py
@@ -1,6 +1,4 @@
import time
-import subprocess
-import time
import config
from invoice.payment_invoice import invoice
@@ -36,7 +34,8 @@ class btcd(invoice):
)
else:
raise Exception(
- "Could not connect to bitcoind. Check your RPC / port tunneling settings and try again."
+ "Could not connect to bitcoind. \
+ Check your RPC / port tunneling settings and try again."
)
def check_payment(self):
diff --git a/pay/lnd.py b/pay/lnd.py
@@ -17,31 +17,7 @@ class lnd(invoice):
from lndgrpc import LNDClient
# Copy admin macaroon and tls cert to local machine
- if (not os.path.isfile("tls.cert")) or (not os.path.isfile("admin.macaroon")):
- print(
- "Could not find tls.cert or admin.macaroon in BTCPyment folder. Attempting to download from lnd directory."
- )
- 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"
- )
- subprocess.run(
- ["scp", "{}:{}".format(config.tunnel_host, tls_file), "."]
- )
- subprocess.run(
- [
- "scp",
- "-r",
- "{}:{}".format(config.tunnel_host, macaroon_file),
- ".",
- ]
- )
- except Exception as e:
- print(e)
- print("Failed to copy tls and macaroon files to local machine.")
- else:
- print("Found tls.cert and admin.macaroon.")
+ self.copy_certs()
# Conect to lightning node
connection_str = "{}:{}".format(config.host, config.rpcport)
@@ -81,6 +57,37 @@ class lnd(invoice):
)
print("Ready for payments requests.")
+ return
+
+ # Copy tls and macaroon certs from remote machine.
+ def copy_certs():
+ if (not os.path.isfile("tls.cert")) or (not os.path.isfile("admin.macaroon")):
+ print(
+ "Could not find tls.cert or admin.macaroon in BTCPyment folder. \
+ Attempting to download from lnd directory."
+ )
+ 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"
+ )
+ subprocess.run(
+ ["scp", "{}:{}".format(config.tunnel_host, tls_file), "."]
+ )
+ subprocess.run(
+ [
+ "scp",
+ "-r",
+ "{}:{}".format(config.tunnel_host, macaroon_file),
+ ".",
+ ]
+ )
+ except Exception as e:
+ print(e)
+ print("Failed to copy tls and macaroon files to local machine.")
+ else:
+ print("Found tls.cert and admin.macaroon.")
+ return
# Create lightning invoice
def create_lnd_invoice(self, btc_amount):
diff --git a/server.py b/server.py
@@ -28,6 +28,7 @@ print("Initialised Flask with secret key: {}".format(app.config["SECRET_KEY"]))
# cors_allowed_origins * allows for webhooks to be initiated from iframes.
socket_ = SocketIO(app, async_mode=async_mode, cors_allowed_origins="*")
+
# Basic return on initialisation
@socket_.on("initialise")
def test_message(message):
@@ -65,7 +66,7 @@ def make_payment(payload):
amount = payload["amount"]
try:
amount = float(amount)
- except:
+ except Exception as e:
update_status(payment, "Invalid amount.")
amount = None
return
@@ -193,7 +194,7 @@ def process_payment(payment):
# Continue waiting for transaction...
else:
- update_status(payment, "Waiting for payment...".format(payment.value))
+ update_status(payment, "Waiting for payment...")
socket_.sleep(config.pollrate)
else:
update_status(payment, "Payment expired.")
diff --git a/ssh_tunnel.py b/ssh_tunnel.py
@@ -2,7 +2,6 @@ import config
import invoice
from pay import bitcoind
-import time
import subprocess