From 715d7ebf6d3efb086ec85e226333236b10576871 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Tue, 8 Feb 2022 02:05:22 -0800 Subject: [PATCH] Handle LND down response to clients --- api/logics.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/api/logics.py b/api/logics.py index c71f0c5d..3069c299 100644 --- a/api/logics.py +++ b/api/logics.py @@ -532,10 +532,14 @@ class Logics(): description = f"RoboSats - Publishing '{str(order)}' - Maker bond - This payment WILL FREEZE IN YOUR WALLET, check on the website if it was successful. It will automatically return unless you cheat or cancel unilaterally." # Gen hold Invoice - hold_payment = LNNode.gen_hold_invoice(bond_satoshis, - description, - invoice_expiry=Order.t_to_expire[Order.Status.WFB], - cltv_expiry_secs=BOND_EXPIRY*3600) + try: + hold_payment = LNNode.gen_hold_invoice(bond_satoshis, + description, + invoice_expiry=Order.t_to_expire[Order.Status.WFB], + cltv_expiry_secs=BOND_EXPIRY*3600) + except Exception as e: + if 'status = StatusCode.UNAVAILABLE' in str(e): + return False, {'bad_request':'The Lightning Network Daemon (LND) is down. Write in the Telegram group to make sure staff is aware.'} order.maker_bond = LNPayment.objects.create( concept = LNPayment.Concepts.MAKEBOND, @@ -613,10 +617,15 @@ class Logics(): + " - Taker bond - This payment WILL FREEZE IN YOUR WALLET, check on the website if it was successful. It will automatically return unless you cheat or cancel unilaterally.") # Gen hold Invoice - hold_payment = LNNode.gen_hold_invoice(bond_satoshis, - description, - invoice_expiry=Order.t_to_expire[Order.Status.TAK], - cltv_expiry_secs=BOND_EXPIRY*3600) + try: + hold_payment = LNNode.gen_hold_invoice(bond_satoshis, + description, + invoice_expiry=Order.t_to_expire[Order.Status.TAK], + cltv_expiry_secs=BOND_EXPIRY*3600) + + except Exception as e: + if 'status = StatusCode.UNAVAILABLE' in str(e): + return False, {'bad_request':'The Lightning Network Daemon (LND) is down. Write in the Telegram group to make sure staff is aware.'} order.taker_bond = LNPayment.objects.create( concept = LNPayment.Concepts.TAKEBOND, @@ -678,11 +687,17 @@ class Logics(): description = f"RoboSats - Escrow amount for '{str(order)}' - It WILL FREEZE IN YOUR WALLET. It will be released to the buyer once you confirm you received the fiat. It will automatically return if buyer does not confirm the payment." # Gen hold Invoice - hold_payment = LNNode.gen_hold_invoice(escrow_satoshis, - description, - invoice_expiry=Order.t_to_expire[Order.Status.WF2], - cltv_expiry_secs=ESCROW_EXPIRY*3600) + try: + hold_payment = LNNode.gen_hold_invoice(escrow_satoshis, + description, + invoice_expiry=Order.t_to_expire[Order.Status.WF2], + cltv_expiry_secs=ESCROW_EXPIRY*3600) + except Exception as e: + if 'status = StatusCode.UNAVAILABLE' in str(e): + return False, {'bad_request':'The Lightning Network Daemon (LND). Write in the Telegram group to make sure staff is aware.'} + + order.trade_escrow = LNPayment.objects.create( concept = LNPayment.Concepts.TRESCROW, type = LNPayment.Types.HOLD,