mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-13 10:56:24 +00:00
background process debugging
This commit is contained in:
parent
300a385589
commit
4eaad57475
@ -33,7 +33,7 @@ class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||
@admin.register(LNPayment)
|
||||
class LNPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||
list_display = ('hash','concept','status','num_satoshis','type','expires_at','sender_link','receiver_link','order_made','order_taken','order_escrow','order_paid')
|
||||
list_display_links = ('hash','concept','order_made','order_taken','order_escrow','order_paid')
|
||||
list_display_links = ('hash','concept')
|
||||
change_links = ('sender','receiver')
|
||||
list_filter = ('type','concept','status')
|
||||
|
||||
|
@ -220,7 +220,7 @@ class Logics():
|
||||
@classmethod
|
||||
def open_dispute(cls, order, user=None):
|
||||
|
||||
# Always settle the escrow during a dispute (same as with 'Fiat Sent')
|
||||
# Always settle the escrow during a dispute
|
||||
# Dispute winner will have to submit a new invoice.
|
||||
|
||||
if not order.trade_escrow.status == LNPayment.Status.SETLED:
|
||||
@ -235,7 +235,10 @@ class Logics():
|
||||
if not user == None:
|
||||
profile = user.profile
|
||||
profile.num_disputes = profile.num_disputes + 1
|
||||
profile.orders_disputes_started = list(profile.orders_disputes_started).append(str(order.id))
|
||||
if profile.orders_disputes_started == None:
|
||||
profile.orders_disputes_started = [str(order.id)]
|
||||
else:
|
||||
profile.orders_disputes_started = list(profile.orders_disputes_started).append(str(order.id))
|
||||
profile.save()
|
||||
|
||||
return True, None
|
||||
@ -325,7 +328,7 @@ class Logics():
|
||||
''' adds a new rating to a user profile'''
|
||||
|
||||
# TODO Unsafe, does not update ratings, it adds more ratings everytime a new rating is clicked.
|
||||
profile.total_ratings = profile.total_ratings + 1
|
||||
profile.total_ratings += 1
|
||||
latest_ratings = profile.latest_ratings
|
||||
if latest_ratings == None:
|
||||
profile.latest_ratings = [rating]
|
||||
@ -633,6 +636,7 @@ class Logics():
|
||||
'''returns the trade escrow'''
|
||||
if LNNode.cancel_return_hold_invoice(order.trade_escrow.payment_hash):
|
||||
order.trade_escrow.status = LNPayment.Status.RETNED
|
||||
order.trade_escrow.save()
|
||||
return True
|
||||
|
||||
def cancel_escrow(order):
|
||||
@ -640,6 +644,7 @@ class Logics():
|
||||
# Same as return escrow, but used when the invoice was never LOCKED
|
||||
if LNNode.cancel_return_hold_invoice(order.trade_escrow.payment_hash):
|
||||
order.trade_escrow.status = LNPayment.Status.CANCEL
|
||||
order.trade_escrow.save()
|
||||
return True
|
||||
|
||||
def return_bond(bond):
|
||||
@ -649,10 +654,12 @@ class Logics():
|
||||
try:
|
||||
LNNode.cancel_return_hold_invoice(bond.payment_hash)
|
||||
bond.status = LNPayment.Status.RETNED
|
||||
bond.save()
|
||||
return True
|
||||
except Exception as e:
|
||||
if 'invoice already settled' in str(e):
|
||||
bond.status = LNPayment.Status.SETLED
|
||||
bond.save()
|
||||
return True
|
||||
else:
|
||||
raise e
|
||||
@ -665,10 +672,12 @@ class Logics():
|
||||
try:
|
||||
LNNode.cancel_return_hold_invoice(bond.payment_hash)
|
||||
bond.status = LNPayment.Status.CANCEL
|
||||
bond.save()
|
||||
return True
|
||||
except Exception as e:
|
||||
if 'invoice already settled' in str(e):
|
||||
bond.status = LNPayment.Status.SETLED
|
||||
bond.save()
|
||||
return True
|
||||
else:
|
||||
raise e
|
||||
@ -705,11 +714,11 @@ class Logics():
|
||||
order.status = Order.Status.SUC
|
||||
order.buyer_invoice.status = LNPayment.Status.SUCCED
|
||||
order.expires_at = timezone.now() + timedelta(seconds=Order.t_to_expire[Order.Status.SUC])
|
||||
order.save()
|
||||
|
||||
# RETURN THE BONDS
|
||||
cls.return_bond(order.taker_bond)
|
||||
cls.return_bond(order.maker_bond)
|
||||
order.save()
|
||||
|
||||
return True, context
|
||||
else:
|
||||
# error handling here
|
||||
|
@ -40,11 +40,13 @@ class Command(BaseCommand):
|
||||
if Logics.order_expires(order): # Order send to expire here
|
||||
debug['expired_orders'].append({idx:context})
|
||||
|
||||
# If it cannot locate the hold invoice, make it expire anywway
|
||||
# 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:
|
||||
if 'unable to locate invoice' in str(e):
|
||||
self.stdout.write(str(e))
|
||||
order.status = Order.Status.EXP
|
||||
order.save()
|
||||
debug['expired_orders'].append({idx:context})
|
||||
|
||||
|
||||
|
@ -57,7 +57,6 @@ class LNPayment(models.Model):
|
||||
FLIGHT = 7, 'In flight'
|
||||
SUCCED = 8, 'Succeeded'
|
||||
FAILRO = 9, 'Routing failed'
|
||||
|
||||
|
||||
# payment use details
|
||||
type = models.PositiveSmallIntegerField(choices=Types.choices, null=False, default=Types.HOLD)
|
||||
@ -141,7 +140,7 @@ class Order(models.Model):
|
||||
last_satoshis = models.PositiveBigIntegerField(null=True, validators=[MinValueValidator(0), MaxValueValidator(MAX_TRADE*2)], blank=True) # sats last time checked. Weird if 2* trade max...
|
||||
|
||||
# order participants
|
||||
maker = models.ForeignKey(User, related_name='maker', on_delete=models.CASCADE, null=True, default=None) # unique = True, a maker can only make one order
|
||||
maker = models.ForeignKey(User, related_name='maker', on_delete=models.SET_NULL, null=True, default=None) # unique = True, a maker can only make one order
|
||||
taker = models.ForeignKey(User, related_name='taker', on_delete=models.SET_NULL, null=True, default=None, blank=True) # unique = True, a taker can only take one order
|
||||
is_pending_cancel = models.BooleanField(default=False, null=False) # When collaborative cancel is needed and one partner has cancelled.
|
||||
is_fiat_sent = models.BooleanField(default=False, null=False)
|
||||
|
2
clean_orders
Normal file
2
clean_orders
Normal file
@ -0,0 +1,2 @@
|
||||
2022-01-20 12:59:13.516882+00:00
|
||||
{'num_expired_orders': 1, 'expired_orders': [{0: 'Order 56: SELL BTC for 40.0 USD was Public'}]}
|
Loading…
Reference in New Issue
Block a user