Skip to content

Commit fb22b42

Browse files
committed
Subnets show check-in (incomplete)
1 parent c98d8ff commit fb22b42

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

bittensor_cli/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4593,6 +4593,7 @@ def subnets_show(
45934593
quiet: bool = Options.quiet,
45944594
verbose: bool = Options.verbose,
45954595
prompt: bool = Options.prompt,
4596+
json_output: bool = Options.json_output,
45964597
):
45974598
"""
45984599
Displays detailed information about a subnet including participants and their state.
@@ -4601,7 +4602,7 @@ def subnets_show(
46014602
46024603
[green]$[/green] btcli subnets list
46034604
"""
4604-
self.verbosity_handler(quiet, verbose)
4605+
self.verbosity_handler(quiet, verbose, json_output)
46054606
subtensor = self.initialize_chain(network)
46064607
return self._run_command(
46074608
subnets.show(
@@ -4612,6 +4613,7 @@ def subnets_show(
46124613
delegate_selection=False,
46134614
verbose=verbose,
46144615
prompt=prompt,
4616+
json_output=json_output,
46154617
)
46164618
)
46174619

bittensor_cli/src/commands/subnets/subnets.py

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -862,20 +862,22 @@ async def show(
862862
delegate_selection: bool = False,
863863
verbose: bool = False,
864864
prompt: bool = True,
865+
json_output: bool = False,
865866
) -> Optional[str]:
866867
async def show_root():
868+
# TODO json_output for this, don't forget
867869
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
873870

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),
875873
subtensor.get_subnet_state(netuid=0, block_hash=block_hash),
876874
subtensor.query_all_identities(block_hash=block_hash),
877875
subtensor.get_delegate_identities(block_hash=block_hash),
878876
)
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
879881

880882
if root_state is None:
881883
err_console.print("The root subnet does not exist")
@@ -887,12 +889,11 @@ async def show_root():
887889
)
888890
return
889891

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
893893

894894
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",
896897
show_footer=True,
897898
show_edge=False,
898899
header_style="bold white",
@@ -1177,6 +1178,7 @@ async def show_subnet(netuid_: int):
11771178
)
11781179

11791180
rows = []
1181+
json_out_rows = []
11801182
for idx in sorted_indices:
11811183
# Get identity for this uid
11821184
coldkey_identity = identities.get(subnet_state.coldkeys[idx], {}).get(
@@ -1228,6 +1230,22 @@ async def show_subnet(netuid_: int):
12281230
uid_identity, # Identity
12291231
)
12301232
)
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+
)
12311249

12321250
# Add columns to the table
12331251
table.add_column("UID", style="grey89", no_wrap=True, justify="center")
@@ -1320,6 +1338,24 @@ async def show_subnet(netuid_: int):
13201338
if current_burn_cost
13211339
else Balance(0)
13221340
)
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))
13231359

13241360
console.print(
13251361
f"[{COLOR_PALETTE['GENERAL']['SUBHEADING']}]Subnet {netuid_}{subnet_name_display}[/{COLOR_PALETTE['GENERAL']['SUBHEADING']}]"

0 commit comments

Comments
 (0)