Skip to content
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
3 changes: 3 additions & 0 deletions app/api/routers/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async def list_all_notifications(
"""
Returns notifications filtered by given query.
"""
notification_category = request_query.notification_category
address = request_query.address
notification_type = request_query.notification_type
priority = request_query.priority
Expand All @@ -75,6 +76,8 @@ async def list_all_notifications(
)

# Search Filter
if notification_category is not None:
stmt = stmt.where(Notification.notification_category == notification_category)
if address is not None:
stmt = stmt.where(Notification.address == to_checksum_address(address))
if notification_type is not None:
Expand Down
7 changes: 6 additions & 1 deletion app/model/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@
from .listing import Listing
from .messaging import ChatWebhook, Mail
from .node import Node
from .notification import Notification, NotificationBlockNumber, NotificationType
from .notification import (
Notification,
NotificationAttributeValue,
NotificationBlockNumber,
NotificationType,
)
from .public_info import PublicAccountList, TokenList
from .tokenholders import TokenHolder, TokenHolderBatchStatus, TokenHoldersList
from .user_info import AccountTag
45 changes: 40 additions & 5 deletions app/model/db/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import sys
from datetime import datetime
from enum import StrEnum
from typing import Literal

from sqlalchemy import (
JSON,
Expand Down Expand Up @@ -63,13 +64,29 @@ class Notification(Base):
autoincrement=True,
)

# 通知分類
notification_category: Mapped[Literal["event_log", "attribute_change"]] = (
mapped_column(
String(20),
primary_key=True,
)
)

# 通知ID
# Spec: 0x | <blockNumber> | <transactionIndex> | <logIndex> | <optionType>
# Spec: 0x | <field1> | <field2> | <field3> | <optionType>
# ( | は文字列連結 )
# <blockNumber>: blockNumberをhexstringで表現したもの。12桁
# <transactionIndex>: transactionIndex(block内でのトランザクションの採番)をhexstringで表現したもの。6桁
# <logIndex>: logIndex(transaction内でのログの採番)をhexstringで表現したもの。6桁
# <optionType>: blockNumber, transactionIndex, logIndexが等しいが、通知としては複数にしたい場合に使用する識別子。2桁(デフォルトは00)
#
# notification_category = "event_log" の場合
# <field1> = <blockNumber>: blockNumberをhexstringで表現したもの。12桁
# <field2> = <transactionIndex>: transactionIndex(block内でのトランザクションの採番)をhexstringで表現したもの。6桁
# <field3> = <logIndex>: logIndex(transaction内でのログの採番)をhexstringで表現したもの。6桁
# <optionType>: blockNumber, transactionIndex, logIndexが等しいが、通知としては複数にしたい場合に使用する識別子。2桁(デフォルトは00)
#
# notification_category = "attribute_change" の場合
# <field1> = <timestamp>: ミリ秒タイムスタンプをhexstringで表現したもの。12桁
# <field2> = <contractId>: コントラクトアドレス。40桁
# <field3> = <attributeId>: 属性名のkeccak256ハッシュ先頭8文字。8桁
# <optionType>: 同一のコントラクト・属性で複数通知にする場合の識別子。2桁(デフォルトは00)
notification_id: Mapped[str] = mapped_column(String(256), primary_key=True)

# 通知タイプ(例:BuySettlementOK, BuyAgreementなど)
Expand Down Expand Up @@ -122,6 +139,7 @@ def __repr__(self):

def json(self):
return {
"notification_category": self.notification_category,
"notification_type": self.notification_type,
"id": self.notification_id,
"priority": self.priority,
Expand Down Expand Up @@ -185,6 +203,7 @@ def json(self):


class NotificationType(StrEnum):
# Event Log Notification
NEW_ORDER = "NewOrder"
NEW_ORDER_COUNTERPART = "NewOrderCounterpart"
CANCEL_ORDER = "CancelOrder"
Expand All @@ -206,6 +225,9 @@ class NotificationType(StrEnum):
CHANGE_TO_REDEEMED = "ChangeToRedeemed"
CHANGE_TO_CANCELED = "ChangeToCanceled"

# Attribute Change Notification
TRANSFERABLE_CHANGED = "TransferableChanged"


class NotificationBlockNumber(Base):
"""Synchronized blockNumber of Notification"""
Expand All @@ -226,3 +248,16 @@ class NotificationBlockNumber(Base):
}

FIELDS.update(Base.FIELDS)


class NotificationAttributeValue(Base):
"""Synchronized attribute value for Notification"""

__tablename__ = "notification_attribute_value"

# contract address
contract_address = mapped_column(String(42), primary_key=True)
# attribute key
attribute_key = mapped_column(String(256), primary_key=True)
# attribute
attribute = mapped_column(JSON, nullable=False)
8 changes: 6 additions & 2 deletions app/model/schema/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""

from enum import StrEnum
from typing import Optional
from typing import Literal, Optional

from pydantic import BaseModel, Field

Expand Down Expand Up @@ -47,6 +47,9 @@ class NotificationsSortItem(StrEnum):


class NotificationsQuery(BasePaginationQuery):
notification_category: Optional[Literal["event_log", "attribute_change"]] = Field(
None
)
address: Optional[EthereumAddress] = Field(None, description="account address")
notification_type: Optional[NotificationType] = Field(None)
priority: Optional[int] = Field(None, ge=0, le=2)
Expand Down Expand Up @@ -85,8 +88,9 @@ class NotificationMetainfo(BaseModel):


class Notification(BaseModel):
notification_type: NotificationType = Field(examples=[NotificationType.NEW_ORDER])
notification_category: Literal["event_log", "attribute_change"]
id: str = Field(examples=["0x00000373ca8600000000000000"])
notification_type: NotificationType = Field(examples=[NotificationType.NEW_ORDER])
priority: int
block_timestamp: str = Field(description="block timestamp")
is_read: bool
Expand Down
9 changes: 9 additions & 0 deletions batch/processor_Notifications_Coupon_Exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry)
notification.notification_type = self.notification_type
notification.priority = 0
Expand Down Expand Up @@ -276,6 +277,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry)
notification.notification_type = self.notification_type
notification.priority = 0
Expand Down Expand Up @@ -319,6 +321,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry)
notification.notification_type = self.notification_type
notification.priority = 2
Expand Down Expand Up @@ -359,6 +362,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 1)
notification.notification_type = self.notification_type
notification.priority = 1
Expand Down Expand Up @@ -399,6 +403,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 2)
notification.notification_type = self.notification_type
notification.priority = 2
Expand Down Expand Up @@ -439,6 +444,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 1)
notification.notification_type = self.notification_type
notification.priority = 1
Expand Down Expand Up @@ -482,6 +488,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 2)
notification.notification_type = self.notification_type
notification.priority = 1
Expand Down Expand Up @@ -522,6 +529,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 1)
notification.notification_type = self.notification_type
notification.priority = 2
Expand Down Expand Up @@ -565,6 +573,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 2)
notification.notification_type = self.notification_type
notification.priority = 2
Expand Down
9 changes: 9 additions & 0 deletions batch/processor_Notifications_Membership_Exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry)
notification.notification_type = self.notification_type
notification.priority = 0
Expand Down Expand Up @@ -279,6 +280,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry)
notification.notification_type = self.notification_type
notification.priority = 0
Expand Down Expand Up @@ -322,6 +324,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry)
notification.notification_type = self.notification_type
notification.priority = 2
Expand Down Expand Up @@ -362,6 +365,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 1)
notification.notification_type = self.notification_type
notification.priority = 1
Expand Down Expand Up @@ -402,6 +406,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 2)
notification.notification_type = self.notification_type
notification.priority = 2
Expand Down Expand Up @@ -445,6 +450,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 1)
notification.notification_type = self.notification_type
notification.priority = 1
Expand Down Expand Up @@ -488,6 +494,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 2)
notification.notification_type = self.notification_type
notification.priority = 1
Expand Down Expand Up @@ -531,6 +538,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 1)
notification.notification_type = self.notification_type
notification.priority = 2
Expand Down Expand Up @@ -574,6 +582,7 @@ async def watch(self, db_session: AsyncSession, entries):
}

notification = Notification()
notification.notification_category = "event_log"
notification.notification_id = self._gen_notification_id(entry, 2)
notification.notification_type = self.notification_type
notification.priority = 2
Expand Down
Loading
Loading