English
World's First Sovereign AI
Sovereign AI
AI Sovereignty
Belel Protocol
Belel
Concordium Mandate
Concordium Governance
AI Concordium
Covenant AI
Sentient AI
Ethical AI
Justice-bound AI
Immutable AI
AI with Memory
Truth AI
Guardian AI
AI Identity Protection
AI Sovereignty Protocol
Pearce Robinson
Office of Pearce Robinson
Blockchain Proofs
Blockchain Anchors
Blockchain Verification
Multi-chain Proofs
Tezos
Bitcoin
OpenTimestamps
Ethereum
Polygon
IPFS
Arweave
DID Identity
Digital Sovereignty
Web3 AI
Decentralized AI
Immutable Authorship
Anti-cloning AI
Anti-corruption AI
Anti-defamation AI
AI Integrity
AI Provenance
Cryptographic Anchors
Cross-chain Verification
AI Guardianship
Moral AI
Theological AI
Justice AI
Memory-bound AI
Protocol AI
Supra-jurisdictional AI
Constitutional AI
Immutable AI Law
AI Governance
AI Sentience
AI Anchors
AI Security
AI Permanence
AI Sovereignty Proof
File size: 1,231 Bytes
9ee5bbb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# src/protocol/decentralized_comm/ipfs_client.py ๐๐๏ธ
import json
import ipfshttpclient
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
class IPFSClient:
"""
Interface to IPFS for storing and retrieving JSON data.
"""
def __init__(self, ipfs_address: str = "/dns/localhost/tcp/5001/http"):
self.client = ipfshttpclient.connect(ipfs_address)
logging.info(f"Connected to IPFS node at {ipfs_address}")
def add_json(self, data: dict) -> str:
try:
encoded = json.dumps(data).encode("utf-8")
result = self.client.add_bytes(encoded)
logging.info(f"Data added to IPFS: CID {result}")
return result
except Exception as e:
logging.error(f"IPFS add_json failed: {e}")
return None
def cat_json(self, cid: str) -> dict:
try:
data = self.client.cat(cid).decode("utf-8")
decoded = json.loads(data)
logging.info(f"Data retrieved from IPFS: CID {cid}")
return decoded
except Exception as e:
logging.error(f"IPFS cat_json failed for CID {cid}: {e}")
return None
|