Skip to content

Commit

Permalink
Add an indexer of DVP delivery event
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesmoke05 committed Apr 11, 2024
1 parent 0542dd8 commit 275b3b7
Show file tree
Hide file tree
Showing 16 changed files with 5,386 additions and 27 deletions.
1 change: 1 addition & 0 deletions app/model/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .e2e_messaging_account import E2EMessagingAccount, E2EMessagingAccountRsaKey
from .freeze_log_account import FreezeLogAccount
from .idx_block_data import IDXBlockData, IDXBlockDataBlockNumber
from .idx_delivery import DeliveryStatus, IDXDelivery, IDXDeliveryBlockNumber
from .idx_e2e_messaging import IDXE2EMessaging, IDXE2EMessagingBlockNumber
from .idx_issue_redeem import (
IDXIssueRedeem,
Expand Down
6 changes: 2 additions & 4 deletions app/model/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from datetime import UTC, date as datetime_date, datetime

from sqlalchemy import DateTime
from sqlalchemy.orm import Mapped, declarative_base, mapped_column
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

from app.database import get_db_schema

Expand All @@ -34,7 +34,7 @@ def naive_utcnow():
return aware_utcnow().replace(tzinfo=None)


class BaseModel(object):
class Base(DeclarativeBase):
# created datetime(UTC)
created: Mapped[datetime | None] = mapped_column(DateTime, default=naive_utcnow)
# modified datetime(UTC)
Expand All @@ -50,8 +50,6 @@ def datetime_to_timestamp(date):
return None


Base = declarative_base(cls=BaseModel)

schema = get_db_schema()
if schema is not None:
setattr(Base, "__table_args__", {"schema": schema})
129 changes: 129 additions & 0 deletions app/model/db/idx_delivery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
"""
Copyright BOOSTRY Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
"""

from datetime import datetime
from enum import IntEnum

from sqlalchemy import BigInteger, Boolean, DateTime, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from .base import Base


class DeliveryStatus(IntEnum):
"""DVP Delivery Status"""

DELIVERY_CREATED = 0
DELIVERY_CANCELED = 1
DELIVERY_CONFIRMED = 2
DELIVERY_FINISHED = 3
DELIVERY_ABORTED = 4


class IDXDelivery(Base):
"""DVP Delivery Event (INDEX)"""

__tablename__ = "idx_delivery"

# Sequence Id
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
# DVP Contract Address
exchange_address: Mapped[str] = mapped_column(
String(42), index=True, nullable=False
)
# Delivery ID
delivery_id: Mapped[int] = mapped_column(BigInteger, index=True, nullable=False)
# Token Address
token_address: Mapped[str] = mapped_column(String(42), index=True, nullable=False)
# Delivery Buyer
buyer_address: Mapped[str] = mapped_column(String(42), nullable=False)
# Delivery From
seller_address: Mapped[str] = mapped_column(String(42), index=True, nullable=False)
# Delivery Amount
amount: Mapped[int] = mapped_column(BigInteger, nullable=False)
# Delivery Agent
agent_address: Mapped[str] = mapped_column(String(42), index=True, nullable=False)
# Data
data: Mapped[str] = mapped_column(Text)
# Create Delivery Blocktimestamp
create_blocktimestamp: Mapped[datetime] = mapped_column(DateTime, nullable=False)
# Create Transaction Hash
create_transaction_hash: Mapped[str] = mapped_column(
String(66), index=True, nullable=False
)
# Cancel Delivery Blocktimestamp
cancel_blocktimestamp: Mapped[datetime | None] = mapped_column(DateTime)
# Cancel Transaction Hash
cancel_transaction_hash: Mapped[str | None] = mapped_column(String(66), index=True)
# Confirm Delivery Blocktimestamp
confirm_blocktimestamp: Mapped[datetime | None] = mapped_column(DateTime)
# Confirm Transaction Hash
confirm_transaction_hash: Mapped[str | None] = mapped_column(String(66), index=True)
# Finish Delivery Blocktimestamp
finish_blocktimestamp: Mapped[datetime | None] = mapped_column(DateTime)
# Finish Transaction Hash
finish_transaction_hash: Mapped[str | None] = mapped_column(String(66), index=True)
# Abort Delivery Blocktimestamp
abort_blocktimestamp: Mapped[datetime | None] = mapped_column(DateTime)
# Abort Transaction Hash
abort_transaction_hash: Mapped[str | None] = mapped_column(String(66), index=True)
# Confirmation Status
confirmed: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
# Delivery Valid Status
valid: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
# Delivery Status(DeliveryStatus)
status: Mapped[int] = mapped_column(
BigInteger, nullable=False, default=DeliveryStatus.DELIVERY_CREATED
)

def json(self):
return {
"exchange_address": self.exchange_address,
"token_address": self.token_address,
"delivery_id": self.delivery_id,
"buyer_address": self.buyer_address,
"seller_address": self.seller_address,
"agent_address": self.agent_address,
"amount": self.amount,
"data": self.data,
"create_blocktimestamp": self.create_blocktimestamp,
"create_transaction_hash": self.create_transaction_hash,
"cancel_blocktimestamp": self.cancel_blocktimestamp,
"cancel_transaction_hash": self.cancel_transaction_hash,
"confirm_blocktimestamp": self.confirm_blocktimestamp,
"confirm_transaction_hash": self.confirm_transaction_hash,
"finish_blocktimestamp": self.finish_blocktimestamp,
"finish_transaction_hash": self.finish_transaction_hash,
"abort_blocktimestamp": self.abort_blocktimestamp,
"abort_transaction_hash": self.abort_transaction_hash,
"confirmed": self.confirmed,
"valid": self.valid,
"status": self.status,
}


class IDXDeliveryBlockNumber(Base):
"""Synchronized blockNumber of IDXDelivery"""

__tablename__ = "idx_delivery_block_number"

# target exchange address
exchange_address: Mapped[str] = mapped_column(String(42), primary_key=True)
# latest blockNumber
latest_block_number: Mapped[int] = mapped_column(BigInteger, nullable=False)
28 changes: 28 additions & 0 deletions app/utils/contract_error_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,34 @@
240303: "Message sender is not escrow agent.",
240304: "Token status of escrow is inactive.",
240401: "Message sender balance is insufficient.",
# DVPStorage (25XXXX)
250001: "Message sender(exchange contract) isn't latest version.",
# IbetSecurityTokenDVP (26XXXX)
260001: "Delivery amount is 0.",
260002: "Message sender balance is insufficient.",
260003: "Token status of delivery is inactive.",
260004: "Token transferApprovalRequired of delivery is enabled.",
260101: "Target delivery ID is invalid.",
260102: "Target delivery status is invalid.",
260103: "Target delivery has been confirmed.",
260104: "Message sender is not the delivery seller nor the delivery buyer.",
260201: "Target delivery ID is invalid.",
260202: "Target delivery status is invalid.",
260203: "Target delivery has been confirmed.",
260204: "Message sender is not the delivery buyer.",
260205: "Token status of delivery is inactive.",
260206: "Token transferApprovalRequired of delivery is enabled.",
260301: "Target delivery ID is invalid.",
260302: "Target delivery status is invalid.",
260303: "Target delivery has not been confirmed.",
260304: "Message sender is not the delivery agent.",
260305: "Token status of delivery is inactive.",
260306: "Token transferApprovalRequired of delivery is enabled.",
260401: "Target delivery ID is invalid.",
260402: "Target delivery status is invalid.",
260403: "Target delivery has been confirmed.",
260404: "Message sender is not the delivery agent.",
260501: "Message sender balance is insufficient.",
# PaymentGateway (30XXXX)
300001: "Payment account is banned.",
300101: "Target account address is not registered.",
Expand Down
Loading

0 comments on commit 275b3b7

Please sign in to comment.