mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21:35 +00:00
Make payment_hash the primary key of LNpayment model
This commit is contained in:
parent
ad6ee9d4de
commit
5e0639cfb3
@ -22,6 +22,7 @@ class EUserAdmin(UserAdmin):
|
||||
def avatar_tag(self, obj):
|
||||
return obj.profile.avatar_tag()
|
||||
|
||||
|
||||
@admin.register(Order)
|
||||
class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||
list_display = ('id','type','maker_link','taker_link','status','amount','currency_link','t0_satoshis','is_disputed','is_fiat_sent','created_at','expires_at', 'buyer_invoice_link','maker_bond_link','taker_bond_link','trade_escrow_link')
|
||||
@ -31,8 +32,8 @@ class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||
|
||||
@admin.register(LNPayment)
|
||||
class LNPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||
list_display = ('id','concept','status','num_satoshis','type','expires_at','sender_link','receiver_link','order_made','order_taken','order_escrow','order_paid')
|
||||
list_display_links = ('id','concept','order_made','order_taken','order_escrow','order_paid')
|
||||
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')
|
||||
change_links = ('sender','receiver')
|
||||
list_filter = ('type','concept','status')
|
||||
|
||||
|
@ -97,23 +97,31 @@ class Command(BaseCommand):
|
||||
def update_order_status(self, lnpayment):
|
||||
''' Background process following LND hold invoices
|
||||
can catch LNpayments changing status. If they do,
|
||||
the order status might have to change status too.'''
|
||||
the order status might have to change too.'''
|
||||
|
||||
# If the LNPayment goes to LOCKED (ACCEPTED)
|
||||
if lnpayment.status == LNPayment.Status.LOCKED:
|
||||
|
||||
# It is a maker bond => Publish order.
|
||||
if not lnpayment.order_made == None:
|
||||
Logics.publish_order(lnpayment.order_made)
|
||||
return
|
||||
|
||||
# It is a taker bond => close contract.
|
||||
elif not lnpayment.order_taken == None:
|
||||
if lnpayment.order_taken.status == Order.Status.TAK:
|
||||
Logics.finalize_contract(lnpayment.order_taken)
|
||||
try:
|
||||
# It is a maker bond => Publish order.
|
||||
if not lnpayment.order_made == None:
|
||||
Logics.publish_order(lnpayment.order_made)
|
||||
return
|
||||
|
||||
# It is a trade escrow => move foward order status.
|
||||
elif not lnpayment.order_escrow == None:
|
||||
Logics.trade_escrow_received(lnpayment.order_escrow)
|
||||
return
|
||||
# It is a taker bond => close contract.
|
||||
elif not lnpayment.order_taken == None:
|
||||
if lnpayment.order_taken.status == Order.Status.TAK:
|
||||
Logics.finalize_contract(lnpayment.order_taken)
|
||||
return
|
||||
|
||||
# It is a trade escrow => move foward order status.
|
||||
elif not lnpayment.order_escrow == None:
|
||||
Logics.trade_escrow_received(lnpayment.order_escrow)
|
||||
return
|
||||
except Exception as e:
|
||||
self.stdout.write(str(e))
|
||||
|
||||
# TODO If an lnpayment goes from LOCKED to INVGED. Totally weird
|
||||
# halt the order
|
||||
if lnpayment.status == LNPayment.Status.LOCKED:
|
||||
pass
|
@ -2,6 +2,7 @@ from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator, validate_comma_separated_integer_list
|
||||
from django.db.models.signals import post_save, pre_delete
|
||||
from django.template.defaultfilters import truncatechars
|
||||
from django.dispatch import receiver
|
||||
from django.utils.html import mark_safe
|
||||
import uuid
|
||||
@ -59,15 +60,14 @@ class LNPayment(models.Model):
|
||||
|
||||
|
||||
# payment use details
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
type = models.PositiveSmallIntegerField(choices=Types.choices, null=False, default=Types.HOLD)
|
||||
concept = models.PositiveSmallIntegerField(choices=Concepts.choices, null=False, default=Concepts.MAKEBOND)
|
||||
status = models.PositiveSmallIntegerField(choices=Status.choices, null=False, default=Status.INVGEN)
|
||||
routing_retries = models.PositiveSmallIntegerField(null=False, default=0)
|
||||
|
||||
# payment info
|
||||
payment_hash = models.CharField(max_length=100, unique=True, default=None, blank=True, primary_key=True)
|
||||
invoice = models.CharField(max_length=1200, unique=True, null=True, default=None, blank=True) # Some invoices with lots of routing hints might be long
|
||||
payment_hash = models.CharField(max_length=100, unique=True, null=True, default=None, blank=True)
|
||||
preimage = models.CharField(max_length=64, unique=True, null=True, default=None, blank=True)
|
||||
description = models.CharField(max_length=500, unique=False, null=True, default=None, blank=True)
|
||||
num_satoshis = models.PositiveBigIntegerField(validators=[MinValueValidator(MIN_TRADE*BOND_SIZE), MaxValueValidator(MAX_TRADE*(1+BOND_SIZE+FEE))])
|
||||
@ -79,12 +79,19 @@ class LNPayment(models.Model):
|
||||
receiver = models.ForeignKey(User, related_name='receiver', on_delete=models.CASCADE, null=True, default=None)
|
||||
|
||||
def __str__(self):
|
||||
return (f'LN-{str(self.id)[:8]}: {self.Concepts(self.concept).label} - {self.Status(self.status).label}')
|
||||
return (f'LN-{str(self.payment_hash)[:8]}: {self.Concepts(self.concept).label} - {self.Status(self.status).label}')
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Lightning payment'
|
||||
verbose_name_plural = 'Lightning payments'
|
||||
|
||||
@property
|
||||
def hash(self):
|
||||
# Payment hash is the primary key of LNpayments
|
||||
# However it is too long for the admin panel.
|
||||
# We created a truncated property for display 'hash'
|
||||
return truncatechars(self.payment_hash, 10)
|
||||
|
||||
class Order(models.Model):
|
||||
|
||||
class Types(models.IntegerChoices):
|
||||
@ -141,8 +148,8 @@ class Order(models.Model):
|
||||
|
||||
# in dispute
|
||||
is_disputed = models.BooleanField(default=False, null=False)
|
||||
maker_statement = models.TextField(max_length=5000, unique=True, null=True, default=None, blank=True)
|
||||
taker_statement = models.TextField(max_length=5000, unique=True, null=True, default=None, blank=True)
|
||||
maker_statement = models.TextField(max_length=5000, null=True, default=None, blank=True)
|
||||
taker_statement = models.TextField(max_length=5000, null=True, default=None, blank=True)
|
||||
|
||||
# LNpayments
|
||||
# Order collateral
|
||||
|
Loading…
Reference in New Issue
Block a user