hippius 0.2.13__tar.gz → 0.2.14__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hippius
3
- Version: 0.2.13
3
+ Version: 0.2.14
4
4
  Summary: Python SDK and CLI for Hippius blockchain storage
5
5
  Home-page: https://github.com/thenervelab/hippius-sdk
6
6
  Author: Dubs
@@ -26,7 +26,7 @@ from hippius_sdk.config import (
26
26
  from hippius_sdk.ipfs import IPFSClient
27
27
  from hippius_sdk.utils import format_cid, format_size, hex_to_ipfs_cid
28
28
 
29
- __version__ = "0.2.13"
29
+ __version__ = "0.2.14"
30
30
  __all__ = [
31
31
  "HippiusClient",
32
32
  "IPFSClient",
@@ -970,26 +970,21 @@ async def handle_ec_files(
970
970
  ):
971
971
  account_address = client.substrate_client._keypair.ss58_address
972
972
  else:
973
- # Try to get the default address
974
- default_address = get_default_address()
975
- if default_address:
976
- account_address = default_address
977
- else:
978
- has_default = get_default_address() is not None
973
+ # Use the active account address instead of default address
974
+ from hippius_sdk.config import get_account_address, get_active_account
979
975
 
980
- error("No account address provided, and client has no keypair.")
976
+ active_account = get_active_account()
977
+ if active_account:
978
+ account_address = get_account_address(active_account)
981
979
 
982
- if has_default:
983
- warning(
984
- "Please provide an account address with '--account_address' or the default address may be invalid."
985
- )
986
- else:
987
- info(
988
- "Please provide an account address with '--account_address' or set a default with:"
989
- )
990
- log(
991
- " [bold green underline]hippius address set-default <your_account_address>[/bold green underline]"
992
- )
980
+ if not account_address:
981
+ error("No account address provided and client has no keypair.")
982
+ info(
983
+ "Please provide an account address with '--account_address' or set an active account with:"
984
+ )
985
+ log(
986
+ " [bold green underline]hippius account switch <account_name>[/bold green underline]"
987
+ )
993
988
  return 1
994
989
 
995
990
  info(f"Getting erasure-coded files for account: [bold]{account_address}[/bold]")
@@ -1751,6 +1751,7 @@ class IPFSClient:
1751
1751
  cancel_from_blockchain: bool = True,
1752
1752
  parallel_limit: int = 20,
1753
1753
  seed_phrase: Optional[str] = None,
1754
+ metadata_timeout: int = 30, # Timeout in seconds for metadata fetch
1754
1755
  ) -> bool:
1755
1756
  """
1756
1757
  Delete an erasure-coded file, including all its chunks in parallel.
@@ -1760,30 +1761,49 @@ class IPFSClient:
1760
1761
  cancel_from_blockchain: Whether to cancel storage from blockchain
1761
1762
  parallel_limit: Maximum number of concurrent deletion operations
1762
1763
  seed_phrase: Optional seed phrase to use for blockchain interactions (uses config if None)
1764
+ metadata_timeout: Timeout in seconds for metadata fetch operation (default: 30)
1763
1765
 
1764
1766
  Returns:
1765
1767
  bool: True if the deletion was successful, False otherwise
1766
1768
  """
1769
+ print(f"Starting deletion process for metadata CID: {metadata_cid}")
1767
1770
 
1768
1771
  # Try to download and process metadata file and chunks
1769
1772
  ipfs_failure = False
1770
1773
  metadata_error = False
1774
+ chunks = []
1771
1775
 
1772
1776
  try:
1773
- # First download the metadata to get chunk CIDs
1777
+ # First download the metadata to get chunk CIDs with timeout
1774
1778
  try:
1775
- metadata_result = await self.cat(metadata_cid)
1776
- metadata_json = json.loads(metadata_result["content"].decode("utf-8"))
1777
- chunks = metadata_json.get("chunks", [])
1778
- except json.JSONDecodeError:
1779
+ print("Attempting to fetch metadata file...")
1780
+ # Create a task for fetching metadata with timeout
1781
+ metadata_task = asyncio.create_task(self.cat(metadata_cid))
1782
+ try:
1783
+ metadata_result = await asyncio.wait_for(
1784
+ metadata_task, timeout=metadata_timeout
1785
+ )
1786
+ print(
1787
+ f"Successfully fetched metadata (size: {len(metadata_result['content'])} bytes)"
1788
+ )
1789
+
1790
+ # Parse the metadata JSON
1791
+ metadata_json = json.loads(
1792
+ metadata_result["content"].decode("utf-8")
1793
+ )
1794
+ chunks = metadata_json.get("chunks", [])
1795
+ print(f"Found {len(chunks)} chunks in metadata")
1796
+ except asyncio.TimeoutError:
1797
+ print(
1798
+ f"Timed out after {metadata_timeout}s waiting for metadata download"
1799
+ )
1800
+ # We'll continue with blockchain cancellation even without metadata
1801
+ except json.JSONDecodeError as e:
1779
1802
  # If we can't parse the metadata JSON, record the error but continue
1780
- metadata_error = True
1781
- # Continue with empty chunks so we can at least try to unpin the metadata file
1782
- chunks = []
1783
- except Exception:
1803
+ print(f"Error parsing metadata JSON: {e}")
1804
+ except Exception as e:
1784
1805
  # Any other metadata error
1785
- metadata_error = True
1786
- chunks = []
1806
+ print(f"Error retrieving or processing metadata: {e}")
1787
1807
 
1788
1808
  # Extract all chunk CIDs
1789
1809
  chunk_cids = []
@@ -1794,54 +1814,79 @@ class IPFSClient:
1794
1814
  elif isinstance(chunk_cid, str):
1795
1815
  chunk_cids.append(chunk_cid)
1796
1816
 
1817
+ print(f"Extracted {len(chunk_cids)} CIDs from chunks")
1818
+
1797
1819
  # Create a semaphore to limit concurrent operations
1798
1820
  semaphore = asyncio.Semaphore(parallel_limit)
1799
1821
 
1800
- # Define the unpin task for each chunk with error handling
1822
+ # Define the unpin task for each chunk with error handling and timeout
1801
1823
  async def unpin_chunk(cid):
1802
1824
  async with semaphore:
1803
1825
  try:
1804
- await self.client.unpin(cid)
1826
+ # Add a timeout for each unpin operation
1827
+ unpin_task = asyncio.create_task(self.client.unpin(cid))
1828
+ await asyncio.wait_for(
1829
+ unpin_task, timeout=10
1830
+ ) # 10-second timeout per unpin
1805
1831
  return {"success": True, "cid": cid}
1806
- except Exception:
1832
+ except asyncio.TimeoutError:
1833
+ print(f"Unpin operation timed out for CID: {cid}")
1834
+ return {"success": False, "cid": cid, "error": "timeout"}
1835
+ except Exception as e:
1807
1836
  # Record failure but continue with other chunks
1808
- return {"success": False, "cid": cid}
1837
+ print(f"Error unpinning CID {cid}: {str(e)}")
1838
+ return {"success": False, "cid": cid, "error": str(e)}
1809
1839
 
1810
1840
  # Unpin all chunks in parallel
1811
1841
  if chunk_cids:
1842
+ print(f"Starting parallel unpin of {len(chunk_cids)} chunks...")
1812
1843
  unpin_tasks = [unpin_chunk(cid) for cid in chunk_cids]
1813
1844
  results = await asyncio.gather(*unpin_tasks)
1814
1845
 
1815
1846
  # Count failures
1816
1847
  failures = [r for r in results if not r["success"]]
1817
1848
  if failures:
1818
- ipfs_failure = True
1819
- except Exception:
1849
+ print(f"Failed to unpin {len(failures)} chunks")
1850
+ else:
1851
+ print("Successfully unpinned all chunks")
1852
+ except Exception as e:
1820
1853
  # If we can't process chunks at all, record the failure
1821
- ipfs_failure = True
1854
+ print(f"Exception during chunks processing: {e}")
1822
1855
 
1823
1856
  # Unpin the metadata file itself, regardless of whether we could process chunks
1824
1857
  try:
1825
- await self.client.unpin(metadata_cid)
1826
- except Exception:
1858
+ print(f"Unpinning metadata file: {metadata_cid}")
1859
+ unpin_task = asyncio.create_task(self.client.unpin(metadata_cid))
1860
+ await asyncio.wait_for(unpin_task, timeout=10) # 10-second timeout
1861
+ print("Successfully unpinned metadata file")
1862
+ except Exception as e:
1827
1863
  # Record the failure but continue with blockchain cancellation
1828
- ipfs_failure = True
1864
+ print(f"Error unpinning metadata file: {e}")
1829
1865
 
1830
1866
  # Handle blockchain cancellation if requested
1831
1867
  if cancel_from_blockchain:
1832
- # Create a substrate client
1833
- substrate_client = SubstrateClient()
1834
-
1835
- # This will raise appropriate exceptions if it fails:
1836
- # - HippiusAlreadyDeletedError if already deleted
1837
- # - HippiusFailedSubstrateDelete if transaction fails
1838
- # - Other exceptions for other failures
1839
- await substrate_client.cancel_storage_request(
1840
- metadata_cid, seed_phrase=seed_phrase
1841
- )
1868
+ try:
1869
+ # Create a substrate client
1870
+ print("Creating substrate client for blockchain cancellation...")
1871
+ substrate_client = SubstrateClient()
1872
+
1873
+ # This will raise appropriate exceptions if it fails:
1874
+ # - HippiusAlreadyDeletedError if already deleted
1875
+ # - HippiusFailedSubstrateDelete if transaction fails
1876
+ # - Other exceptions for other failures
1877
+ print(f"Cancelling storage request for CID: {metadata_cid}")
1878
+ await substrate_client.cancel_storage_request(
1879
+ metadata_cid, seed_phrase=seed_phrase
1880
+ )
1881
+ print("Successfully cancelled storage request on blockchain")
1882
+ except Exception as e:
1883
+ print(f"Error during blockchain cancellation: {e}")
1884
+ # Re-raise the exception to be handled by the caller
1885
+ raise
1842
1886
 
1843
1887
  # If we get here, either:
1844
1888
  # 1. Blockchain cancellation succeeded (if requested)
1845
1889
  # 2. We weren't doing blockchain cancellation
1846
1890
  # In either case, we report success
1891
+ print("Delete EC file operation completed successfully")
1847
1892
  return True
@@ -141,9 +141,7 @@ class AsyncIPFSClient:
141
141
  Returns:
142
142
  Response from the IPFS node
143
143
  """
144
- pin_ls_url = f"{self.api_url}/api/v0/pin/ls?arg={cid}"
145
- pin_ls_response = await self.client.post(pin_ls_url)
146
- pin_ls_response.raise_for_status()
144
+
147
145
  response = await self.client.post(f"{self.api_url}/api/v0/pin/rm?arg={cid}")
148
146
 
149
147
  response.raise_for_status()
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "hippius"
3
- version = "0.2.13"
3
+ version = "0.2.14"
4
4
  description = "Python SDK and CLI for Hippius blockchain storage"
5
5
  authors = ["Dubs <dubs@dubs.rs>"]
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes