Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store the settlement_service_type of dvp delivery when indexing #679

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
72 changes: 62 additions & 10 deletions docs/ibet_prime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10304,6 +10304,34 @@ components:
- is_deleted
title: DVPAgentAccountResponse
description: DVP agent account reference schema (RESPONSE)
DVPDeliveryData:
properties:
delivery_type:
type: string
enum:
- offering
- primary
title: Delivery Type
trade_date:
type: string
title: Trade Date
settlement_date:
type: string
title: Settlement Date
settlement_service_account_id:
type: string
title: Settlement Service Account Id
value:
type: integer
title: Value
type: object
required:
- delivery_type
- trade_date
- settlement_date
- settlement_service_account_id
- value
title: DVPDeliveryData
DVPDeliveryInfoMetaInfo:
properties:
exchange_address:
Expand Down Expand Up @@ -11791,6 +11819,12 @@ components:
minLength: 3
- type: 'null'
title: Face Value Currency
purpose:
anyOf:
- type: string
maxLength: 2000
- type: 'null'
title: Purpose
interest_rate:
anyOf:
- type: number
Expand Down Expand Up @@ -11835,6 +11869,16 @@ components:
const: ''
- type: 'null'
title: Redemption Value Currency
redemption_date:
anyOf:
- type: string
pattern: ^(19[0-9]{2}|20[0-9]{2})(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$
- type: string
enum:
- ''
const: ''
- type: 'null'
title: Redemption Date
base_fx_rate:
anyOf:
- type: number
Expand Down Expand Up @@ -13241,11 +13285,14 @@ components:
type: string
title: Agent Address
data:
type: string
title: Data
examples:
- '{}'
- '{"type": "primary"}'
anyOf:
- $ref: '#/components/schemas/DVPDeliveryData'
- type: 'null'
settlement_service_type:
anyOf:
- type: string
- type: 'null'
title: Settlement Service Type
create_blocktimestamp:
type: string
title: Create Blocktimestamp
Expand Down Expand Up @@ -13310,6 +13357,7 @@ components:
- amount
- agent_address
- data
- settlement_service_type
- create_blocktimestamp
- create_transaction_hash
- cancel_blocktimestamp
Expand Down Expand Up @@ -13357,11 +13405,14 @@ components:
type: string
title: Agent Address
data:
type: string
title: Data
examples:
- '{}'
- '{"type": "primary"}'
anyOf:
- $ref: '#/components/schemas/DVPDeliveryData'
- type: 'null'
settlement_service_type:
anyOf:
- type: string
- type: 'null'
title: Settlement Service Type
create_blocktimestamp:
type: string
title: Create Blocktimestamp
Expand Down Expand Up @@ -13428,6 +13479,7 @@ components:
- amount
- agent_address
- data
- settlement_service_type
- create_blocktimestamp
- create_transaction_hash
- cancel_blocktimestamp
Expand Down
31 changes: 31 additions & 0 deletions migrations/versions/f728fd994b80_v24_9_0_feature_674.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""v24_9_0_feature_674

Revision ID: f728fd994b80
Revises: f237571559e6
Create Date: 2024-08-20 11:59:35.833321

"""

from alembic import op
import sqlalchemy as sa


from app.database import get_db_schema

# revision identifiers, used by Alembic.
revision = "f728fd994b80"
down_revision = "f237571559e6"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
"idx_delivery",
sa.Column("settlement_service_type", sa.String(length=50), nullable=True),
schema=get_db_schema(),
)


def downgrade():
op.drop_column("idx_delivery", "settlement_service_type", schema=get_db_schema())
Loading