Skip to content

Commit af01b9a

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 ef520a0 commit af01b9a

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
@@ -178,6 +179,8 @@ async def download_file_to_buffer(
178179
)
179180
else:
180181
raise FileTooLarge(f"The file from {file_hash} is too large")
182+
else:
183+
response.raise_for_status()
181184

182185
async def download_file_ipfs_to_buffer(
183186
self,
@@ -343,6 +346,11 @@ async def get_message_error(
343346
"details": message_raw["details"],
344347
}
345348

349+
async def get_message_status(self, item_hash: str) -> MessageStatus:
350+
async with self.http_session.get(f"/api/v0/messages/{item_hash}") as resp:
351+
resp.raise_for_status()
352+
return MessageStatus((await resp.json())["status"])
353+
346354
async def watch_messages(
347355
self,
348356
message_filter: Optional[MessageFilter] = None,

0 commit comments

Comments
 (0)