24
24
from rich .prompt import Confirm , Prompt
25
25
from rich .table import Table
26
26
from rich .console import Console
27
+ from rich .text import Text
27
28
from tqdm import tqdm
28
29
29
30
import bittensor
@@ -616,7 +617,13 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
616
617
if not cli .config .is_set ("hotkey" ):
617
618
cli .config .hotkey = Prompt .ask ("Enter parent hotkey (ss58)" )
618
619
619
- children = GetChildrenCommand .run (cli )
620
+ # display children
621
+ GetChildrenCommand .retrieve_children (
622
+ subtensor = subtensor ,
623
+ hotkey = cli .config .hotkey ,
624
+ netuid = cli .config .netuid ,
625
+ render_table = True ,
626
+ )
620
627
621
628
if not cli .config .is_set ("children" ):
622
629
cli .config .children = Prompt .ask (
@@ -661,6 +668,12 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
661
668
662
669
# Result
663
670
if success :
671
+ GetChildrenCommand .retrieve_children (
672
+ subtensor = subtensor ,
673
+ hotkey = cli .config .hotkey ,
674
+ netuid = cli .config .netuid ,
675
+ render_table = True ,
676
+ )
664
677
console .print (
665
678
":white_heavy_check_mark: [green]Set children hotkeys.[/green]"
666
679
)
@@ -765,16 +778,39 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
765
778
766
779
# Get values if not set.
767
780
if not cli .config .is_set ("hotkey" ):
768
- cli .config .netuid = Prompt .ask ("Enter hotkey" )
781
+ cli .config .hotkey = Prompt .ask ("Enter parent hotkey (ss58) " )
769
782
770
783
# Parse from strings
771
784
netuid = cli .config .netuid
772
785
hotkey = cli .config .hotkey
773
786
774
787
children = subtensor .get_children (hotkey , netuid )
775
788
776
- GetChildrenCommand .render_table (subtensor , hotkey , children , netuid )
789
+ GetChildrenCommand .render_table (subtensor , hotkey , children , netuid , True )
790
+
791
+ return children
792
+
793
+ @staticmethod
794
+ def retrieve_children (
795
+ subtensor : "bittensor.subtensor" , hotkey : str , netuid : int , render_table : bool
796
+ ):
797
+ """
798
+
799
+ Static method to retrieve children for a given subtensor.
800
+
801
+ Args:
802
+ subtensor (bittensor.subtensor): The subtensor object used to interact with the Bittensor network.
803
+ hotkey (str): The hotkey of the tensor owner.
804
+ netuid (int): The network unique identifier of the subtensor.
805
+ render_table (bool): Flag indicating whether to render the retrieved children in a table.
806
+
807
+ Returns:
808
+ List[str]: A list of children hotkeys.
777
809
810
+ """
811
+ children = subtensor .get_children (hotkey , netuid )
812
+ if render_table :
813
+ GetChildrenCommand .render_table (subtensor , hotkey , children , netuid , False )
778
814
return children
779
815
780
816
@staticmethod
@@ -803,7 +839,33 @@ def render_table(
803
839
hotkey : str ,
804
840
children : list [Tuple [int , str ]],
805
841
netuid : int ,
842
+ prompt : bool ,
806
843
):
844
+ """
845
+
846
+ Render a table displaying information about child hotkeys on a particular subnet.
847
+
848
+ Parameters:
849
+ - subtensor: An instance of the "bittensor.subtensor" class.
850
+ - hotkey: The hotkey of the parent node.
851
+ - children: A list of tuples containing information about child hotkeys. Each tuple should contain:
852
+ - The proportion of the child's stake relative to the total stake.
853
+ - The hotkey of the child node.
854
+ - netuid: The ID of the subnet.
855
+ - prompt: A boolean indicating whether to display a prompt for adding a child hotkey.
856
+
857
+ Returns:
858
+ None
859
+
860
+ Example Usage:
861
+ subtensor = bittensor.subtensor_instance
862
+ hotkey = "parent_hotkey"
863
+ children = [(0.5, "child1_hotkey"), (0.3, "child2_hotkey"), (0.2, "child3_hotkey")]
864
+ netuid = 1234
865
+ prompt = True
866
+ render_table(subtensor, hotkey, children, netuid, prompt)
867
+
868
+ """
807
869
console = Console ()
808
870
809
871
# Initialize Rich table for pretty printing
@@ -822,12 +884,14 @@ def render_table(
822
884
823
885
if not children :
824
886
console .print (table )
825
-
826
- command = f"btcli stake set_children --children <child_hotkey> --hotkey <parent_hotkey> --netuid { netuid } --proportion <float>"
827
- console .print (f"There are currently no child hotkeys on subnet { netuid } ." )
828
887
console .print (
829
- f"To add a child hotkey you can run the command: [white] { command } [/white] "
888
+ f"There are currently no child hotkeys on subnet { netuid } with ParentHotKey { hotkey } . "
830
889
)
890
+ if prompt :
891
+ command = f"btcli stake set_children --children <child_hotkey> --hotkey <parent_hotkey> --netuid { netuid } --proportion <float>"
892
+ console .print (
893
+ f"To add a child hotkey you can run the command: [white]{ command } [/white]"
894
+ )
831
895
return
832
896
833
897
console .print ("ParentHotKey:" , style = "cyan" , no_wrap = True )
@@ -857,10 +921,14 @@ def render_table(
857
921
858
922
# add the children info to the table
859
923
for i , (proportion , hotkey , stake ) in enumerate (children_info , 1 ):
924
+ proportion_str = Text (
925
+ str (proportion ), style = "red" if proportion == 0 else ""
926
+ )
927
+ hotkey = Text (hotkey , style = "red" if proportion == 0 else "" )
860
928
table .add_row (
861
929
str (i ),
862
930
hotkey ,
863
- str ( proportion ) ,
931
+ proportion_str ,
864
932
str (stake ),
865
933
)
866
934
0 commit comments