Skip to content

Commit 7fed122

Browse files
committed
Last commands finished.
1 parent 742e479 commit 7fed122

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

bittensor_cli/cli.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5341,6 +5341,7 @@ def weights_reveal(
53415341
"-s",
53425342
help="Corresponding salt for the hash function, e.g. -s 163,241,217 ...",
53435343
),
5344+
json_output: bool = Options.json_output,
53445345
quiet: bool = Options.quiet,
53455346
verbose: bool = Options.verbose,
53465347
prompt: bool = Options.prompt,
@@ -5354,7 +5355,7 @@ def weights_reveal(
53545355
53555356
[green]$[/green] btcli wt reveal --netuid 1 --uids 1,2,3,4 --weights 0.1,0.2,0.3,0.4 --salt 163,241,217,11,161,142,147,189
53565357
"""
5357-
self.verbosity_handler(quiet, verbose)
5358+
self.verbosity_handler(quiet, verbose, json_output)
53585359
uids = list_prompt(uids, int, "UIDs of interest for the specified netuid")
53595360
weights = list_prompt(
53605361
weights, float, "Corresponding weights for the specified UIDs"
@@ -5387,7 +5388,7 @@ def weights_reveal(
53875388
err_console.print(
53885389
"The number of UIDs you specify must match up with the specified number of weights"
53895390
)
5390-
raise typer.Exit()
5391+
return
53915392

53925393
if salt:
53935394
salt = parse_to_list(
@@ -5416,6 +5417,7 @@ def weights_reveal(
54165417
salt,
54175418
__version_as_int__,
54185419
prompt=prompt,
5420+
json_output=json_output,
54195421
)
54205422
)
54215423

@@ -5439,6 +5441,7 @@ def weights_commit(
54395441
"-s",
54405442
help="Corresponding salt for the hash function, e.g. -s 163 -s 241 -s 217 ...",
54415443
),
5444+
json_output: bool = Options.json_output,
54425445
quiet: bool = Options.quiet,
54435446
verbose: bool = Options.verbose,
54445447
prompt: bool = Options.prompt,
@@ -5456,7 +5459,7 @@ def weights_commit(
54565459
[italic]Note[/italic]: This command is used to commit weights for a specific subnet and requires the user to have the necessary
54575460
permissions.
54585461
"""
5459-
self.verbosity_handler(quiet, verbose)
5462+
self.verbosity_handler(quiet, verbose, json_output)
54605463

54615464
if uids:
54625465
uids = parse_to_list(
@@ -5485,7 +5488,7 @@ def weights_commit(
54855488
err_console.print(
54865489
"The number of UIDs you specify must match up with the specified number of weights"
54875490
)
5488-
raise typer.Exit()
5491+
return
54895492

54905493
if salt:
54915494
salt = parse_to_list(
@@ -5512,6 +5515,7 @@ def weights_commit(
55125515
weights,
55135516
salt,
55145517
__version_as_int__,
5518+
json_output=json_output,
55155519
prompt=prompt,
55165520
)
55175521
)

bittensor_cli/src/commands/weights.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import json
23
import os
34
from datetime import datetime, timedelta
45
from typing import TYPE_CHECKING
@@ -9,7 +10,12 @@
910
from rich.prompt import Confirm
1011
from async_substrate_interface.errors import SubstrateRequestException
1112

12-
from bittensor_cli.src.bittensor.utils import err_console, console, format_error_message
13+
from bittensor_cli.src.bittensor.utils import (
14+
err_console,
15+
console,
16+
format_error_message,
17+
json_console,
18+
)
1319
from bittensor_cli.src.bittensor.extrinsics.root import (
1420
convert_weights_and_uids_for_emit,
1521
generate_weight_hash,
@@ -372,6 +378,7 @@ async def reveal_weights(
372378
weights: list[float],
373379
salt: list[int],
374380
version: int,
381+
json_output: bool = False,
375382
prompt: bool = True,
376383
) -> None:
377384
"""Reveal weights for a specific subnet."""
@@ -395,11 +402,13 @@ async def reveal_weights(
395402
subtensor, wallet, netuid, uids_, weights_, list(salt_), version, prompt=prompt
396403
)
397404
success, message = await extrinsic.reveal(weight_uids, weight_vals)
398-
399-
if success:
400-
console.print("Weights revealed successfully")
405+
if json_output:
406+
json_console.print(json.dumps({"success": success, "message": message}))
401407
else:
402-
err_console.print(f"Failed to reveal weights: {message}")
408+
if success:
409+
console.print("Weights revealed successfully")
410+
else:
411+
err_console.print(f"Failed to reveal weights: {message}")
403412

404413

405414
async def commit_weights(
@@ -410,6 +419,7 @@ async def commit_weights(
410419
weights: list[float],
411420
salt: list[int],
412421
version: int,
422+
json_output: bool = False,
413423
prompt: bool = True,
414424
):
415425
"""Commits weights and then reveals them for a specific subnet"""
@@ -429,7 +439,10 @@ async def commit_weights(
429439
subtensor, wallet, netuid, uids_, weights_, list(salt_), version, prompt=prompt
430440
)
431441
success, message = await extrinsic.set_weights_extrinsic()
432-
if success:
433-
console.print("Weights set successfully")
442+
if json_output:
443+
json_console.print(json.dumps({"success": success, "message": message}))
434444
else:
435-
err_console.print(f"Failed to commit weights: {message}")
445+
if success:
446+
console.print("Weights set successfully")
447+
else:
448+
err_console.print(f"Failed to commit weights: {message}")

0 commit comments

Comments
 (0)