Fix clean-orders failure when trade_escrow has not been generated

This commit is contained in:
Reckless_Satoshi 2022-02-20 06:38:29 -08:00
parent 0b7542bf68
commit 9025b2e07d
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
2 changed files with 13 additions and 2 deletions

View File

@ -234,7 +234,10 @@ class Logics:
if maker_is_seller:
cls.settle_bond(order.maker_bond)
cls.return_bond(order.taker_bond)
cls.cancel_escrow(order)
try: # If seller is offline the escrow LNpayment does not even exist
cls.cancel_escrow(order)
except:
pass
order.status = Order.Status.EXP
order.save()
return True
@ -242,7 +245,10 @@ class Logics:
# If maker is buyer, settle the taker's bond order goes back to public
else:
cls.settle_bond(order.taker_bond)
cls.cancel_escrow(order)
try: # If seller is offline the escrow LNpayment does not even exist
cls.cancel_escrow(order)
except:
pass
order.taker = None
order.taker_bond = None
order.trade_escrow = None

View File

@ -43,6 +43,8 @@ class Command(BaseCommand):
debug = {}
debug["num_expired_orders"] = len(queryset)
debug["expired_orders"] = []
debug["failed_order_expiry"] = []
debug["reason_failure"] = []
for idx, order in enumerate(queryset):
context = str(order) + " was " + Order.Status(
@ -55,6 +57,9 @@ class Command(BaseCommand):
# It should not happen, but if it cannot locate the hold invoice
# it probably was cancelled by another thread, make it expire anyway.
except Exception as e:
debug["failed_order_expiry"].append({idx: context})
debug["reason_failure"].append({idx: str(e)})
if "unable to locate invoice" in str(e):
self.stdout.write(str(e))
order.status = Order.Status.EXP