Skip to content

Commit cd62d4c

Browse files
committed
Feature: Add LightNode and MessageCache
A LightNode can synchronize on a subset, or domain, of aleph.im messages. It relies on the MessageCache, which manages a message database with peewee.
1 parent 00592c2 commit cd62d4c

18 files changed

+1852
-14
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*.pot
1111
__pycache__/*
1212
.cache/*
13+
cache/**/*
1314
.*.swp
1415
*/.ipynb_checkpoints/*
1516

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ testing =
8282
substrate-interface
8383
py-sr25519-bindings
8484
ledgereth==0.9.0
85+
peewee
8586
mqtt =
8687
aiomqtt<=0.1.3
8788
certifi
@@ -107,6 +108,8 @@ ledger =
107108
ledgereth==0.9.0
108109
docs =
109110
sphinxcontrib-plantuml
111+
cache =
112+
peewee
110113

111114
[options.entry_points]
112115
# Add here console scripts like:

src/aleph/sdk/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pkg_resources import DistributionNotFound, get_distribution
22

3-
from aleph.sdk.client import AlephHttpClient, AuthenticatedAlephHttpClient
3+
from aleph.sdk.client import AlephHttpClient, AuthenticatedAlephHttpClient, LightNode
44

55
try:
66
# Change here if project is renamed and does not equal the package name
@@ -11,4 +11,4 @@
1111
finally:
1212
del get_distribution, DistributionNotFound
1313

14-
__all__ = ["AlephHttpClient", "AuthenticatedAlephHttpClient"]
14+
__all__ = ["AlephHttpClient", "AuthenticatedAlephHttpClient", "LightNode"]

src/aleph/sdk/client/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from .abstract import AlephClient, AuthenticatedAlephClient
22
from .authenticated_http import AuthenticatedAlephHttpClient
33
from .http import AlephHttpClient
4+
from .light_node import LightNode
5+
from .message_cache import MessageCache
46

57
__all__ = [
68
"AlephClient",
79
"AuthenticatedAlephClient",
810
"AlephHttpClient",
911
"AuthenticatedAlephHttpClient",
12+
"MessageCache",
13+
"LightNode",
1014
]

src/aleph/sdk/client/http.py

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import aiohttp
77
from aleph_message import parse_message
88
from aleph_message.models import AlephMessage, ItemHash, ItemType
9+
from aleph_message.status import MessageStatus
910
from pydantic import ValidationError
1011

1112
from ..conf import settings
@@ -171,6 +172,8 @@ async def download_file_to_buffer(
171172
)
172173
else:
173174
raise FileTooLarge(f"The file from {file_hash} is too large")
175+
else:
176+
response.raise_for_status()
174177

175178
async def download_file_ipfs_to_buffer(
176179
self,
@@ -314,6 +317,11 @@ async def get_message(
314317
)
315318
return message
316319

320+
async def get_message_status(self, item_hash: str) -> MessageStatus:
321+
async with self.http_session.get(f"/api/v0/messages/{item_hash}") as resp:
322+
resp.raise_for_status()
323+
return MessageStatus((await resp.json())["status"])
324+
317325
async def watch_messages(
318326
self,
319327
message_filter: Optional[MessageFilter] = None,

0 commit comments

Comments
 (0)