From bc9f8ae985a9f7f847d4ba89f866c9154efd8a93 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Fri, 1 Dec 2023 12:56:55 +0000 Subject: [PATCH] Add robot hash ids to order details and robot view --- api/oas_schemas.py | 4 ++++ api/serializers.py | 11 +++++++++-- api/views.py | 4 ++++ docs/assets/schemas/api-latest.yaml | 15 +++++++++++++-- tests/test_trade_pipeline.py | 6 ++++++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/api/oas_schemas.py b/api/oas_schemas.py index 41a138e9..2c611f84 100644 --- a/api/oas_schemas.py +++ b/api/oas_schemas.py @@ -432,6 +432,10 @@ class RobotViewSchema: "type": "string", "description": "Username generated (Robot name)", }, + "hash_id": { + "type": "string", + "description": "The hash identity of the robot, it is used to deterministically generate the avatar and the nicknames. It is the second sha256() of the token.", + }, "public_key": { "type": "string", "description": "Armored ASCII PGP public key block", diff --git a/api/serializers.py b/api/serializers.py index f6cb7f77..205613d6 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -254,8 +254,14 @@ class OrderDetailSerializer(serializers.ModelSerializer): maker_nick = serializers.CharField( required=False, help_text="Nickname (Robot name) of the maker" ) + maker_hash_id = serializers.CharField( + required=False, help_text="The maker's robot hash" + ) taker_nick = serializers.CharField( - required=False, help_text="Nickname (Robot name) of the taker" + required=False, help_text="The taker's robot hash" + ) + taker_hash_id = serializers.CharField( + required=False, help_text="The taker's robot hash" ) status_message = serializers.CharField( required=False, @@ -268,7 +274,6 @@ class OrderDetailSerializer(serializers.ModelSerializer): required=False, help_text="Whether or not the counterparty raised a dispute" ) ur_nick = serializers.CharField(required=False, help_text="Your Nickname") - ur_nick = serializers.CharField(required=False, help_text="Your Nick") maker_locked = serializers.BooleanField( required=False, help_text="True if maker bond is locked, False otherwise" ) @@ -428,7 +433,9 @@ class OrderDetailSerializer(serializers.ModelSerializer): "is_buyer", "is_seller", "maker_nick", + "maker_hash_id", "taker_nick", + "taker_hash_id", "status_message", "is_fiat_sent", "is_disputed", diff --git a/api/views.py b/api/views.py index 1d01118f..453c69e4 100644 --- a/api/views.py +++ b/api/views.py @@ -244,6 +244,7 @@ class OrderView(viewsets.ViewSet): ) data["maker_nick"] = str(order.maker) + data["maker_hash_id"] = str(order.maker.robot.hash_id) # Add activity status of participants based on last_seen data["maker_status"] = Logics.user_activity_status(order.maker.last_login) @@ -278,6 +279,8 @@ class OrderView(viewsets.ViewSet): data["is_buyer"] = Logics.is_buyer(order, request.user) data["is_seller"] = Logics.is_seller(order, request.user) data["taker_nick"] = str(order.taker) + if order.taker: + data["taker_hash_id"] = str(order.taker.robot.hash_id) data["status_message"] = Order.Status(order.status).label data["is_fiat_sent"] = order.is_fiat_sent data["latitude"] = order.latitude @@ -648,6 +651,7 @@ class RobotView(APIView): user = request.user context = {} context["nickname"] = user.username + context["hash_id"] = user.robot.hash_id context["public_key"] = user.robot.public_key context["encrypted_private_key"] = user.robot.encrypted_private_key context["earned_rewards"] = user.robot.earned_rewards diff --git a/docs/assets/schemas/api-latest.yaml b/docs/assets/schemas/api-latest.yaml index 9887731d..055f0434 100644 --- a/docs/assets/schemas/api-latest.yaml +++ b/docs/assets/schemas/api-latest.yaml @@ -770,6 +770,11 @@ paths: nickname: type: string description: Username generated (Robot name) + hash_id: + type: string + description: The hash identity of the robot, it is used to deterministically + generate the avatar and the nicknames. It is the second sha256() + of the token. public_key: type: string description: Armored ASCII PGP public key block @@ -1375,9 +1380,15 @@ components: maker_nick: type: string description: Nickname (Robot name) of the maker + maker_hash_id: + type: string + description: The maker's robot hash taker_nick: type: string - description: Nickname (Robot name) of the taker + description: The taker's robot hash + taker_hash_id: + type: string + description: The taker's robot hash status_message: type: string description: The current status of the order corresponding to the `status` @@ -1389,7 +1400,7 @@ components: description: Whether or not the counterparty raised a dispute ur_nick: type: string - description: Your Nick + description: Your Nickname maker_locked: type: boolean description: True if maker bond is locked, False otherwise diff --git a/tests/test_trade_pipeline.py b/tests/test_trade_pipeline.py index ef96eae6..a3671d50 100644 --- a/tests/test_trade_pipeline.py +++ b/tests/test_trade_pipeline.py @@ -257,6 +257,10 @@ class TradeTest(BaseAPITestCase): self.assertEqual( data["ur_nick"], read_file(f"tests/robots/{robot_index}/nickname") ) + self.assertEqual( + data["maker_nick"], read_file(f"tests/robots/{robot_index}/nickname") + ) + self.assertIsHash(data["maker_hash_id"]) self.assertIsInstance(data["satoshis_now"], int) self.assertFalse(data["maker_locked"]) self.assertFalse(data["taker_locked"]) @@ -342,6 +346,8 @@ class TradeTest(BaseAPITestCase): self.assertEqual( data["maker_nick"], read_file(f"tests/robots/{trade.maker_index}/nickname") ) + self.assertIsHash(data["maker_hash_id"]) + self.assertIsHash(data["taker_hash_id"]) self.assertEqual(data["maker_status"], "Active") self.assertEqual(data["taker_status"], "Active") self.assertFalse(data["is_maker"])