diff --git a/src/lighthouseweb3/__init__.py b/src/lighthouseweb3/__init__.py index b1d8d7c..a13f762 100644 --- a/src/lighthouseweb3/__init__.py +++ b/src/lighthouseweb3/__init__.py @@ -14,7 +14,8 @@ ipns_publish_record as ipnsPublishRecord, get_ipns_record as getIpnsRecord, remove_ipns_record as removeIpnsRecord, - create_wallet as createWallet + create_wallet as createWallet, + podsi as podsi ) @@ -224,3 +225,15 @@ def getTagged(self, tag: str): except Exception as e: raise e + def getProof(self, cid: str): + """ + Get proof from the Lighthouse. + + :param cid: str, content identifier + :return: List[t.DealData], list of deal data + """ + try: + return podsi.get_proof(cid) + except Exception as e: + raise e + diff --git a/src/lighthouseweb3/functions/config.py b/src/lighthouseweb3/functions/config.py index 000c5ef..3104a7a 100644 --- a/src/lighthouseweb3/functions/config.py +++ b/src/lighthouseweb3/functions/config.py @@ -9,3 +9,4 @@ class Config: lighthouse_node = "https://node.lighthouse.storage" lighthouse_bls_node = "https://encryption.lighthouse.storage" lighthouse_gateway = "https://gateway.lighthouse.storage/ipfs" + \ No newline at end of file diff --git a/src/lighthouseweb3/functions/podsi.py b/src/lighthouseweb3/functions/podsi.py new file mode 100644 index 0000000..65edf44 --- /dev/null +++ b/src/lighthouseweb3/functions/podsi.py @@ -0,0 +1,56 @@ +import requests +from typing import TypedDict, List +from .config import Config + +class VerifierData(TypedDict): + commPc: str + sizePc: str + +class ProofIndex(TypedDict): + index: str + path: List[str] + +class ProofSubtree(TypedDict): + index: str + path: List[str] + +class IndexRecord(TypedDict): + checksum: str + proofIndex: str + proofSubtree: int + size: int + +class InclusionProof(TypedDict): + proofIndex: ProofIndex + proofSubtree: ProofSubtree + indexRecord: IndexRecord + +class Proof(TypedDict): + verifierData: VerifierData + inclusionProof: InclusionProof + +class DealInfo(TypedDict): + dealId: int + storageProvider: str + proof: Proof + +class PODSIData(TypedDict): + pieceCID: str + dealInfo: List[DealInfo] + +def get_proof(cid: str) -> PODSIData: + try: + response = requests.get(f"{Config.lighthouse_api}/api/lighthouse/get_proof?cid={cid}") + + if not response.ok: + if response.status_code == 400: + raise Exception("Proof Doesn't exist yet") + raise Exception(f"Request failed with status code {response.status_code}") + + data = response.json() + return data + + except requests.RequestException as error: + if hasattr(error, 'response') and error.response and error.response.status_code == 400: + raise Exception("Proof Doesn't exist yet") + raise Exception(str(error)) \ No newline at end of file