From 2dec0282bbad531cd27efd7c80f3cffad1c82678 Mon Sep 17 00:00:00 2001 From: AnonO6 <21ucs043@gmail.com> Date: Sun, 13 Jul 2025 14:56:23 +0000 Subject: [PATCH 1/2] feat:added get_access_condition func --- src/lighthouseweb3/__init__.py | 11 ++++++++++- src/lighthouseweb3/functions/create_wallet.py | 2 +- .../functions/get_access_condition.py | 15 +++++++++++++++ tests/test_get_access_condition.py | 12 ++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/lighthouseweb3/functions/get_access_condition.py create mode 100644 tests/test_get_access_condition.py diff --git a/src/lighthouseweb3/__init__.py b/src/lighthouseweb3/__init__.py index b1d8d7c..d8f34f9 100644 --- a/src/lighthouseweb3/__init__.py +++ b/src/lighthouseweb3/__init__.py @@ -14,10 +14,12 @@ ipns_publish_record as ipnsPublishRecord, get_ipns_record as getIpnsRecord, remove_ipns_record as removeIpnsRecord, - create_wallet as createWallet + create_wallet as createWallet, + get_access_condition as getAccessCondition ) + class Lighthouse: def __init__(self, token: str = ""): self.token = token or os.environ.get("LIGHTHOUSE_TOKEN", "") @@ -224,3 +226,10 @@ def getTagged(self, tag: str): except Exception as e: raise e + @staticmethod + def getAccessCondition(cid: str): + try: + return getAccessCondition.get_access_condition(cid) + except Exception as e: + raise e + diff --git a/src/lighthouseweb3/functions/create_wallet.py b/src/lighthouseweb3/functions/create_wallet.py index a8d2335..455162d 100644 --- a/src/lighthouseweb3/functions/create_wallet.py +++ b/src/lighthouseweb3/functions/create_wallet.py @@ -6,7 +6,7 @@ def create_wallet(password: str): wallet = Account.create() - url = f"{Config.lighthouse_api}/api/auth/get_auth_message?publicKey={wallet.address}" + url = f"{Config.lighthouse_bls_node}/api/auth/get_auth_message?publicKey={wallet.address}" try: response = req.get(url) diff --git a/src/lighthouseweb3/functions/get_access_condition.py b/src/lighthouseweb3/functions/get_access_condition.py new file mode 100644 index 0000000..599d912 --- /dev/null +++ b/src/lighthouseweb3/functions/get_access_condition.py @@ -0,0 +1,15 @@ +import httpx +from typing import Any, Dict +from .config import Config + +async def get_access_condition(cid: str) -> Dict[str, Any]: + url = f"{Config.lighthouse_api}/api/fileAccessConditions/get/{cid}" + + try: + async with httpx.AsyncClient() as client: + response = await client.get(url) + response.raise_for_status() + conditions = response.json() + return {"data": conditions} + except httpx.HTTPError as exc: + raise Exception(f"HTTP error occurred: {exc}") from exc diff --git a/tests/test_get_access_condition.py b/tests/test_get_access_condition.py new file mode 100644 index 0000000..13e99dc --- /dev/null +++ b/tests/test_get_access_condition.py @@ -0,0 +1,12 @@ +import unittest +from src.lighthouseweb3 import Lighthouse + + +class TestCreateWallet(unittest.TestCase): + + async def test_get_access_condition(self): + """test static create wallet function""" + cid = 'QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH' + res = await Lighthouse.getAccessCondition(cid=cid) + self.assertIsInstance(res, dict) + self.assertEqual(res.get("data").get("cid"), cid) From ed8e68ad1d0c8162b3f8b613f14ae2147be33c7a Mon Sep 17 00:00:00 2001 From: AnonO6 <21ucs043@gmail.com> Date: Sun, 13 Jul 2025 17:26:51 +0000 Subject: [PATCH 2/2] feat:added doc string --- src/lighthouseweb3/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lighthouseweb3/__init__.py b/src/lighthouseweb3/__init__.py index d8f34f9..166827f 100644 --- a/src/lighthouseweb3/__init__.py +++ b/src/lighthouseweb3/__init__.py @@ -228,8 +228,13 @@ def getTagged(self, tag: str): @staticmethod def getAccessCondition(cid: str): + """ + Retrieves the access condition for a given content identifier (CID). + + :param cid: str, Content Identifier for the data to be retrieved + :return: dict, A dictionary containing the access condition + """ try: return getAccessCondition.get_access_condition(cid) except Exception as e: raise e -