robosats/api/serializers.py

129 lines
4.5 KiB
Python
Raw Normal View History

from rest_framework import serializers
2022-01-06 21:36:22 +00:00
from .models import Order
2022-02-17 19:50:10 +00:00
class ListOrderSerializer(serializers.ModelSerializer):
2022-02-17 19:50:10 +00:00
class Meta:
model = Order
2022-02-17 19:50:10 +00:00
fields = (
"id",
"status",
"created_at",
"expires_at",
"type",
"currency",
"amount",
"has_range",
"min_amount",
"max_amount",
2022-02-17 19:50:10 +00:00
"payment_method",
"is_explicit",
"premium",
"satoshis",
"bondless_taker",
2022-02-17 19:50:10 +00:00
"maker",
"taker",
"escrow_duration",
2022-02-17 19:50:10 +00:00
)
class MakeOrderSerializer(serializers.ModelSerializer):
2022-02-17 19:50:10 +00:00
class Meta:
model = Order
2022-02-17 19:50:10 +00:00
fields = (
"type",
"currency",
"amount",
"has_range",
"min_amount",
"max_amount",
2022-02-17 19:50:10 +00:00
"payment_method",
"is_explicit",
"premium",
"satoshis",
2022-03-18 21:21:13 +00:00
"public_duration",
"escrow_duration",
2022-03-18 22:09:38 +00:00
"bond_size",
"bondless_taker",
2022-02-17 19:50:10 +00:00
)
2022-01-06 20:33:40 +00:00
class UpdateOrderSerializer(serializers.Serializer):
2022-02-17 19:50:10 +00:00
invoice = serializers.CharField(max_length=2000,
allow_null=True,
allow_blank=True,
default=None)
statement = serializers.CharField(max_length=10000,
allow_null=True,
allow_blank=True,
default=None)
action = serializers.ChoiceField(
choices=(
"pause",
2022-02-17 19:50:10 +00:00
"take",
"update_invoice",
"submit_statement",
"dispute",
"cancel",
"confirm",
"rate_user",
"rate_platform",
),
allow_null=False,
)
rating = serializers.ChoiceField(
choices=("1", "2", "3", "4", "5"),
allow_null=True,
allow_blank=True,
default=None,
)
amount = serializers.DecimalField(max_digits=18, decimal_places=8, allow_null=True, required=False, default=None)
class UserGenSerializer(serializers.Serializer):
# Mandatory fields
token_sha256 = serializers.CharField(
min_length=64,
max_length=64,
allow_null=False,
allow_blank=False,
required=True,
help_text="SHA256 of user secret")
public_key = serializers.CharField(max_length=2000,
allow_null=False,
allow_blank=False,
required=True,
help_text="Armored ASCII PGP public key block")
encrypted_private_key = serializers.CharField(max_length=2000,
allow_null=False,
allow_blank=False,
required=True,
help_text="Armored ASCII PGP encrypted private key block")
# Optional fields
ref_code = serializers.CharField(max_length=30,
allow_null=True,
allow_blank=True,
required=False,
default=None)
counts = serializers.ListField(child=serializers.IntegerField(),
allow_null=True,
required=False,
default=None)
length = serializers.IntegerField(allow_null=True,
default=None,
required=False,
min_value=1)
unique_values = serializers.IntegerField(allow_null=True,
default=None,
required=False,
min_value=1)
class ClaimRewardSerializer(serializers.Serializer):
invoice = serializers.CharField(max_length=2000,
allow_null=True,
allow_blank=True,
default=None)
class PriceSerializer(serializers.Serializer):
pass