Skip to content

Commit

Permalink
Store the settlement_service_type of dvp delivery when indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesmoke05 committed Aug 20, 2024
1 parent b9954fd commit 47549ce
Show file tree
Hide file tree
Showing 9 changed files with 1,965 additions and 216 deletions.
5 changes: 5 additions & 0 deletions app/model/db/idx_dvp_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class IDXDelivery(Base):
agent_address: Mapped[str] = mapped_column(String(42), index=True, nullable=False)
# Data
data: Mapped[str] = mapped_column(Text)
# Settlement Service Type
settlement_service_type: Mapped[str | None] = mapped_column(
String(50), nullable=True
)
# Create Delivery Blocktimestamp
create_blocktimestamp: Mapped[datetime] = mapped_column(DateTime, nullable=False)
# Create Transaction Hash
Expand Down Expand Up @@ -102,6 +106,7 @@ def json(self):
"agent_address": self.agent_address,
"amount": self.amount,
"data": self.data,
"settlement_service_type": self.settlement_service_type,
"create_blocktimestamp": self.create_blocktimestamp,
"create_transaction_hash": self.create_transaction_hash,
"cancel_blocktimestamp": self.cancel_blocktimestamp,
Expand Down
14 changes: 12 additions & 2 deletions app/model/schema/settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class DeliveryStatus(IntEnum):
DELIVERY_ABORTED = 4


class DVPDeliveryData(BaseModel):
delivery_type: Literal["offering", "primary"]
trade_date: str
settlement_date: str
settlement_service_account_id: str
value: int


############################
# REQUEST
############################
Expand Down Expand Up @@ -192,7 +200,8 @@ class RetrieveDVPDeliveryResponse(BaseModel):
seller_personal_information: Optional[PersonalInfo] = Field(...)
amount: int
agent_address: str
data: str = Field(examples=["{}", '{"type": "primary"}'])
data: DVPDeliveryData | None
settlement_service_type: str | None
create_blocktimestamp: str
create_transaction_hash: str
cancel_blocktimestamp: Optional[str] = Field(...)
Expand Down Expand Up @@ -225,7 +234,8 @@ class RetrieveDVPAgentDeliveryResponse(BaseModel):
seller_address: str
amount: int
agent_address: str
data: str = Field(examples=["{}", '{"type": "primary"}'])
data: DVPDeliveryData | None
settlement_service_type: str | None
create_blocktimestamp: str
create_transaction_hash: str
cancel_blocktimestamp: Optional[str] = Field(...)
Expand Down
6 changes: 4 additions & 2 deletions app/routers/issuer/settlement_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ async def list_all_dvp_deliveries(
),
"amount": _delivery.amount,
"agent_address": _delivery.agent_address,
"data": _delivery.data,
"data": json.loads(_delivery.data) if _delivery.data else None,
"settlement_service_type": _delivery.settlement_service_type,
"create_blocktimestamp": create_blocktimestamp,
"create_transaction_hash": _delivery.create_transaction_hash,
"cancel_blocktimestamp": cancel_blocktimestamp,
Expand Down Expand Up @@ -479,7 +480,8 @@ async def retrieve_dvp_delivery(
),
"amount": _delivery[0].amount,
"agent_address": _delivery[0].agent_address,
"data": _delivery[0].data,
"data": json.loads(_delivery[0].data) if _delivery[0].data else None,
"settlement_service_type": _delivery[0].settlement_service_type,
"create_blocktimestamp": create_blocktimestamp,
"create_transaction_hash": _delivery[0].create_transaction_hash,
"cancel_blocktimestamp": cancel_blocktimestamp,
Expand Down
4 changes: 3 additions & 1 deletion app/routers/misc/settlement_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import json
import re
import secrets
from datetime import UTC
Expand Down Expand Up @@ -357,7 +358,8 @@ async def list_all_dvp_agent_deliveries(
"seller_address": _delivery.seller_address,
"amount": _delivery.amount,
"agent_address": _delivery.agent_address,
"data": _delivery.data,
"data": json.loads(_delivery.data) if _delivery.data else None,
"settlement_service_type": _delivery.settlement_service_type,
"create_blocktimestamp": create_blocktimestamp,
"create_transaction_hash": _delivery.create_transaction_hash,
"cancel_blocktimestamp": cancel_blocktimestamp,
Expand Down
15 changes: 11 additions & 4 deletions batch/indexer_dvp_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ async def __sync_delivery_created(
# "settlement_service_type": "",
# "data": ""
# }
raw_data = args.get("data")
raw_data: str = args.get("data")
try:
raw_data_json = json.loads(raw_data)
except JSONDecodeError:
Expand All @@ -323,7 +323,7 @@ async def __sync_delivery_created(
"data": None,
}

_data = raw_data
_data: str = raw_data
if DVP_DATA_ENCRYPTION_MODE == "aes-256-cbc":
if (
raw_data_json.get("encryption_algorithm") == "aes-256-cbc"
Expand Down Expand Up @@ -360,6 +360,9 @@ async def __sync_delivery_created(
block_timestamp=block_timestamp,
transaction_hash=transaction_hash,
data=_data,
settlement_service_type=raw_data_json.get(
"settlement_service_type", None
),
)
except Exception:
raise
Expand Down Expand Up @@ -591,19 +594,22 @@ async def __sink_on_delivery(
block_timestamp: int,
transaction_hash: str,
data: Optional[str] = None,
settlement_service_type: Optional[str] = None,
):
"""Update Delivery data in DB
:param db_session: ORM session
:param event_type: event type ["Created", "Canceled", "Confirmed", "Finished", "Aborted"]
:param token_address: token address
:param exchange_address: exchange address
:param delivery_id: delivery id
:param token_address: token address
:param buyer_address: delivery buyer address
:param seller_address: delivery seller address
:param amount: delivery amount
:param agent_address: delivery agent address
:param data: optional data (Created)
:param block_timestamp: block timestamp
:param transaction_hash: transaction hash
:param data: [optional] data (Created)
:param settlement_service_type: [optional] settlement service type (Created)
:return: None
"""
# Verify account exists
Expand Down Expand Up @@ -662,6 +668,7 @@ async def __sink_on_delivery(
delivery.amount = amount
delivery.agent_address = agent_address
delivery.data = data
delivery.settlement_service_type = settlement_service_type
delivery.create_blocktimestamp = datetime.fromtimestamp(
block_timestamp, tz=UTC
)
Expand Down
Loading

0 comments on commit 47549ce

Please sign in to comment.