12
12
import warnings
13
13
from dataclasses import fields
14
14
from pathlib import Path
15
- from typing import Coroutine , Optional , Union
15
+ from typing import Coroutine , Optional , Union , Literal
16
16
17
17
import numpy as np
18
18
import rich
@@ -1671,7 +1671,7 @@ def wallet_ask(
1671
1671
wallet_name : Optional [str ],
1672
1672
wallet_path : Optional [str ],
1673
1673
wallet_hotkey : Optional [str ],
1674
- ask_for : Optional [list [str ]] = None ,
1674
+ ask_for : Optional [list [Literal [ WO . NAME , WO . PATH , WO . HOTKEY ] ]] = None ,
1675
1675
validate : WV = WV .WALLET ,
1676
1676
return_wallet_and_hotkey : bool = False ,
1677
1677
) -> Union [Wallet , tuple [Wallet , str ]]:
@@ -3798,11 +3798,11 @@ def stake_remove(
3798
3798
"Interactive mode cannot be used with hotkey selection options like "
3799
3799
"--include-hotkeys, --exclude-hotkeys, --all-hotkeys, or --hotkey."
3800
3800
)
3801
- raise typer . Exit ()
3801
+ return False
3802
3802
3803
3803
if unstake_all and unstake_all_alpha :
3804
3804
print_error ("Cannot specify both unstake-all and unstake-all-alpha." )
3805
- raise typer . Exit ()
3805
+ return False
3806
3806
3807
3807
if not interactive and not unstake_all and not unstake_all_alpha :
3808
3808
netuid = get_optional_netuid (netuid , all_netuids )
@@ -3811,23 +3811,39 @@ def stake_remove(
3811
3811
"You have specified hotkeys to include and also the `--all-hotkeys` flag. The flag"
3812
3812
" should only be used standalone (to use all hotkeys) or with `--exclude-hotkeys`."
3813
3813
)
3814
- raise typer . Exit ()
3814
+ return False
3815
3815
3816
3816
if include_hotkeys and exclude_hotkeys :
3817
3817
print_error (
3818
3818
"You have specified both including and excluding hotkeys options. Select one or the other."
3819
3819
)
3820
- raise typer . Exit ()
3820
+ return False
3821
3821
3822
3822
if unstake_all and amount :
3823
3823
print_error (
3824
3824
"Cannot specify both a specific amount and 'unstake-all'. Choose one or the other."
3825
3825
)
3826
- raise typer . Exit ()
3826
+ return False
3827
3827
3828
3828
if amount and amount <= 0 :
3829
3829
print_error (f"You entered an incorrect unstake amount: { amount } " )
3830
- raise typer .Exit ()
3830
+ return False
3831
+
3832
+ if include_hotkeys :
3833
+ include_hotkeys = parse_to_list (
3834
+ include_hotkeys ,
3835
+ str ,
3836
+ "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--include-hotkeys hk1,hk2`." ,
3837
+ is_ss58 = False ,
3838
+ )
3839
+
3840
+ if exclude_hotkeys :
3841
+ exclude_hotkeys = parse_to_list (
3842
+ exclude_hotkeys ,
3843
+ str ,
3844
+ "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--exclude-hotkeys hk3,hk4`." ,
3845
+ is_ss58 = False ,
3846
+ )
3831
3847
3832
3848
if (
3833
3849
not wallet_hotkey
@@ -3844,7 +3860,8 @@ def stake_remove(
3844
3860
default = self .config .get ("wallet_name" ) or defaults .wallet .name ,
3845
3861
)
3846
3862
hotkey_or_ss58 = Prompt .ask (
3847
- "Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake from [dim](or Press Enter to view existing staked hotkeys)[/dim]" ,
3863
+ "Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake from [dim]"
3864
+ "(or Press Enter to view existing staked hotkeys)[/dim]" ,
3848
3865
)
3849
3866
if hotkey_or_ss58 == "" :
3850
3867
wallet = self .wallet_ask (
@@ -3875,12 +3892,12 @@ def stake_remove(
3875
3892
if include_hotkeys :
3876
3893
if len (include_hotkeys ) > 1 :
3877
3894
print_error ("Cannot unstake_all from multiple hotkeys at once." )
3878
- raise typer . Exit ()
3895
+ return False
3879
3896
elif is_valid_ss58_address (include_hotkeys [0 ]):
3880
3897
hotkey_ss58_address = include_hotkeys [0 ]
3881
3898
else :
3882
3899
print_error ("Invalid hotkey ss58 address." )
3883
- raise typer . Exit ()
3900
+ return False
3884
3901
elif all_hotkeys :
3885
3902
wallet = self .wallet_ask (
3886
3903
wallet_name ,
@@ -3891,7 +3908,8 @@ def stake_remove(
3891
3908
else :
3892
3909
if not hotkey_ss58_address and not wallet_hotkey :
3893
3910
hotkey_or_ss58 = Prompt .ask (
3894
- "Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake all from [dim](or enter 'all' to unstake from all hotkeys)[/dim]" ,
3911
+ "Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake all from [dim]"
3912
+ "(or enter 'all' to unstake from all hotkeys)[/dim]" ,
3895
3913
default = self .config .get ("wallet_hotkey" )
3896
3914
or defaults .wallet .hotkey ,
3897
3915
)
@@ -3957,22 +3975,23 @@ def stake_remove(
3957
3975
ask_for = [WO .NAME , WO .PATH , WO .HOTKEY ],
3958
3976
validate = WV .WALLET_AND_HOTKEY ,
3959
3977
)
3960
-
3961
- if include_hotkeys :
3962
- include_hotkeys = parse_to_list (
3963
- include_hotkeys ,
3964
- str ,
3965
- "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--include-hotkeys hk1,hk2`." ,
3966
- is_ss58 = False ,
3978
+ if not amount and not prompt :
3979
+ print_error (
3980
+ f"Ambiguous request! Specify [{ COLORS .G .ARG } ]--amount[/{ COLORS .G .ARG } ], "
3981
+ f"[{ COLORS .G .ARG } ]--all[/{ COLORS .G .ARG } ], "
3982
+ f"or [{ COLORS .G .ARG } ]--all-alpha[/{ COLORS .G .ARG } ] to use [{ COLORS .G .ARG } ]--no-prompt[/{ COLORS .G .ARG } ]"
3967
3983
)
3984
+ return False
3968
3985
3969
- if exclude_hotkeys :
3970
- exclude_hotkeys = parse_to_list (
3971
- exclude_hotkeys ,
3972
- str ,
3973
- "Hotkeys must be a comma-separated list of ss58s or names, e.g., `--exclude-hotkeys hk3,hk4`." ,
3974
- is_ss58 = False ,
3986
+ if not amount and json_output :
3987
+ json_console .print_json (
3988
+ data = {
3989
+ "success" : False ,
3990
+ "err_msg" : "Ambiguous request! Specify '--amount', '--all', "
3991
+ "or '--all-alpha' to use '--json-output'" ,
3992
+ }
3975
3993
)
3994
+ return False
3976
3995
3977
3996
return self ._run_command (
3978
3997
remove_stake .unstake (
0 commit comments