Skip to content

Commit 59d361d

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 82f7c6a commit 59d361d

17 files changed

+1870
-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

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ install_requires =
4343
# Required to fix a dependency issue with parsimonious and Python3.11
4444
eth_abi==4.0.0b2; python_version>="3.11"
4545
python-magic
46+
peewee
4647
# The usage of test_requires is discouraged, see `Dependency Management` docs
4748
# tests_require = pytest; pytest-cov
4849
# Require a specific Python version, e.g. Python 2.7 or >= 3.4

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)