mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21:35 +00:00
Add async background catches expiry height
This commit is contained in:
parent
5a677067f7
commit
d2dbc0d249
@ -9,6 +9,7 @@ from base64 import b64decode
|
||||
from datetime import timedelta, datetime
|
||||
from django.utils import timezone
|
||||
|
||||
from api.models import LNPayment
|
||||
#######
|
||||
# Should work with LND (c-lightning in the future if there are features that deserve the work)
|
||||
#######
|
||||
@ -117,6 +118,7 @@ class LNNode():
|
||||
if response.state == 3: # ACCEPTED (LOCKED)
|
||||
print('STATUS: ACCEPTED')
|
||||
lnpayment.expiry_height = response.htlcs[0].expiry_height
|
||||
lnpayment.status = LNPayment.Status.LOCKED
|
||||
lnpayment.save()
|
||||
return True
|
||||
|
||||
|
@ -479,8 +479,6 @@ class Logics():
|
||||
if order.maker_bond.status == LNPayment.Status.LOCKED:
|
||||
return True
|
||||
elif LNNode.validate_hold_invoice_locked(order.maker_bond):
|
||||
order.maker_bond.status = LNPayment.Status.LOCKED
|
||||
order.maker_bond.save()
|
||||
cls.publish_order(order)
|
||||
return True
|
||||
return False
|
||||
@ -628,8 +626,6 @@ class Logics():
|
||||
if order.trade_escrow.status == LNPayment.Status.LOCKED:
|
||||
return True
|
||||
elif LNNode.validate_hold_invoice_locked(order.trade_escrow):
|
||||
order.trade_escrow.status = LNPayment.Status.LOCKED
|
||||
order.trade_escrow.save()
|
||||
cls.trade_escrow_received(order)
|
||||
return True
|
||||
return False
|
||||
|
@ -65,12 +65,18 @@ class Command(BaseCommand):
|
||||
|
||||
for idx, hold_lnpayment in enumerate(queryset):
|
||||
old_status = LNPayment.Status(hold_lnpayment.status).label
|
||||
|
||||
try:
|
||||
try:
|
||||
# this is similar to LNNnode.validate_hold_invoice_locked
|
||||
request = LNNode.invoicesrpc.LookupInvoiceMsg(payment_hash=bytes.fromhex(hold_lnpayment.payment_hash))
|
||||
response = stub.LookupInvoiceV2(request, metadata=[('macaroon', MACAROON.hex())])
|
||||
hold_lnpayment.status = lnd_state_to_lnpayment_status[response.state]
|
||||
hold_lnpayment.expiry_height = response.htlcs[0].expiry_height
|
||||
|
||||
# try saving expiry height
|
||||
if hasattr(response, 'htlcs' ):
|
||||
try:
|
||||
hold_lnpayment.expiry_height = response.htlcs[0].expiry_height
|
||||
except:
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
# If it fails at finding the invoice: it has been canceled.
|
||||
@ -78,9 +84,10 @@ class Command(BaseCommand):
|
||||
if 'unable to locate invoice' in str(e):
|
||||
self.stdout.write(str(e))
|
||||
hold_lnpayment.status = LNPayment.Status.CANCEL
|
||||
|
||||
# LND restarted.
|
||||
if 'wallet locked, unlock it' in str(e):
|
||||
self.stdout.write(str(timezone.now())+':: Wallet Locked')
|
||||
self.stdout.write(str(timezone.now())+' :: Wallet Locked')
|
||||
# Other write to logs
|
||||
else:
|
||||
self.stdout.write(str(e))
|
||||
|
Loading…
Reference in New Issue
Block a user