1
1
import asyncio
2
+ import json
2
3
from typing import Optional
3
4
4
5
from bittensor_wallet import Wallet
19
20
is_valid_ss58_address ,
20
21
format_error_message ,
21
22
unlock_key ,
23
+ json_console ,
22
24
)
23
25
24
26
@@ -500,6 +502,7 @@ async def set_children(
500
502
wait_for_inclusion : bool = True ,
501
503
wait_for_finalization : bool = True ,
502
504
prompt : bool = True ,
505
+ json_output : bool = False ,
503
506
):
504
507
"""Set children hotkeys."""
505
508
# Validate children SS58 addresses
@@ -520,6 +523,7 @@ async def set_children(
520
523
f"Proposed sum of proportions is { total_proposed } ."
521
524
)
522
525
children_with_proportions = list (zip (proportions , children ))
526
+ successes = {}
523
527
if netuid is not None :
524
528
success , message = await set_children_extrinsic (
525
529
subtensor = subtensor ,
@@ -531,12 +535,20 @@ async def set_children(
531
535
wait_for_inclusion = wait_for_inclusion ,
532
536
wait_for_finalization = wait_for_finalization ,
533
537
)
538
+ successes [netuid ] = {
539
+ "success" : success ,
540
+ "error" : message ,
541
+ "completion_block" : None ,
542
+ "set_block" : None ,
543
+ }
534
544
# Result
535
545
if success :
536
546
if wait_for_inclusion and wait_for_finalization :
537
547
current_block , completion_block = await get_childkey_completion_block (
538
548
subtensor , netuid
539
549
)
550
+ successes [netuid ]["completion_block" ] = completion_block
551
+ successes [netuid ]["set_block" ] = current_block
540
552
console .print (
541
553
f"Your childkey request has been submitted. It will be completed around block { completion_block } . "
542
554
f"The current block is { current_block } "
@@ -555,7 +567,7 @@ async def set_children(
555
567
if netuid_ == 0 : # dont include root network
556
568
continue
557
569
console .print (f"Setting children on netuid { netuid_ } ." )
558
- await set_children_extrinsic (
570
+ success , message = await set_children_extrinsic (
559
571
subtensor = subtensor ,
560
572
wallet = wallet ,
561
573
netuid = netuid_ ,
@@ -568,13 +580,21 @@ async def set_children(
568
580
current_block , completion_block = await get_childkey_completion_block (
569
581
subtensor , netuid_
570
582
)
583
+ successes [netuid_ ] = {
584
+ "success" : success ,
585
+ "error" : message ,
586
+ "completion_block" : completion_block ,
587
+ "set_block" : current_block ,
588
+ }
571
589
console .print (
572
590
f"Your childkey request for netuid { netuid_ } has been submitted. It will be completed around "
573
591
f"block { completion_block } . The current block is { current_block } ."
574
592
)
575
593
console .print (
576
594
":white_heavy_check_mark: [green]Sent set children request for all subnets.[/green]"
577
595
)
596
+ if json_output :
597
+ json_console .print (json .dumps (successes ))
578
598
579
599
580
600
async def revoke_children (
@@ -584,10 +604,12 @@ async def revoke_children(
584
604
wait_for_inclusion : bool = True ,
585
605
wait_for_finalization : bool = True ,
586
606
prompt : bool = True ,
607
+ json_output : bool = False ,
587
608
):
588
609
"""
589
610
Revokes the children hotkeys associated with a given network identifier (netuid).
590
611
"""
612
+ dict_output = {}
591
613
if netuid :
592
614
success , message = await set_children_extrinsic (
593
615
subtensor = subtensor ,
@@ -599,6 +621,7 @@ async def revoke_children(
599
621
wait_for_inclusion = wait_for_inclusion ,
600
622
wait_for_finalization = wait_for_finalization ,
601
623
)
624
+ dict_output [netuid ] = {"success" : success , "error" : message }
602
625
603
626
# Result
604
627
if success :
@@ -618,7 +641,7 @@ async def revoke_children(
618
641
if netuid == 0 : # dont include root network
619
642
continue
620
643
console .print (f"Revoking children from netuid { netuid } ." )
621
- await set_children_extrinsic (
644
+ success , message = await set_children_extrinsic (
622
645
subtensor = subtensor ,
623
646
wallet = wallet ,
624
647
netuid = netuid ,
@@ -628,9 +651,12 @@ async def revoke_children(
628
651
wait_for_inclusion = True ,
629
652
wait_for_finalization = False ,
630
653
)
654
+ dict_output [netuid ] = {"success" : success , "error" : message }
631
655
console .print (
632
656
":white_heavy_check_mark: [green]Sent revoke children command. Finalization may take a few minutes.[/green]"
633
657
)
658
+ if json_output :
659
+ json_console .print (json .dumps (dict_output ))
634
660
635
661
636
662
async def childkey_take (
0 commit comments