-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: improve chain data service
Problem: a few todos are still open on the chain data service. Solution: improve and rename the `get_chaindata` method. The new `prepare_sync_event_payload` method now always returns an off-chain sync event (on-chain sync events never occur anyway). It also returns the result as a Pydantic model for more flexibility. Serialization is left upon the caller. We now use a Pydantic model to translate `MessageDb` objects in the correct format.
- Loading branch information
1 parent
a6710e7
commit fb9ebbe
Showing
12 changed files
with
168 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from typing import Literal, Optional, List, Union, Annotated | ||
|
||
from aleph_message.models import ItemHash, ItemType, Chain, MessageType | ||
from pydantic import BaseModel, Field, validator | ||
|
||
from aleph.types.chain_sync import ChainSyncProtocol | ||
from aleph.types.channel import Channel | ||
import datetime as dt | ||
|
||
|
||
class OnChainMessage(BaseModel): | ||
class Config: | ||
orm_mode = True | ||
|
||
sender: str | ||
chain: Chain | ||
signature: Optional[str] | ||
type: MessageType | ||
item_content: Optional[str] | ||
item_type: ItemType | ||
item_hash: ItemHash | ||
time: float | ||
channel: Optional[Channel] = None | ||
|
||
@validator("time", pre=True) | ||
def check_time(cls, v, values): | ||
if isinstance(v, dt.datetime): | ||
return v.timestamp() | ||
|
||
return v | ||
|
||
|
||
class OnChainContent(BaseModel): | ||
messages: List[OnChainMessage] | ||
|
||
|
||
class OnChainSyncEventPayload(BaseModel): | ||
protocol: Literal[ChainSyncProtocol.ON_CHAIN_SYNC] | ||
version: int | ||
content: OnChainContent | ||
|
||
|
||
class OffChainSyncEventPayload(BaseModel): | ||
protocol: Literal[ChainSyncProtocol.OFF_CHAIN_SYNC] | ||
version: int | ||
content: str | ||
|
||
|
||
SyncEventPayload = Annotated[ | ||
Union[OnChainSyncEventPayload, OffChainSyncEventPayload], | ||
Field(discriminator="protocol"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters