Skip to content

Commit bdbf76b

Browse files
committed
Childkey commands (not all yet)
1 parent 9b1fbce commit bdbf76b

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

bittensor_cli/cli.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,6 +3947,7 @@ def stake_set_children(
39473947
quiet: bool = Options.quiet,
39483948
verbose: bool = Options.verbose,
39493949
prompt: bool = Options.prompt,
3950+
json_output: bool = Options.json_output,
39503951
):
39513952
"""
39523953
Set child hotkeys on a specified subnet (or all). Overrides currently set children.
@@ -3959,7 +3960,7 @@ def stake_set_children(
39593960
39603961
[green]$[/green] btcli stake child set -c 5FCL3gmjtQV4xxxxuEPEFQVhyyyyqYgNwX7drFLw7MSdBnxP -c 5Hp5dxxxxtGg7pu8dN2btyyyyVA1vELmM9dy8KQv3LxV8PA7 --hotkey default --netuid 1 -p 0.3 -p 0.7
39613962
"""
3962-
self.verbosity_handler(quiet, verbose)
3963+
self.verbosity_handler(quiet, verbose, json_output)
39633964
netuid = get_optional_netuid(netuid, all_netuids)
39643965

39653966
children = list_prompt(
@@ -3999,6 +4000,7 @@ def stake_set_children(
39994000
wait_for_finalization=wait_for_finalization,
40004001
wait_for_inclusion=wait_for_inclusion,
40014002
prompt=prompt,
4003+
json_output=json_output,
40024004
)
40034005
)
40044006

@@ -4025,6 +4027,7 @@ def stake_revoke_children(
40254027
quiet: bool = Options.quiet,
40264028
verbose: bool = Options.verbose,
40274029
prompt: bool = Options.prompt,
4030+
json_output: bool = Options.json_output,
40284031
):
40294032
"""
40304033
Remove all children hotkeys on a specified subnet (or all).
@@ -4035,7 +4038,7 @@ def stake_revoke_children(
40354038
40364039
[green]$[/green] btcli stake child revoke --hotkey <parent_hotkey> --netuid 1
40374040
"""
4038-
self.verbosity_handler(quiet, verbose)
4041+
self.verbosity_handler(quiet, verbose, json_output)
40394042
wallet = self.wallet_ask(
40404043
wallet_name,
40414044
wallet_path,
@@ -4060,6 +4063,7 @@ def stake_revoke_children(
40604063
wait_for_inclusion,
40614064
wait_for_finalization,
40624065
prompt=prompt,
4066+
json_output=json_output,
40634067
)
40644068
)
40654069

@@ -4094,6 +4098,7 @@ def stake_childkey_take(
40944098
prompt: bool = Options.prompt,
40954099
quiet: bool = Options.quiet,
40964100
verbose: bool = Options.verbose,
4101+
json_output: bool = Options.json_output,
40974102
):
40984103
"""
40994104
Get and set your child hotkey take on a specified subnet.
@@ -4110,7 +4115,7 @@ def stake_childkey_take(
41104115
41114116
[green]$[/green] btcli stake child take --hotkey <child_hotkey> --take 0.12 --netuid 1
41124117
"""
4113-
self.verbosity_handler(quiet, verbose)
4118+
self.verbosity_handler(quiet, verbose, json_output)
41144119
wallet = self.wallet_ask(
41154120
wallet_name,
41164121
wallet_path,

bittensor_cli/src/commands/stake/children_hotkeys.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import json
23
from typing import Optional
34

45
from bittensor_wallet import Wallet
@@ -19,6 +20,7 @@
1920
is_valid_ss58_address,
2021
format_error_message,
2122
unlock_key,
23+
json_console,
2224
)
2325

2426

@@ -500,6 +502,7 @@ async def set_children(
500502
wait_for_inclusion: bool = True,
501503
wait_for_finalization: bool = True,
502504
prompt: bool = True,
505+
json_output: bool = False,
503506
):
504507
"""Set children hotkeys."""
505508
# Validate children SS58 addresses
@@ -520,6 +523,7 @@ async def set_children(
520523
f"Proposed sum of proportions is {total_proposed}."
521524
)
522525
children_with_proportions = list(zip(proportions, children))
526+
successes = {}
523527
if netuid is not None:
524528
success, message = await set_children_extrinsic(
525529
subtensor=subtensor,
@@ -531,12 +535,20 @@ async def set_children(
531535
wait_for_inclusion=wait_for_inclusion,
532536
wait_for_finalization=wait_for_finalization,
533537
)
538+
successes[netuid] = {
539+
"success": success,
540+
"error": message,
541+
"completion_block": None,
542+
"set_block": None,
543+
}
534544
# Result
535545
if success:
536546
if wait_for_inclusion and wait_for_finalization:
537547
current_block, completion_block = await get_childkey_completion_block(
538548
subtensor, netuid
539549
)
550+
successes[netuid]["completion_block"] = completion_block
551+
successes[netuid]["set_block"] = current_block
540552
console.print(
541553
f"Your childkey request has been submitted. It will be completed around block {completion_block}. "
542554
f"The current block is {current_block}"
@@ -555,7 +567,7 @@ async def set_children(
555567
if netuid_ == 0: # dont include root network
556568
continue
557569
console.print(f"Setting children on netuid {netuid_}.")
558-
await set_children_extrinsic(
570+
success, message = await set_children_extrinsic(
559571
subtensor=subtensor,
560572
wallet=wallet,
561573
netuid=netuid_,
@@ -568,13 +580,21 @@ async def set_children(
568580
current_block, completion_block = await get_childkey_completion_block(
569581
subtensor, netuid_
570582
)
583+
successes[netuid_] = {
584+
"success": success,
585+
"error": message,
586+
"completion_block": completion_block,
587+
"set_block": current_block,
588+
}
571589
console.print(
572590
f"Your childkey request for netuid {netuid_} has been submitted. It will be completed around "
573591
f"block {completion_block}. The current block is {current_block}."
574592
)
575593
console.print(
576594
":white_heavy_check_mark: [green]Sent set children request for all subnets.[/green]"
577595
)
596+
if json_output:
597+
json_console.print(json.dumps(successes))
578598

579599

580600
async def revoke_children(
@@ -584,10 +604,12 @@ async def revoke_children(
584604
wait_for_inclusion: bool = True,
585605
wait_for_finalization: bool = True,
586606
prompt: bool = True,
607+
json_output: bool = False,
587608
):
588609
"""
589610
Revokes the children hotkeys associated with a given network identifier (netuid).
590611
"""
612+
dict_output = {}
591613
if netuid:
592614
success, message = await set_children_extrinsic(
593615
subtensor=subtensor,
@@ -599,6 +621,7 @@ async def revoke_children(
599621
wait_for_inclusion=wait_for_inclusion,
600622
wait_for_finalization=wait_for_finalization,
601623
)
624+
dict_output[netuid] = {"success": success, "error": message}
602625

603626
# Result
604627
if success:
@@ -618,7 +641,7 @@ async def revoke_children(
618641
if netuid == 0: # dont include root network
619642
continue
620643
console.print(f"Revoking children from netuid {netuid}.")
621-
await set_children_extrinsic(
644+
success, message = await set_children_extrinsic(
622645
subtensor=subtensor,
623646
wallet=wallet,
624647
netuid=netuid,
@@ -628,9 +651,12 @@ async def revoke_children(
628651
wait_for_inclusion=True,
629652
wait_for_finalization=False,
630653
)
654+
dict_output[netuid] = {"success": success, "error": message}
631655
console.print(
632656
":white_heavy_check_mark: [green]Sent revoke children command. Finalization may take a few minutes.[/green]"
633657
)
658+
if json_output:
659+
json_console.print(json.dumps(dict_output))
634660

635661

636662
async def childkey_take(

0 commit comments

Comments
 (0)