From 08f4587611021117b1474b981185a964e1eed8c1 Mon Sep 17 00:00:00 2001 From: Dairus Date: Sun, 28 Dec 2025 19:57:22 +0100 Subject: [PATCH 1/2] Add example for handling commitment data Added an example of handling realistic commitment data in the subtensor module. --- bittensor/core/subtensor.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index 6862f3a1c4..dd67c6ec3a 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -1571,6 +1571,40 @@ def get_commitment(self, netuid: int, uid: int, block: Optional[int] = None) -> # TODO: add a real example of how to handle realistic commitment data, or chop example + + Example: + import bittensor as bt + import json + + wallet = bt.Wallet() + subtensor = bt.Subtensor(network="test") + netuid = 1 + + # Realistic commitment data often includes versioning and content hashes + commitment_data = { + "version": "1.0.0", + "model_hash": "QmX...", # IPFS hash or similar + "timestamp": 1234567890 + } + + # Convert to string for storage + data_str = json.dumps(commitment_data) + + # Set commitment + # Note: This requires the wallet to be a registered neuron on the subnet + subtensor.set_commitment(wallet=wallet, netuid=netuid, data=data_str) + + # Retrieve commitment + uid = 123 + retrieved_data_str = subtensor.get_commitment(netuid=netuid, uid=uid) + + if retrieved_data_str: + try: + # Parse back to dictionary + retrieved_data = json.loads(retrieved_data_str) + print(f"Retrieved version: {retrieved_data.get('version')}") + except json.JSONDecodeError: + print("Failed to decode commitment data") Notes: - From 3c74c535918527a94429c0aa76e5212a04d7d175 Mon Sep 17 00:00:00 2001 From: Dairus Date: Sun, 28 Dec 2025 20:12:54 +0100 Subject: [PATCH 2/2] Clean up docstring in subtensor.py Removed unnecessary comments and whitespace in the docstring. --- bittensor/core/subtensor.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index dd67c6ec3a..bea5bb0095 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -1568,10 +1568,7 @@ def get_commitment(self, netuid: int, uid: int, block: Optional[int] = None) -> Returns: The commitment data as a string. - - - # TODO: add a real example of how to handle realistic commitment data, or chop example - + Example: import bittensor as bt import json