Skip to content

Commit

Permalink
WIP MessageCache improvements; add correct Aggregate and Forget imple…
Browse files Browse the repository at this point in the history
…mentation
  • Loading branch information
MHHukiewitz committed Oct 5, 2023
1 parent 8be422e commit 778ae95
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 136 deletions.
6 changes: 2 additions & 4 deletions src/aleph/sdk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class BaseAlephClient(ABC):
async def fetch_aggregate(
self,
address: str,
key: str,
limit: int = 100,
key: str
) -> Dict[str, Dict]:
"""
Fetch a value from the aggregate store by owner address and item key.
Expand All @@ -53,8 +52,7 @@ async def fetch_aggregate(
async def fetch_aggregates(
self,
address: str,
keys: Optional[Iterable[str]] = None,
limit: int = 100,
keys: Optional[Iterable[str]] = None
) -> Dict[str, Dict]:
"""
Fetch key-value pairs from the aggregate store by owner address.
Expand Down
10 changes: 2 additions & 8 deletions src/aleph/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,9 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
async def fetch_aggregate(
self,
address: str,
key: str,
limit: int = 100,
key: str
) -> Dict[str, Dict]:
params: Dict[str, Any] = {"keys": key}
if limit:
params["limit"] = limit

async with self.http_session.get(
f"/api/v0/aggregates/{address}.json", params=params
Expand All @@ -548,15 +545,12 @@ async def fetch_aggregate(
async def fetch_aggregates(
self,
address: str,
keys: Optional[Iterable[str]] = None,
limit: int = 100,
keys: Optional[Iterable[str]] = None
) -> Dict[str, Dict]:
keys_str = ",".join(keys) if keys else ""
params: Dict[str, Any] = {}
if keys_str:
params["keys"] = keys_str
if limit:
params["limit"] = limit

async with self.http_session.get(
f"/api/v0/aggregates/{address}.json",
Expand Down
33 changes: 26 additions & 7 deletions src/aleph/sdk/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from typing import Any, Dict, List, Optional, Union

from aleph_message.models import AlephMessage, ItemHash, ChainRef, ItemType, Chain, MessageConfirmation
from aleph_message.models import (
AlephMessage,
Chain,
ItemHash,
ItemType,
MessageConfirmation,
)
from pydantic import BaseModel, Field


Expand All @@ -23,24 +29,37 @@ class Post(BaseModel):
A post is a type of message that can be updated. Over the get_posts API
we get the latest version of a post.
"""

chain: Chain = Field(description="Blockchain this post is associated with")
item_hash: ItemHash = Field(description="Unique hash for this post")
sender: str = Field(description="Address of the sender")
type: str = Field(description="Type of the POST message")
channel: Optional[str] = Field(description="Channel this post is associated with")
confirmed: bool = Field(description="Whether the post is confirmed or not")
content: Dict[str, Any] = Field(description="The content of the POST message")
item_content: Optional[str] = Field(description="The POSTs content field as serialized JSON, if of type inline")
item_type: ItemType = Field(description="Type of the item content, usually 'inline' or 'storage' for POSTs")
signature: Optional[str] = Field(description="Cryptographic signature of the message by the sender")
item_content: Optional[str] = Field(
description="The POSTs content field as serialized JSON, if of type inline"
)
item_type: ItemType = Field(
description="Type of the item content, usually 'inline' or 'storage' for POSTs"
)
signature: Optional[str] = Field(
description="Cryptographic signature of the message by the sender"
)
size: int = Field(description="Size of the post")
time: float = Field(description="Timestamp of the post")
confirmations: List[MessageConfirmation] = Field(description="Number of confirmations")
confirmations: List[MessageConfirmation] = Field(
description="Number of confirmations"
)
original_item_hash: ItemHash = Field(description="Hash of the original content")
original_signature: Optional[str] = Field(description="Cryptographic signature of the original message")
original_signature: Optional[str] = Field(
description="Cryptographic signature of the original message"
)
original_type: str = Field(description="The original type of the message")
hash: ItemHash = Field(description="Hash of the original item")
ref: Optional[Union[str, Any]] = Field(description="Other message referenced by this one")
ref: Optional[Union[str, Any]] = Field(
description="Other message referenced by this one"
)


class PostsResponse(PaginationResponse):
Expand Down
Loading

0 comments on commit 778ae95

Please sign in to comment.