12
12
import warnings
13
13
from dataclasses import fields
14
14
from pathlib import Path
15
- from typing import Coroutine , Optional
15
+ from typing import Coroutine , Optional , Union
16
16
17
17
import numpy as np
18
18
import rich
@@ -1639,15 +1639,17 @@ def wallet_ask(
1639
1639
wallet_hotkey : Optional [str ],
1640
1640
ask_for : Optional [list [str ]] = None ,
1641
1641
validate : WV = WV .WALLET ,
1642
- ) -> Wallet :
1642
+ return_wallet_and_hotkey : bool = False ,
1643
+ ) -> Union [Wallet , tuple [Wallet , str ]]:
1643
1644
"""
1644
1645
Generates a wallet object based on supplied values, validating the wallet is valid if flag is set
1645
1646
:param wallet_name: name of the wallet
1646
1647
:param wallet_path: root path of the wallets
1647
1648
:param wallet_hotkey: name of the wallet hotkey file
1648
1649
:param validate: flag whether to check for the wallet's validity
1649
1650
:param ask_for: aspect of the wallet (name, path, hotkey) to prompt the user for
1650
- :return: created Wallet object
1651
+ :param return_wallet_and_hotkey: if specified, will return both the wallet object, and the hotkey SS58
1652
+ :return: created Wallet object (or wallet, hotkey ss58)
1651
1653
"""
1652
1654
ask_for = ask_for or []
1653
1655
# Prompt for missing attributes specified in ask_for
@@ -1672,8 +1674,9 @@ def wallet_ask(
1672
1674
)
1673
1675
else :
1674
1676
wallet_hotkey = Prompt .ask (
1675
- "Enter the [blue]wallet hotkey[/blue]"
1676
- + " [dark_sea_green3 italic](Hint: You can set this with `btcli config set --wallet-hotkey`)[/dark_sea_green3 italic]" ,
1677
+ "Enter the [blue]wallet hotkey[/blue][dark_sea_green3 italic]"
1678
+ "(Hint: You can set this with `btcli config set --wallet-hotkey`)"
1679
+ "[/dark_sea_green3 italic]" ,
1677
1680
default = defaults .wallet .hotkey ,
1678
1681
)
1679
1682
if wallet_path :
@@ -1691,7 +1694,8 @@ def wallet_ask(
1691
1694
if WO .PATH in ask_for and not wallet_path :
1692
1695
wallet_path = Prompt .ask (
1693
1696
"Enter the [blue]wallet path[/blue]"
1694
- + " [dark_sea_green3 italic](Hint: You can set this with `btcli config set --wallet-path`)[/dark_sea_green3 italic]" ,
1697
+ "[dark_sea_green3 italic](Hint: You can set this with `btcli config set --wallet-path`)"
1698
+ "[/dark_sea_green3 italic]" ,
1695
1699
default = defaults .wallet .path ,
1696
1700
)
1697
1701
# Create the Wallet object
@@ -1715,7 +1719,25 @@ def wallet_ask(
1715
1719
f"Please verify your wallet information: { wallet } [/red]"
1716
1720
)
1717
1721
raise typer .Exit ()
1718
- return wallet
1722
+ if return_wallet_and_hotkey :
1723
+ valid = utils .is_valid_wallet (wallet )
1724
+ if valid [1 ]:
1725
+ return wallet , wallet .hotkey .ss58_address
1726
+ else :
1727
+ hotkey = (
1728
+ Prompt .ask (
1729
+ "Enter the SS58 of the hotkey to use for this transaction."
1730
+ )
1731
+ ).strip ()
1732
+ if not is_valid_ss58_address (hotkey ):
1733
+ err_console .print (
1734
+ f"[red]Error: { hotkey } is not valid SS58 address."
1735
+ )
1736
+ raise typer .Exit (1 )
1737
+ else :
1738
+ return wallet , hotkey
1739
+ else :
1740
+ return wallet
1719
1741
1720
1742
def wallet_list (
1721
1743
self ,
@@ -5834,18 +5856,13 @@ def liquidity_add(
5834
5856
show_default = False ,
5835
5857
)
5836
5858
5837
- if not wallet_name :
5838
- wallet_name = Prompt .ask (
5839
- "Enter the [blue]wallet name[/blue]" ,
5840
- default = self .config .get ("wallet_name" ) or defaults .wallet .name ,
5841
- )
5842
-
5843
- wallet = self .wallet_ask (
5859
+ wallet , hotkey = self .wallet_ask (
5844
5860
wallet_name = wallet_name ,
5845
5861
wallet_path = wallet_path ,
5846
5862
wallet_hotkey = wallet_hotkey ,
5847
5863
ask_for = [WO .NAME , WO .HOTKEY , WO .PATH ],
5848
- validate = WV .WALLET_AND_HOTKEY ,
5864
+ validate = WV .WALLET ,
5865
+ return_wallet_and_hotkey = True ,
5849
5866
)
5850
5867
# Determine the liquidity amount.
5851
5868
if liquidity_ :
@@ -5874,6 +5891,7 @@ def liquidity_add(
5874
5891
liquidity .add_liquidity (
5875
5892
subtensor = self .initialize_chain (network ),
5876
5893
wallet = wallet ,
5894
+ hotkey_ss58 = hotkey ,
5877
5895
netuid = netuid ,
5878
5896
liquidity = liquidity_ ,
5879
5897
price_low = price_low ,
@@ -5908,7 +5926,7 @@ def liquidity_list(
5908
5926
wallet_path = wallet_path ,
5909
5927
wallet_hotkey = wallet_hotkey ,
5910
5928
ask_for = [WO .NAME , WO .HOTKEY , WO .PATH ],
5911
- validate = WV .WALLET_AND_HOTKEY ,
5929
+ validate = WV .WALLET ,
5912
5930
)
5913
5931
self ._run_command (
5914
5932
liquidity .show_liquidity_list (
@@ -5961,17 +5979,19 @@ def liquidity_remove(
5961
5979
show_default = False ,
5962
5980
)
5963
5981
5964
- wallet = self .wallet_ask (
5982
+ wallet , hotkey = self .wallet_ask (
5965
5983
wallet_name = wallet_name ,
5966
5984
wallet_path = wallet_path ,
5967
5985
wallet_hotkey = wallet_hotkey ,
5968
5986
ask_for = [WO .NAME , WO .HOTKEY , WO .PATH ],
5969
- validate = WV .WALLET_AND_HOTKEY ,
5987
+ validate = WV .WALLET ,
5988
+ return_wallet_and_hotkey = True ,
5970
5989
)
5971
5990
return self ._run_command (
5972
5991
liquidity .remove_liquidity (
5973
5992
subtensor = self .initialize_chain (network ),
5974
5993
wallet = wallet ,
5994
+ hotkey_ss58 = hotkey ,
5975
5995
netuid = netuid ,
5976
5996
position_id = position_id ,
5977
5997
prompt = prompt ,
@@ -6011,12 +6031,13 @@ def liquidity_modify(
6011
6031
f"Enter the [{ COLORS .G .SUBHEAD_MAIN } ]netuid[/{ COLORS .G .SUBHEAD_MAIN } ] to use" ,
6012
6032
)
6013
6033
6014
- wallet = self .wallet_ask (
6034
+ wallet , hotkey = self .wallet_ask (
6015
6035
wallet_name = wallet_name ,
6016
6036
wallet_path = wallet_path ,
6017
6037
wallet_hotkey = wallet_hotkey ,
6018
6038
ask_for = [WO .NAME , WO .HOTKEY , WO .PATH ],
6019
- validate = WV .WALLET_AND_HOTKEY ,
6039
+ validate = WV .WALLET ,
6040
+ return_wallet_and_hotkey = True ,
6020
6041
)
6021
6042
6022
6043
if not position_id :
@@ -6035,6 +6056,7 @@ def liquidity_modify(
6035
6056
liquidity .modify_liquidity (
6036
6057
subtensor = self .initialize_chain (network ),
6037
6058
wallet = wallet ,
6059
+ hotkey_ss58 = hotkey ,
6038
6060
netuid = netuid ,
6039
6061
position_id = position_id ,
6040
6062
liquidity_delta = liquidity_delta ,
0 commit comments