mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-29 15:23:34 +03:00
Bug fix, order status now as message, HTLCs relationals working
This commit is contained in:
parent
7d4cd868b0
commit
bd1601d59f
@ -46,15 +46,18 @@ class LNPayment(models.Model):
|
||||
status = models.PositiveSmallIntegerField(choices=Status.choices, null=False, default=Status.INVGEN)
|
||||
|
||||
# payment details
|
||||
invoice = models.CharField(max_length=300, unique=False, null=True, default=None)
|
||||
secret = models.CharField(max_length=300, unique=False, null=True, default=None)
|
||||
invoice = models.CharField(max_length=300, unique=False, null=True, default=None, blank=True)
|
||||
secret = models.CharField(max_length=300, unique=False, null=True, default=None, blank=True)
|
||||
expires_at = models.DateTimeField()
|
||||
amount = models.DecimalField(max_digits=9, decimal_places=4, validators=[MinValueValidator(MIN_TRADE*BOND_SIZE), MaxValueValidator(MAX_TRADE*(1+BOND_SIZE+FEE))])
|
||||
amount = models.PositiveBigIntegerField(validators=[MinValueValidator(MIN_TRADE*BOND_SIZE), MaxValueValidator(MAX_TRADE*(1+BOND_SIZE+FEE))])
|
||||
|
||||
# payment relationals
|
||||
sender = models.ForeignKey(User, related_name='sender', on_delete=models.CASCADE, null=True, default=None)
|
||||
receiver = models.ForeignKey(User, related_name='receiver', on_delete=models.CASCADE, null=True, default=None)
|
||||
|
||||
def __str__(self):
|
||||
# Make relational back to ORDER
|
||||
return (f'HTLC {self.id}: {self.Concepts(self.concept).label}')
|
||||
|
||||
class Order(models.Model):
|
||||
|
||||
@ -97,28 +100,28 @@ class Order(models.Model):
|
||||
# order details
|
||||
type = models.PositiveSmallIntegerField(choices=Types.choices, null=False)
|
||||
currency = models.PositiveSmallIntegerField(choices=Currencies.choices, null=False)
|
||||
amount = models.DecimalField(max_digits=9, decimal_places=4, validators=[MinValueValidator(MIN_TRADE), MaxValueValidator(MAX_TRADE)])
|
||||
payment_method = models.CharField(max_length=30, null=False, default="Not specified")
|
||||
amount = models.DecimalField(max_digits=9, decimal_places=4, validators=[MinValueValidator(0.00001)])
|
||||
payment_method = models.CharField(max_length=30, null=False, default="not specified", blank=True)
|
||||
|
||||
# order pricing method. A explicit amount of sats, or a relative premium above/below market.
|
||||
is_explicit = models.BooleanField(default=False, null=False)
|
||||
# marked to marked
|
||||
premium = models.DecimalField(max_digits=5, decimal_places=2, default=0, null=True, validators=[MinValueValidator(-100), MaxValueValidator(999)])
|
||||
t0_market_satoshis = models.PositiveBigIntegerField(null=True, validators=[MinValueValidator(MIN_TRADE), MaxValueValidator(MAX_TRADE)])
|
||||
premium = models.DecimalField(max_digits=5, decimal_places=2, default=0, null=True, validators=[MinValueValidator(-100), MaxValueValidator(999)], blank=True)
|
||||
t0_market_satoshis = models.PositiveBigIntegerField(null=True, validators=[MinValueValidator(MIN_TRADE), MaxValueValidator(MAX_TRADE)], blank=True)
|
||||
# explicit
|
||||
satoshis = models.PositiveBigIntegerField(null=True, validators=[MinValueValidator(MIN_TRADE), MaxValueValidator(MAX_TRADE)])
|
||||
satoshis = models.PositiveBigIntegerField(null=True, validators=[MinValueValidator(MIN_TRADE), MaxValueValidator(MAX_TRADE)], blank=True)
|
||||
|
||||
# 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
|
||||
taker = models.ForeignKey(User, related_name='taker', on_delete=models.SET_NULL, null=True, default=None) # unique = True, a taker can only take 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
|
||||
|
||||
# order collateral
|
||||
maker_bond = models.ForeignKey(LNPayment, related_name='maker_bond', on_delete=models.SET_NULL, null=True, default=None)
|
||||
taker_bond = models.ForeignKey(LNPayment, related_name='taker_bond', on_delete=models.SET_NULL, null=True, default=None)
|
||||
trade_escrow = models.ForeignKey(LNPayment, related_name='trade_escrow', on_delete=models.SET_NULL, null=True, default=None)
|
||||
maker_bond = models.ForeignKey(LNPayment, related_name='maker_bond', on_delete=models.SET_NULL, null=True, default=None, blank=True)
|
||||
taker_bond = models.ForeignKey(LNPayment, related_name='taker_bond', on_delete=models.SET_NULL, null=True, default=None, blank=True)
|
||||
trade_escrow = models.ForeignKey(LNPayment, related_name='trade_escrow', on_delete=models.SET_NULL, null=True, default=None, blank=True)
|
||||
|
||||
# buyer payment LN invoice
|
||||
buyer_invoice = models.ForeignKey(LNPayment, related_name='buyer_invoice', on_delete=models.SET_NULL, null=True, default=None)
|
||||
buyer_invoice = models.ForeignKey(LNPayment, related_name='buyer_invoice', on_delete=models.SET_NULL, null=True, default=None, blank=True)
|
||||
|
||||
|
||||
class Profile(models.Model):
|
||||
@ -127,15 +130,15 @@ class Profile(models.Model):
|
||||
|
||||
# Ratings stored as a comma separated integer list
|
||||
total_ratings = models.PositiveIntegerField(null=False, default=0)
|
||||
latest_ratings = models.CharField(max_length=999, null=True, default=None, validators=[validate_comma_separated_integer_list]) # Will only store latest ratings
|
||||
avg_rating = models.DecimalField(max_digits=4, decimal_places=1, default=None, null=True, validators=[MinValueValidator(0), MaxValueValidator(100)])
|
||||
latest_ratings = models.CharField(max_length=999, null=True, default=None, validators=[validate_comma_separated_integer_list], blank=True) # Will only store latest ratings
|
||||
avg_rating = models.DecimalField(max_digits=4, decimal_places=1, default=None, null=True, validators=[MinValueValidator(0), MaxValueValidator(100)], blank=True)
|
||||
|
||||
# Disputes
|
||||
num_disputes = models.PositiveIntegerField(null=False, default=0)
|
||||
lost_disputes = models.PositiveIntegerField(null=False, default=0)
|
||||
|
||||
# RoboHash
|
||||
avatar = models.ImageField(default="static/assets/misc/unknown_avatar.png", verbose_name='Avatar')
|
||||
avatar = models.ImageField(default="static/assets/misc/unknown_avatar.png", verbose_name='Avatar', blank=True)
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
def create_user_profile(sender, instance, created, **kwargs):
|
||||
|
@ -14,4 +14,4 @@ class MakeOrderSerializer(serializers.ModelSerializer):
|
||||
class UpdateOrderSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Order
|
||||
fields = ('id','invoice')
|
||||
fields = ('id','buyer_invoice')
|
15
api/views.py
15
api/views.py
@ -112,9 +112,7 @@ class OrderView(viewsets.ViewSet):
|
||||
data['maker_nick'] = str(order.maker)
|
||||
data['taker_nick'] = str(order.taker)
|
||||
|
||||
#To do fix: data['status_message'] = Order.Status.get(order.status).label
|
||||
# Needs to serialize the order.status into the message.
|
||||
data['status_message'] = Order.Status.WFB.label # Hardcoded WFB, should use order.status value.
|
||||
data['status_message'] = Order.Status(order.status).label
|
||||
|
||||
if data['is_participant']:
|
||||
return Response(data, status=status.HTTP_200_OK)
|
||||
@ -125,9 +123,9 @@ class OrderView(viewsets.ViewSet):
|
||||
return Response(data, status=status.HTTP_200_OK)
|
||||
|
||||
return Response({'Order Not Found':'Invalid Order Id'},status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
return Response({'Bad Request':'Order ID parameter not found in request'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
def take_or_update(self, request, format=None):
|
||||
order_id = request.GET.get(self.lookup_url_kwarg)
|
||||
|
||||
@ -135,7 +133,7 @@ class OrderView(viewsets.ViewSet):
|
||||
order = Order.objects.get(id=order_id)
|
||||
|
||||
if serializer.is_valid():
|
||||
invoice = serializer.data.get('invoice')
|
||||
invoice = serializer.data.get('buyer_invoice')
|
||||
|
||||
# If this is an empty POST request (no invoice), it must be taker request!
|
||||
if not invoice and order.status == Order.Status.PUB:
|
||||
@ -196,8 +194,7 @@ class UserView(APIView):
|
||||
value, counts = np.unique(list(token), return_counts=True)
|
||||
shannon_entropy = entropy(counts, base=62)
|
||||
bits_entropy = log2(len(value)**len(token))
|
||||
|
||||
# Start preparing payload
|
||||
# Payload
|
||||
context = {'token_shannon_entropy': shannon_entropy, 'token_bits_entropy': bits_entropy}
|
||||
|
||||
# Deny user gen if entropy below 128 bits or 0.7 shannon heterogeneity
|
||||
@ -208,11 +205,11 @@ class UserView(APIView):
|
||||
# Hashes the token, only 1 iteration. Maybe more is better.
|
||||
hash = hashlib.sha256(str.encode(token)).hexdigest()
|
||||
|
||||
# generate nickname
|
||||
# Generate nickname
|
||||
nickname = self.NickGen.short_from_SHA256(hash, max_length=18)[0]
|
||||
context['nickname'] = nickname
|
||||
|
||||
# generate avatar
|
||||
# Generate avatar
|
||||
rh = Robohash(hash)
|
||||
rh.assemble(roboset='set1', bgset='any')# for backgrounds ON
|
||||
|
||||
|
@ -130,13 +130,12 @@ export default class OrderPage extends Component {
|
||||
</ListItem>
|
||||
<Divider />
|
||||
</>:
|
||||
<>
|
||||
<ListItem>
|
||||
<ListItemText primary={this.state.statusText} secondary="Order status"/>
|
||||
</ListItem>
|
||||
<Divider />
|
||||
</>
|
||||
""
|
||||
}
|
||||
<ListItem>
|
||||
<ListItemText primary={this.state.statusText} secondary="Order status"/>
|
||||
</ListItem>
|
||||
<Divider />
|
||||
</>
|
||||
:""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user