hippius 0.2.6__tar.gz → 0.2.7__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.6
3
+ Version: 0.2.7
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.6"
29
+ __version__ = "0.2.7"
30
30
  __all__ = [
31
31
  "HippiusClient",
32
32
  "IPFSClient",
@@ -236,6 +236,15 @@ def main():
236
236
  force=args.force if hasattr(args, "force") else False,
237
237
  )
238
238
 
239
+ elif args.command == "pin":
240
+ return run_async_handler(
241
+ cli_handlers.handle_pin,
242
+ client,
243
+ args.cid,
244
+ publish=not args.no_publish if hasattr(args, "no_publish") else True,
245
+ miner_ids=miner_ids,
246
+ )
247
+
239
248
  elif args.command == "ec-delete":
240
249
  return run_async_handler(
241
250
  cli_handlers.handle_ec_delete,
@@ -1713,6 +1713,117 @@ async def handle_delete(client: HippiusClient, cid: str, force: bool = False) ->
1713
1713
  return 0
1714
1714
 
1715
1715
 
1716
+ async def handle_pin(
1717
+ client: HippiusClient, cid: str, publish: bool = True, miner_ids=None
1718
+ ) -> int:
1719
+ """Handle the pin command to pin a CID to IPFS and optionally publish to blockchain"""
1720
+ from rich.panel import Panel
1721
+
1722
+ # First check if this CID exists
1723
+ try:
1724
+ exists_result = await client.exists(cid)
1725
+ if not exists_result["exists"]:
1726
+ error(f"CID [bold cyan]{cid}[/bold cyan] not found on IPFS")
1727
+ return 1
1728
+ except Exception as e:
1729
+ warning(f"Error checking if CID exists: {e}")
1730
+ return 1
1731
+
1732
+ # Create operation title based on publish flag
1733
+ if publish:
1734
+ info(
1735
+ f"Preparing to pin and publish content with CID: [bold cyan]{cid}[/bold cyan]"
1736
+ )
1737
+ operation_title = "Pin & Publish Operation"
1738
+ else:
1739
+ info(f"Preparing to pin content with CID: [bold cyan]{cid}[/bold cyan]")
1740
+ operation_title = "Pin Operation"
1741
+
1742
+ # Display operation details
1743
+ operation_details = [
1744
+ f"CID: [bold cyan]{cid}[/bold cyan]",
1745
+ f"Publishing to blockchain: {'Enabled' if publish else 'Disabled'}",
1746
+ ]
1747
+ print_panel("\n".join(operation_details), title=operation_title)
1748
+
1749
+ # Need to authenticate if publishing to blockchain
1750
+ if publish:
1751
+ try:
1752
+ # Ensure we have a keypair for substrate operations
1753
+ _ = client.substrate_client._ensure_keypair()
1754
+ except Exception as e:
1755
+ warning(f"Failed to initialize blockchain client: {str(e)}")
1756
+ warning("Will continue with pinning but blockchain publishing may fail")
1757
+
1758
+ # Show spinner during pinning
1759
+ with console.status(
1760
+ "[cyan]Pinning content to IPFS...[/cyan]", spinner="dots"
1761
+ ) as status:
1762
+ try:
1763
+ # Pin the content to IPFS
1764
+ pin_result = await client.ipfs_client.pin(cid)
1765
+
1766
+ if not pin_result.get("success", False):
1767
+ error(
1768
+ f"Failed to pin content: {pin_result.get('message', 'Unknown error')}"
1769
+ )
1770
+ return 1
1771
+
1772
+ # If publishing to blockchain, do that now
1773
+ if publish:
1774
+ status.update("[cyan]Publishing content to blockchain...[/cyan]")
1775
+
1776
+ # Create a FileInput object for the substrate client
1777
+ from hippius_sdk.substrate import FileInput
1778
+
1779
+ file_input = FileInput(file_hash=cid, file_name=f"pinned_{cid}")
1780
+
1781
+ # Submit the storage request
1782
+ tx_hash = await client.substrate_client.storage_request(
1783
+ files=[file_input], miner_ids=miner_ids
1784
+ )
1785
+
1786
+ # Create result panel with blockchain details
1787
+ gateway_url = f"{client.ipfs_client.gateway}/ipfs/{cid}"
1788
+ panel_details = [
1789
+ f"Successfully pinned and published: [bold cyan]{cid}[/bold cyan]",
1790
+ f"Gateway URL: [bold cyan]{gateway_url}[/bold cyan]",
1791
+ f"Transaction hash: [bold green]{tx_hash}[/bold green]",
1792
+ "\nThis content is now:",
1793
+ "1. Pinned to your IPFS node",
1794
+ "2. Published to the IPFS network",
1795
+ "3. Stored on the Hippius blockchain",
1796
+ ]
1797
+ console.print(
1798
+ Panel(
1799
+ "\n".join(panel_details),
1800
+ title="Operation Complete",
1801
+ border_style="green",
1802
+ )
1803
+ )
1804
+ else:
1805
+ # Just pinning, no blockchain publishing
1806
+ gateway_url = f"{client.ipfs_client.gateway}/ipfs/{cid}"
1807
+ panel_details = [
1808
+ f"Successfully pinned: [bold cyan]{cid}[/bold cyan]",
1809
+ f"Gateway URL: [bold cyan]{gateway_url}[/bold cyan]",
1810
+ "\nThis content is now pinned to your IPFS node.",
1811
+ "It will remain available as long as your node is running.",
1812
+ ]
1813
+ console.print(
1814
+ Panel(
1815
+ "\n".join(panel_details),
1816
+ title="Pinning Complete",
1817
+ border_style="green",
1818
+ )
1819
+ )
1820
+
1821
+ return 0
1822
+ except Exception as e:
1823
+ error(f"Error during operation: {e}")
1824
+ return 1
1825
+
1826
+
1716
1827
  async def handle_ec_delete(
1717
1828
  client: HippiusClient, metadata_cid: str, force: bool = False
1718
1829
  ) -> int:
@@ -63,13 +63,19 @@ examples:
63
63
 
64
64
  # Erasure code without publishing to global IPFS network
65
65
  hippius erasure-code large_file.avi --no-publish
66
-
66
+
67
67
  # Reconstruct an erasure-coded file
68
68
  hippius reconstruct QmMetadataHash reconstructed_file.mp4
69
-
69
+
70
+ # Pin a CID to IPFS and publish to blockchain
71
+ hippius pin QmHash
72
+
73
+ # Pin a CID to IPFS without publishing to blockchain
74
+ hippius pin QmHash --no-publish
75
+
70
76
  # Delete a file from IPFS and marketplace
71
77
  hippius delete QmHash
72
-
78
+
73
79
  # Delete an erasure-coded file and all its chunks
74
80
  hippius ec-delete QmMetadataHash
75
81
  """,
@@ -250,6 +256,23 @@ def add_storage_commands(subparsers):
250
256
  help="Delete without confirmation prompt",
251
257
  )
252
258
 
259
+ # Pin command
260
+ pin_parser = subparsers.add_parser(
261
+ "pin",
262
+ help="Pin a CID to IPFS and publish to blockchain",
263
+ )
264
+ pin_parser.add_argument("cid", help="CID to pin")
265
+ pin_parser.add_argument(
266
+ "--publish",
267
+ action="store_true",
268
+ help="Publish file to IPFS and store on the blockchain (default)",
269
+ )
270
+ pin_parser.add_argument(
271
+ "--no-publish",
272
+ action="store_true",
273
+ help="Don't publish file to blockchain (local pinning only)",
274
+ )
275
+
253
276
  # Keygen command
254
277
  keygen_parser = subparsers.add_parser(
255
278
  "keygen", help="Generate an encryption key for secure file storage"
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "hippius"
3
- version = "0.2.6"
3
+ version = "0.2.7"
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
File without changes