mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21:35 +00:00
Refactor expiry_height into follow_invoices
This commit is contained in:
parent
70b6d88321
commit
b0ffe150c0
@ -265,6 +265,7 @@ class LNNode:
|
||||
from api.models import LNPayment
|
||||
|
||||
status = lnpayment.status
|
||||
expiry_height = 0
|
||||
|
||||
lnd_response_state_to_lnpayment_status = {
|
||||
0: LNPayment.Status.INVGEN, # OPEN
|
||||
@ -280,15 +281,16 @@ class LNNode:
|
||||
)
|
||||
response = cls.invoicesstub.LookupInvoiceV2(request)
|
||||
|
||||
# try saving expiry height
|
||||
status = lnd_response_state_to_lnpayment_status[response.state]
|
||||
|
||||
# get expiry height
|
||||
if hasattr(response, "htlcs"):
|
||||
try:
|
||||
lnpayment.expiry_height = response.htlcs[0].expiry_height
|
||||
for htlc in response.htlcs:
|
||||
expiry_height = max(expiry_height, htlc.expiry_height)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
status = lnd_response_state_to_lnpayment_status[response.state]
|
||||
|
||||
except Exception as e:
|
||||
# If it fails at finding the invoice: it has been canceled.
|
||||
# In RoboSats DB we make a distinction between cancelled and returned (LND does not)
|
||||
@ -304,7 +306,7 @@ class LNNode:
|
||||
else:
|
||||
print(str(e))
|
||||
|
||||
return status
|
||||
return status, expiry_height
|
||||
|
||||
@classmethod
|
||||
def resetmc(cls):
|
||||
|
@ -77,7 +77,7 @@ class Command(BaseCommand):
|
||||
for idx, hold_lnpayment in enumerate(queryset):
|
||||
old_status = hold_lnpayment.status
|
||||
|
||||
new_status = LNNode.lookup_invoice_status(hold_lnpayment)
|
||||
new_status, expiry_height = LNNode.lookup_invoice_status(hold_lnpayment)
|
||||
|
||||
# Only save the hold_payments that change (otherwise this function does not scale)
|
||||
changed = not old_status == new_status
|
||||
@ -94,8 +94,9 @@ class Command(BaseCommand):
|
||||
|
||||
# if these are still different, we update the lnpayment with its new status.
|
||||
lnpayment.status = new_status
|
||||
lnpayment.expiry_height = expiry_height
|
||||
self.update_order_status(lnpayment)
|
||||
lnpayment.save(update_fields=["status"])
|
||||
lnpayment.save(update_fields=["status", "expiry_height"])
|
||||
|
||||
# Report for debugging
|
||||
old = LNPayment.Status(old_status).label
|
||||
|
Loading…
Reference in New Issue
Block a user