Skip to content

Commit 778ae95

Browse files
committed
WIP MessageCache improvements; add correct Aggregate and Forget implementation
1 parent 8be422e commit 778ae95

File tree

10 files changed

+283
-136
lines changed

10 files changed

+283
-136
lines changed

src/aleph/sdk/base.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class BaseAlephClient(ABC):
3737
async def fetch_aggregate(
3838
self,
3939
address: str,
40-
key: str,
41-
limit: int = 100,
40+
key: str
4241
) -> Dict[str, Dict]:
4342
"""
4443
Fetch a value from the aggregate store by owner address and item key.
@@ -53,8 +52,7 @@ async def fetch_aggregate(
5352
async def fetch_aggregates(
5453
self,
5554
address: str,
56-
keys: Optional[Iterable[str]] = None,
57-
limit: int = 100,
55+
keys: Optional[Iterable[str]] = None
5856
) -> Dict[str, Dict]:
5957
"""
6058
Fetch key-value pairs from the aggregate store by owner address.

src/aleph/sdk/client.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,9 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
531531
async def fetch_aggregate(
532532
self,
533533
address: str,
534-
key: str,
535-
limit: int = 100,
534+
key: str
536535
) -> Dict[str, Dict]:
537536
params: Dict[str, Any] = {"keys": key}
538-
if limit:
539-
params["limit"] = limit
540537

541538
async with self.http_session.get(
542539
f"/api/v0/aggregates/{address}.json", params=params
@@ -548,15 +545,12 @@ async def fetch_aggregate(
548545
async def fetch_aggregates(
549546
self,
550547
address: str,
551-
keys: Optional[Iterable[str]] = None,
552-
limit: int = 100,
548+
keys: Optional[Iterable[str]] = None
553549
) -> Dict[str, Dict]:
554550
keys_str = ",".join(keys) if keys else ""
555551
params: Dict[str, Any] = {}
556552
if keys_str:
557553
params["keys"] = keys_str
558-
if limit:
559-
params["limit"] = limit
560554

561555
async with self.http_session.get(
562556
f"/api/v0/aggregates/{address}.json",

src/aleph/sdk/models.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from typing import Any, Dict, List, Optional, Union
22

3-
from aleph_message.models import AlephMessage, ItemHash, ChainRef, ItemType, Chain, MessageConfirmation
3+
from aleph_message.models import (
4+
AlephMessage,
5+
Chain,
6+
ItemHash,
7+
ItemType,
8+
MessageConfirmation,
9+
)
410
from pydantic import BaseModel, Field
511

612

@@ -23,24 +29,37 @@ class Post(BaseModel):
2329
A post is a type of message that can be updated. Over the get_posts API
2430
we get the latest version of a post.
2531
"""
32+
2633
chain: Chain = Field(description="Blockchain this post is associated with")
2734
item_hash: ItemHash = Field(description="Unique hash for this post")
2835
sender: str = Field(description="Address of the sender")
2936
type: str = Field(description="Type of the POST message")
3037
channel: Optional[str] = Field(description="Channel this post is associated with")
3138
confirmed: bool = Field(description="Whether the post is confirmed or not")
3239
content: Dict[str, Any] = Field(description="The content of the POST message")
33-
item_content: Optional[str] = Field(description="The POSTs content field as serialized JSON, if of type inline")
34-
item_type: ItemType = Field(description="Type of the item content, usually 'inline' or 'storage' for POSTs")
35-
signature: Optional[str] = Field(description="Cryptographic signature of the message by the sender")
40+
item_content: Optional[str] = Field(
41+
description="The POSTs content field as serialized JSON, if of type inline"
42+
)
43+
item_type: ItemType = Field(
44+
description="Type of the item content, usually 'inline' or 'storage' for POSTs"
45+
)
46+
signature: Optional[str] = Field(
47+
description="Cryptographic signature of the message by the sender"
48+
)
3649
size: int = Field(description="Size of the post")
3750
time: float = Field(description="Timestamp of the post")
38-
confirmations: List[MessageConfirmation] = Field(description="Number of confirmations")
51+
confirmations: List[MessageConfirmation] = Field(
52+
description="Number of confirmations"
53+
)
3954
original_item_hash: ItemHash = Field(description="Hash of the original content")
40-
original_signature: Optional[str] = Field(description="Cryptographic signature of the original message")
55+
original_signature: Optional[str] = Field(
56+
description="Cryptographic signature of the original message"
57+
)
4158
original_type: str = Field(description="The original type of the message")
4259
hash: ItemHash = Field(description="Hash of the original item")
43-
ref: Optional[Union[str, Any]] = Field(description="Other message referenced by this one")
60+
ref: Optional[Union[str, Any]] = Field(
61+
description="Other message referenced by this one"
62+
)
4463

4564

4665
class PostsResponse(PaginationResponse):

0 commit comments

Comments
 (0)