@@ -862,20 +862,22 @@ async def show(
862
862
delegate_selection : bool = False ,
863
863
verbose : bool = False ,
864
864
prompt : bool = True ,
865
+ json_output : bool = False ,
865
866
) -> Optional [str ]:
866
867
async def show_root ():
868
+ # TODO json_output for this, don't forget
867
869
block_hash = await subtensor .substrate .get_chain_head ()
868
- all_subnets = await subtensor .all_subnets (block_hash = block_hash )
869
- root_info = next ((s for s in all_subnets if s .netuid == 0 ), None )
870
- if root_info is None :
871
- print_error ("The root subnet does not exist" )
872
- return False
873
870
874
- root_state , identities , old_identities = await asyncio .gather (
871
+ all_subnets , root_state , identities , old_identities = await asyncio .gather (
872
+ subtensor .all_subnets (block_hash = block_hash ),
875
873
subtensor .get_subnet_state (netuid = 0 , block_hash = block_hash ),
876
874
subtensor .query_all_identities (block_hash = block_hash ),
877
875
subtensor .get_delegate_identities (block_hash = block_hash ),
878
876
)
877
+ root_info = next ((s for s in all_subnets if s .netuid == 0 ), None )
878
+ if root_info is None :
879
+ print_error ("The root subnet does not exist" )
880
+ return False
879
881
880
882
if root_state is None :
881
883
err_console .print ("The root subnet does not exist" )
@@ -887,12 +889,11 @@ async def show_root():
887
889
)
888
890
return
889
891
890
- tao_sum = sum (
891
- [root_state .tao_stake [idx ].tao for idx in range (len (root_state .tao_stake ))]
892
- )
892
+ tao_sum = sum (root_state .tao_stake ).tao
893
893
894
894
table = Table (
895
- title = f"[{ COLOR_PALETTE ['GENERAL' ]['HEADER' ]} ]Root Network\n [{ COLOR_PALETTE ['GENERAL' ]['SUBHEADING' ]} ]Network: { subtensor .network } [/{ COLOR_PALETTE ['GENERAL' ]['SUBHEADING' ]} ]\n " ,
895
+ title = f"[{ COLOR_PALETTE .G .HEADER } ]Root Network\n [{ COLOR_PALETTE .G .SUBHEAD } ]"
896
+ f"Network: { subtensor .network } [/{ COLOR_PALETTE .G .SUBHEAD } ]\n " ,
896
897
show_footer = True ,
897
898
show_edge = False ,
898
899
header_style = "bold white" ,
@@ -1177,6 +1178,7 @@ async def show_subnet(netuid_: int):
1177
1178
)
1178
1179
1179
1180
rows = []
1181
+ json_out_rows = []
1180
1182
for idx in sorted_indices :
1181
1183
# Get identity for this uid
1182
1184
coldkey_identity = identities .get (subnet_state .coldkeys [idx ], {}).get (
@@ -1228,6 +1230,22 @@ async def show_subnet(netuid_: int):
1228
1230
uid_identity , # Identity
1229
1231
)
1230
1232
)
1233
+ json_out_rows .append (
1234
+ {
1235
+ "uid" : idx ,
1236
+ "stake" : subnet_state .total_stake [idx ].tao ,
1237
+ "alpha_stake" : subnet_state .alpha_stake [idx ].tao ,
1238
+ "tao_stake" : tao_stake .tao ,
1239
+ "dividends" : subnet_state .dividends [idx ],
1240
+ "incentive" : subnet_state .incentives [idx ],
1241
+ "emissions" : Balance .from_tao (subnet_state .emission [idx ].tao )
1242
+ .set_unit (netuid_ )
1243
+ .tao ,
1244
+ "hotkey" : subnet_state .hotkeys [idx ],
1245
+ "coldkey" : subnet_state .coldkeys [idx ],
1246
+ "identity" : uid_identity ,
1247
+ }
1248
+ )
1231
1249
1232
1250
# Add columns to the table
1233
1251
table .add_column ("UID" , style = "grey89" , no_wrap = True , justify = "center" )
@@ -1320,6 +1338,24 @@ async def show_subnet(netuid_: int):
1320
1338
if current_burn_cost
1321
1339
else Balance (0 )
1322
1340
)
1341
+ output_dict = {
1342
+ "netuid" : netuid_ ,
1343
+ "name" : subnet_name_display ,
1344
+ "owner" : subnet_info .owner_coldkey ,
1345
+ "owner_identity" : owner_identity ,
1346
+ "rate" : subnet_info .price .tao ,
1347
+ "emission" : subnet_info .emission .tao ,
1348
+ "tao_pool" : subnet_info .tao_in .tao ,
1349
+ "alpha_pool" : subnet_info .alpha_in .tao ,
1350
+ "tempo" : {
1351
+ "block_since_last_step" : subnet_info .blocks_since_last_step ,
1352
+ "tempo" : subnet_info .tempo ,
1353
+ },
1354
+ "registration_cost" : current_registration_burn .tao ,
1355
+ "uids" : json_out_rows ,
1356
+ }
1357
+ if json_output :
1358
+ json_console .print (json .dumps (output_dict ))
1323
1359
1324
1360
console .print (
1325
1361
f"[{ COLOR_PALETTE ['GENERAL' ]['SUBHEADING' ]} ]Subnet { netuid_ } { subnet_name_display } [/{ COLOR_PALETTE ['GENERAL' ]['SUBHEADING' ]} ]"
0 commit comments