commit 4ecb584a55b7c8da08328e208ed7a8c6c19825ff
parent a567c0252bd55a6b73f2f4e66f06ac2e987adeab
Author: NicholasFarrow <nicholas.w.farrow@gmail.com>
Date: Fri, 22 Jan 2021 20:03:34 +1100
Successful lightning payment acceptance. Also ssh tunnel error verbosity
Diffstat:
2 files changed, 6 insertions(+), 34 deletions(-)
diff --git a/pay/lnd.py b/pay/lnd.py
@@ -68,51 +68,22 @@ class lnd(invoice):
return self.lnd_invoice['payment_request']
- # self.lnd_invoice = json.loads(MessageToJson(self.lnd.add_invoice(sats_amount)))
- # print(self.lnd_invoice)
- # print("printed")
- #
- # self.hash = str(b64decode(self.lnd_invoice['r_hash']).hex())
- # # self.hash = str(b64decode(self.lnd_invoice['rHash']).hex())
- #
- # print("Created invoice: {}".format(self.hash))
- # return self.lnd_invoice['payment_request']
- # return self.lnd_invoice['paymentRequest']
-
def get_address(self):
self.address = self.create_lnd_invoice(self.value)
-
- # for i in range(config.connection_attempts):
- # try:
- # self.address = self.create_lnd_invoice(self.value)
- # except Exception as e:
- # print(e)
- # print("Attempting again... {}/{}...".format(i+1, config.connection_attempts))
-
return
def check_payment(self):
print("Looking up invoice")
- # For some reason this does not work, I think lookup_invoice() may be broken
- # as it does not return the correct response that includes the amount paid among other fields.
invoice_status = json.loads(MessageToJson(self.lnd.lookup_invoice(r_hash_str=b64decode(self.hash).hex())))
- print(invoice_status)
- if 'amt_paid' not in invoice_status.items():
+ if 'amt_paid_sat' not in invoice_status.keys():
conf_paid = 0
unconf_paid = 0
else:
- print("WEEEEEEEEEEEEEEEEEEEE")
-
- #print(self.lnd.lookup_invoice(r_hash=self.hash))
- print("Invoice ^")
-
- # print(str(b64decode(self.hash.strip('\\'))))
- # invoice_status = json.loads(MessageToJson(self.lnd.lookup_invoice(self.hash)))
- # print(invoice_status)
- # print(self.lnd.lookup_invoice("8893044a07c2c5e2a50252f044224f297487242e05758a970d5ba28ece75f66d"))
- # subprocess.run([""])
+ # Store amount paid and convert to BTC units
+ conf_paid = int(invoice_status['amt_paid_sat']) * 10**8
+ unconf_paid = 0
return conf_paid, unconf_paid
diff --git a/ssh_tunnel.py b/ssh_tunnel.py
@@ -14,7 +14,8 @@ try:
tunnel_proc = subprocess.Popen(command)
else:
tunnel_proc = None
-except Exception:
+except Exception as e:
+ print("FAILED TO OPEN TUNNEL. Exception: {}".format(e))
tunnel_proc = None
pass