Skip to content

Commit 5fbeabb

Browse files
committed
adds cli cmd
1 parent 25ad35a commit 5fbeabb

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

bittensor_cli/cli.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,9 @@ def __init__(self):
716716
self.wallet_app.command(
717717
"new-coldkey", rich_help_panel=HELP_PANELS["WALLET"]["MANAGEMENT"]
718718
)(self.wallet_new_coldkey)
719+
self.wallet_app.command(
720+
"associate-hotkey", rich_help_panel=HELP_PANELS["WALLET"]["MANAGEMENT"]
721+
)(self.wallet_associate_hotkey)
719722
self.wallet_app.command(
720723
"create", rich_help_panel=HELP_PANELS["WALLET"]["MANAGEMENT"]
721724
)(self.wallet_create_wallet)
@@ -2265,6 +2268,64 @@ def wallet_new_hotkey(
22652268
wallets.new_hotkey(wallet, n_words, use_password, uri, overwrite)
22662269
)
22672270

2271+
def wallet_associate_hotkey(
2272+
self,
2273+
wallet_name: Optional[str] = Options.wallet_name,
2274+
wallet_path: Optional[str] = Options.wallet_path,
2275+
wallet_hotkey: Optional[str] = Options.wallet_hotkey_ss58,
2276+
network: Optional[list[str]] = Options.network,
2277+
quiet: bool = Options.quiet,
2278+
verbose: bool = Options.verbose,
2279+
):
2280+
"""
2281+
Associate a hotkey with a wallet(coldkey).
2282+
2283+
USAGE
2284+
2285+
This command is used to associate a hotkey with a wallet(coldkey).
2286+
2287+
EXAMPLE
2288+
2289+
[green]$[/green] btcli wallet associate-hotkey --hotkey-name hotkey_name
2290+
[green]$[/green] btcli wallet associate-hotkey --hotkey-ss58 5DkQ4...
2291+
"""
2292+
self.verbosity_handler(quiet, verbose)
2293+
if not wallet_name:
2294+
wallet_name = Prompt.ask(
2295+
"Enter the [blue]wallet name[/blue] [dim](which you want to associate with the hotkey)[/dim]",
2296+
default=self.config.get("wallet_name") or defaults.wallet.name,
2297+
)
2298+
if not wallet_hotkey:
2299+
hotkey_or_wallet = Prompt.ask(
2300+
"Enter the [blue]hotkey[/blue] name or "
2301+
"[blue]hotkey ss58 address[/blue] [dim](to associate with your coldkey)[/dim]"
2302+
)
2303+
if is_valid_ss58_address(hotkey_or_wallet):
2304+
hotkey_ss58 = hotkey_or_wallet
2305+
wallet = self.wallet_ask(
2306+
wallet_name,
2307+
wallet_path,
2308+
wallet_hotkey,
2309+
ask_for=[WO.NAME, WO.PATH],
2310+
validate=WV.WALLET,
2311+
)
2312+
else:
2313+
wallet = self.wallet_ask(
2314+
wallet_name,
2315+
wallet_path,
2316+
hotkey_or_wallet,
2317+
ask_for=[WO.NAME, WO.PATH, WO.HOTKEY],
2318+
validate=WV.WALLET_AND_HOTKEY,
2319+
)
2320+
hotkey_ss58 = wallet.hotkey.ss58_address
2321+
return self._run_command(
2322+
wallets.associate_hotkey(
2323+
wallet,
2324+
self.initialize_chain(network),
2325+
hotkey_ss58,
2326+
)
2327+
)
2328+
22682329
def wallet_new_coldkey(
22692330
self,
22702331
wallet_name: Optional[str] = Options.wallet_name,

0 commit comments

Comments
 (0)