Skip to content

Commit 9b1fbce

Browse files
committed
More stake commands.
1 parent 3349cf6 commit 9b1fbce

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

bittensor_cli/cli.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import asyncio
33
import curses
44
import importlib
5+
import json
56
import os.path
67
import re
78
import ssl
@@ -3460,6 +3461,7 @@ def stake_move(
34603461
prompt: bool = Options.prompt,
34613462
quiet: bool = Options.quiet,
34623463
verbose: bool = Options.verbose,
3464+
json_output: bool = Options.json_output,
34633465
):
34643466
"""
34653467
Move staked TAO between hotkeys while keeping the same coldkey ownership.
@@ -3481,13 +3483,14 @@ def stake_move(
34813483
34823484
[green]$[/green] btcli stake move
34833485
"""
3484-
self.verbosity_handler(quiet, verbose)
3486+
self.verbosity_handler(quiet, verbose, json_output)
34853487
console.print(
34863488
"[dim]This command moves stake from one hotkey to another hotkey while keeping the same coldkey.[/dim]"
34873489
)
34883490
if not destination_hotkey:
34893491
dest_wallet_or_ss58 = Prompt.ask(
3490-
"Enter the [blue]destination wallet[/blue] where destination hotkey is located or [blue]ss58 address[/blue]"
3492+
"Enter the [blue]destination wallet[/blue] where destination hotkey is located or "
3493+
"[blue]ss58 address[/blue]"
34913494
)
34923495
if is_valid_ss58_address(dest_wallet_or_ss58):
34933496
destination_hotkey = dest_wallet_or_ss58
@@ -3574,7 +3577,7 @@ def stake_move(
35743577
"Enter the [blue]destination subnet[/blue] (netuid) to move stake to"
35753578
)
35763579

3577-
return self._run_command(
3580+
result = self._run_command(
35783581
move_stake.move_stake(
35793582
subtensor=self.initialize_chain(network),
35803583
wallet=wallet,
@@ -3588,6 +3591,9 @@ def stake_move(
35883591
prompt=prompt,
35893592
)
35903593
)
3594+
if json_output:
3595+
json_console.print(json.dumps({"success": result}))
3596+
return result
35913597

35923598
def stake_transfer(
35933599
self,
@@ -3624,6 +3630,7 @@ def stake_transfer(
36243630
prompt: bool = Options.prompt,
36253631
quiet: bool = Options.quiet,
36263632
verbose: bool = Options.verbose,
3633+
json_output: bool = Options.json_output,
36273634
):
36283635
"""
36293636
Transfer stake between coldkeys while keeping the same hotkey ownership.
@@ -3657,10 +3664,10 @@ def stake_transfer(
36573664
Transfer all available stake from origin hotkey:
36583665
[green]$[/green] btcli stake transfer --all --origin-netuid 1 --dest-netuid 2
36593666
"""
3667+
self.verbosity_handler(quiet, verbose, json_output)
36603668
console.print(
36613669
"[dim]This command transfers stake from one coldkey to another while keeping the same hotkey.[/dim]"
36623670
)
3663-
self.verbosity_handler(quiet, verbose)
36643671

36653672
if not dest_ss58:
36663673
dest_ss58 = Prompt.ask(
@@ -3732,7 +3739,7 @@ def stake_transfer(
37323739
"Enter the [blue]destination subnet[/blue] (netuid)"
37333740
)
37343741

3735-
return self._run_command(
3742+
result = self._run_command(
37363743
move_stake.transfer_stake(
37373744
wallet=wallet,
37383745
subtensor=self.initialize_chain(network),
@@ -3746,6 +3753,9 @@ def stake_transfer(
37463753
prompt=prompt,
37473754
)
37483755
)
3756+
if json_output:
3757+
json_console.print(json.dumps({"success": result}))
3758+
return result
37493759

37503760
def stake_swap(
37513761
self,
@@ -3784,6 +3794,7 @@ def stake_swap(
37843794
wait_for_finalization: bool = Options.wait_for_finalization,
37853795
quiet: bool = Options.quiet,
37863796
verbose: bool = Options.verbose,
3797+
json_output: bool = Options.json_output,
37873798
):
37883799
"""
37893800
Swap stake between different subnets while keeping the same coldkey-hotkey pair ownership.
@@ -3805,10 +3816,10 @@ def stake_swap(
38053816
Swap 100 TAO from subnet 1 to subnet 2:
38063817
[green]$[/green] btcli stake swap --wallet-name default --wallet-hotkey default --origin-netuid 1 --dest-netuid 2 --amount 100
38073818
"""
3819+
self.verbosity_handler(quiet, verbose, json_output)
38083820
console.print(
38093821
"[dim]This command moves stake from one subnet to another subnet while keeping the same coldkey-hotkey pair.[/dim]"
38103822
)
3811-
self.verbosity_handler(quiet, verbose)
38123823

38133824
wallet = self.wallet_ask(
38143825
wallet_name,
@@ -3833,7 +3844,7 @@ def stake_swap(
38333844
if not amount and not swap_all:
38343845
amount = FloatPrompt.ask("Enter the [blue]amount[/blue] to swap")
38353846

3836-
return self._run_command(
3847+
result = self._run_command(
38373848
move_stake.swap_stake(
38383849
wallet=wallet,
38393850
subtensor=self.initialize_chain(network),
@@ -3847,6 +3858,9 @@ def stake_swap(
38473858
wait_for_finalization=wait_for_finalization,
38483859
)
38493860
)
3861+
if json_output:
3862+
json_console.print(json.dumps({"success": result}))
3863+
return result
38503864

38513865
def stake_get_children(
38523866
self,
@@ -3868,6 +3882,7 @@ def stake_get_children(
38683882
),
38693883
quiet: bool = Options.quiet,
38703884
verbose: bool = Options.verbose,
3885+
json_output: bool = Options.json_output,
38713886
):
38723887
"""
38733888
Get all the child hotkeys on a specified subnet.
@@ -3879,7 +3894,7 @@ def stake_get_children(
38793894
[green]$[/green] btcli stake child get --netuid 1
38803895
[green]$[/green] btcli stake child get --all-netuids
38813896
"""
3882-
self.verbosity_handler(quiet, verbose)
3897+
self.verbosity_handler(quiet, verbose, json_output)
38833898
wallet = self.wallet_ask(
38843899
wallet_name,
38853900
wallet_path,
@@ -3900,11 +3915,14 @@ def stake_get_children(
39003915
"Enter a netuid (leave blank for all)", default=None, show_default=True
39013916
)
39023917

3903-
return self._run_command(
3918+
result = self._run_command(
39043919
children_hotkeys.get_children(
39053920
wallet, self.initialize_chain(network), netuid
39063921
)
39073922
)
3923+
if json_output:
3924+
json_console.print(json.dumps(result))
3925+
return result
39083926

39093927
def stake_set_children(
39103928
self,

bittensor_cli/src/commands/stake/move.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ async def move_stake(
442442
stake_all: bool,
443443
interactive_selection: bool = False,
444444
prompt: bool = True,
445-
):
445+
) -> bool:
446446
if interactive_selection:
447447
try:
448448
selection = await stake_move_transfer_selection(subtensor, wallet)
@@ -509,8 +509,10 @@ async def move_stake(
509509
if amount_to_move_as_balance > origin_stake_balance:
510510
err_console.print(
511511
f"[red]Not enough stake[/red]:\n"
512-
f" Stake balance: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{origin_stake_balance}[/{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]"
513-
f" < Moving amount: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{amount_to_move_as_balance}[/{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]"
512+
f" Stake balance: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]"
513+
f"{origin_stake_balance}[/{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]"
514+
f" < Moving amount: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]"
515+
f"{amount_to_move_as_balance}[/{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]"
514516
)
515517
return False
516518

@@ -559,13 +561,12 @@ async def move_stake(
559561
console.print(":white_heavy_check_mark: [green]Sent[/green]")
560562
return True
561563
else:
562-
await response.process_events()
563564
if not await response.is_success:
564565
err_console.print(
565566
f"\n:cross_mark: [red]Failed[/red] with error:"
566567
f" {format_error_message(await response.error_message)}"
567568
)
568-
return
569+
return False
569570
else:
570571
console.print(
571572
":white_heavy_check_mark: [dark_sea_green3]Stake moved.[/dark_sea_green3]"
@@ -597,7 +598,7 @@ async def move_stake(
597598
f"Destination Stake:\n [blue]{destination_stake_balance}[/blue] :arrow_right: "
598599
f"[{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{new_destination_stake_balance}"
599600
)
600-
return
601+
return True
601602

602603

603604
async def transfer_stake(
@@ -734,7 +735,6 @@ async def transfer_stake(
734735
console.print(":white_heavy_check_mark: [green]Sent[/green]")
735736
return True
736737

737-
await response.process_events()
738738
if not await response.is_success:
739739
err_console.print(
740740
f":cross_mark: [red]Failed[/red] with error: "
@@ -869,7 +869,8 @@ async def swap_stake(
869869
return False
870870

871871
with console.status(
872-
f"\n:satellite: Swapping stake from netuid [blue]{origin_netuid}[/blue] to netuid [blue]{destination_netuid}[/blue]..."
872+
f"\n:satellite: Swapping stake from netuid [blue]{origin_netuid}[/blue] "
873+
f"to netuid [blue]{destination_netuid}[/blue]..."
873874
):
874875
call = await subtensor.substrate.compose_call(
875876
call_module="SubtensorModule",
@@ -896,7 +897,6 @@ async def swap_stake(
896897
console.print(":white_heavy_check_mark: [green]Sent[/green]")
897898
return True
898899

899-
await response.process_events()
900900
if not await response.is_success:
901901
err_console.print(
902902
f":cross_mark: [red]Failed[/red] with error: "

bittensor_cli/src/commands/stake/remove.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ async def unstake(
4646
json_output: bool,
4747
):
4848
"""Unstake from hotkey(s)."""
49-
unstake_all_from_hk = False
5049
with console.status(
5150
f"Retrieving subnet data & identities from {subtensor.network}...",
5251
spinner="earth",

0 commit comments

Comments
 (0)