bittensor
bittensor copied to clipboard
Childkey takes
Description
Implement set_childkey_take functionality in the Bittensor CLI to interact with the newly added chain feature. This allows a coldkey to set the childkey take for a given hotkey on a specific subnet.
Acceptance Criteria
- Implement
set_childkey_takefunction in the Subtensor class - Implement
get_childkey_takefunction in the Subtensor class - Create a new CLI command for setting childkey take
- Create a new CLI command for querying childkey take
- Write unit tests for new functionality
- Update documentation
Tasks
- Implement
set_childkey_takefunction in the Subtensor class
def set_childkey_take(
self,
wallet: "bittensor.wallet",
hotkey: str,
netuid: int,
take: float,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
) -> bool:
# Validate input
if not 0 <= take <= 0.18:
raise ValueError("Take must be between 0 and 0.18")
# Convert take to u16 representation
take_u16 = int(take * 10000)
# Create and send extrinsic
try:
success = self._do_set_childkey_take(
wallet=wallet,
hotkey=hotkey,
netuid=netuid,
take=take_u16,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)
return success
except Exception as e:
bittensor.__console__.print(f":cross_mark: [red]Failed to set childkey take: {e}[/red]")
return False
- Implement
get_childkey_takefunction in the Subtensor class
def get_childkey_take(
self,
hotkey: str,
netuid: int,
block: Optional[int] = None
) -> Optional[float]:
try:
result = self.query_subtensor("ChildkeyTake", block, [hotkey, netuid])
if result is None:
return None
return float(result) / 10000 # Convert from u16 to float
except Exception as e:
bittensor.__console__.print(f":cross_mark: [red]Failed to get childkey take: {e}[/red]")
return None
- Create a new CLI command for setting childkey take
class SetChildkeyTakeCommand:
@staticmethod
def run(cli: "bittensor.cli"):
r"""Set childkey take for a hotkey on a specific subnet."""
wallet = bittensor.wallet(config=cli.config)
subtensor = bittensor.subtensor(config=cli.config)
# Get parameters
hotkey = cli.config.hotkey
netuid = cli.config.netuid
take = cli.config.take
# Set childkey take
success = subtensor.set_childkey_take(
wallet=wallet,
hotkey=hotkey,
netuid=netuid,
take=take,
wait_for_inclusion=cli.config.wait_for_inclusion,
wait_for_finalization=cli.config.wait_for_finalization,
)
if success:
cli.console.print(f"Successfully set childkey take for hotkey {hotkey} on subnet {netuid} to {take}")
else:
cli.console.print(f"Failed to set childkey take for hotkey {hotkey} on subnet {netuid}")
- Create a new CLI command for querying childkey take
class GetChildkeyTakeCommand:
@staticmethod
def run(cli: "bittensor.cli"):
r"""Get childkey take for a hotkey on a specific subnet."""
subtensor = bittensor.subtensor(config=cli.config)
# Get parameters
hotkey = cli.config.hotkey
netuid = cli.config.netuid
# Get childkey take
take = subtensor.get_childkey_take(hotkey=hotkey, netuid=netuid)
if take is not None:
cli.console.print(f"Childkey take for hotkey {hotkey} on subnet {netuid}: {take}")
else:
cli.console.print(f"Failed to get childkey take for hotkey {hotkey} on subnet {netuid}")