Add robot hash ids to order details and robot view

This commit is contained in:
Reckless_Satoshi 2023-12-01 12:56:55 +00:00
parent 07830fd2fd
commit bc9f8ae985
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 36 additions and 4 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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

View File

@ -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

View File

@ -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"])