From 92b041cb3104d38ff14c97db5fdbd171c685b677 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Tue, 28 Nov 2023 11:13:40 +0000 Subject: [PATCH] Add maker_hash_id to book response --- api/serializers.py | 2 ++ api/views.py | 1 + docs/assets/schemas/api-latest.yaml | 2 ++ robosats/middleware.py | 3 +++ tests/test_trade_pipeline.py | 1 + 5 files changed, 9 insertions(+) diff --git a/api/serializers.py b/api/serializers.py index c4ccca88..f6cb7f77 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -476,6 +476,7 @@ class OrderDetailSerializer(serializers.ModelSerializer): class OrderPublicSerializer(serializers.ModelSerializer): maker_nick = serializers.CharField(required=False) + maker_hash_id = serializers.CharField(required=False) maker_status = serializers.CharField( help_text='Status of the nick - "Active" or "Inactive"', required=False ) @@ -505,6 +506,7 @@ class OrderPublicSerializer(serializers.ModelSerializer): "satoshis", "maker", "maker_nick", + "maker_hash_id", "maker_status", "price", "escrow_duration", diff --git a/api/views.py b/api/views.py index e050cee0..1d01118f 100644 --- a/api/views.py +++ b/api/views.py @@ -708,6 +708,7 @@ class BookView(ListAPIView): for order in queryset: data = ListOrderSerializer(order).data data["maker_nick"] = str(order.maker) + data["maker_hash_id"] = str(order.maker.robot.hash_id) data["satoshis_now"] = Logics.satoshis_now(order) # Compute current premium for those orders that are explicitly priced. diff --git a/docs/assets/schemas/api-latest.yaml b/docs/assets/schemas/api-latest.yaml index 85bcb1e7..f3246422 100644 --- a/docs/assets/schemas/api-latest.yaml +++ b/docs/assets/schemas/api-latest.yaml @@ -1554,6 +1554,8 @@ components: nullable: true maker_nick: type: string + maker_hash_id: + type: string maker_status: type: string description: Status of the nick - "Active" or "Inactive" diff --git a/robosats/middleware.py b/robosats/middleware.py index 7e2a5df1..8e27fc45 100644 --- a/robosats/middleware.py +++ b/robosats/middleware.py @@ -137,6 +137,9 @@ class RobotTokenSHA256AuthenticationMiddleWare: user = User.objects.create_user(username=nickname, password=None) + # Store hash_id + user.robot.hash_id = hash + # Django rest_framework authtokens are limited to 40 characters. # We use base91 so we can store the full entropy in the field. Token.objects.create(key=token_sha256_b91, user=user) diff --git a/tests/test_trade_pipeline.py b/tests/test_trade_pipeline.py index ef9b4dd0..922b79dd 100644 --- a/tests/test_trade_pipeline.py +++ b/tests/test_trade_pipeline.py @@ -831,6 +831,7 @@ class TradeTest(BaseAPITestCase): self.assertIsInstance(datetime.fromisoformat(data[0]["created_at"]), datetime) self.assertIsInstance(datetime.fromisoformat(data[0]["expires_at"]), datetime) + self.assertIsHash(data[0]["maker_hash_id"]) self.assertIsNone(data[0]["amount"]) self.assertAlmostEqual( float(data[0]["min_amount"]), trade.maker_form["min_amount"]