diff --git a/README.md b/README.md index 6f4210d..a1c6ee5 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,14 @@ python commit.py commit-repo \ --wallet.hotkey ``` +### Commit CDN URL for PLY file storage +```bash +python commit.py commit-cdn-url \ + --cdn-url \ + --wallet.name \ + --wallet.hotkey +``` + ### List all commitments ```bash python commit.py list-all diff --git a/commit.py b/commit.py index 7f66462..ebfc4db 100644 --- a/commit.py +++ b/commit.py @@ -1,5 +1,6 @@ import asyncio import json +import requests import sys import bittensor as bt @@ -73,6 +74,61 @@ def commit_repo_cmd( ) +@cli.command("commit-cdn-url") +@click.option( + "--cdn-url", + required=True, + help="URL of the S3 compatible object storage that saves the generated PLY files" +) +@click.option("--netuid", default=17, show_default=True) +@click.option( + "--subtensor.endpoint", "subtensor_endpoint", default="finney", show_default=True +) +@click.option("--wallet.name", "wallet_name", required=True) +@click.option("--wallet.hotkey", "wallet_hotkey", required=True) +@click.option("--wallet.path", "wallet_path", default=None) +def commit_cdn_url_cmd( + cdn_url: str, + netuid: int, + subtensor_endpoint: str, + wallet_name: str, + wallet_hotkey: str, + wallet_path: str | None, +) -> None: + """Commit PLY file storage on-chain.""" + try: + response = requests.head(cdn_url, timeout=10) + if not response.ok: + click.echo( + json.dumps( + { + "success": False, + "error": f"CDN URL {cdn_url} is not accessible: {response.status_code}" + } + ) + ) + raise SystemExit(1) + except requests.RequestException as e: + click.echo( + json.dumps( + { + "success": False, + "error": f"CDN URL {cdn_url} is not accessible: {str(e)}" + } + ) + ) + raise SystemExit(1) + + _run_commit( + data={"cdn_url": cdn_url}, + netuid=netuid, + subtensor_endpoint=subtensor_endpoint, + wallet_name=wallet_name, + wallet_hotkey=wallet_hotkey, + wallet_path=wallet_path, + ) + + def _run_commit( *, data: dict, @@ -133,6 +189,7 @@ def _parse_commitments(commitments: dict) -> list[dict]: for hotkey, entries in commitments.items(): latest_commit: tuple[int, str] | None = None latest_repo: tuple[int, str] | None = None + latest_cdn_url: tuple[int, str] | None = None for block, data in entries: try: @@ -148,6 +205,10 @@ def _parse_commitments(commitments: dict) -> list[dict]: if latest_repo is None or block > latest_repo[0]: latest_repo = (block, repo) + if cdn_url := parsed.get("cdn_url"): + if latest_cdn_url is None or block > latest_cdn_url[0]: + latest_cdn_url = (block, cdn_url) + if latest_commit is None: continue @@ -158,6 +219,8 @@ def _parse_commitments(commitments: dict) -> list[dict]: "commit_block": latest_commit[0], "repo": latest_repo[1] if latest_repo else None, "repo_block": latest_repo[0] if latest_repo else None, + "cdn_url": latest_cdn_url[1] if latest_cdn_url else None, + "cdn_url_block": latest_cdn_url[0] if latest_cdn_url else None, } ) diff --git a/requirements.txt b/requirements.txt index 323eb1e..59eaa01 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ bittensor==9.12.2 bittensor-wallet==4.0.1 click==8.3.1 pydantic==2.12.4 -pydantic-settings==2.12.0 \ No newline at end of file +pydantic-settings==2.12.0 +requests==2.32.5 \ No newline at end of file