Skip to content

Commit 6b794ca

Browse files
committed
Updates wallet_check_ck_swap
1 parent 7ab8b5e commit 6b794ca

File tree

1 file changed

+91
-7
lines changed

1 file changed

+91
-7
lines changed

bittensor_cli/cli.py

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ class Options:
109109
"--wallet.hotkey",
110110
help="Hotkey of the wallet",
111111
)
112+
wallet_ss58_address = typer.Option(
113+
None,
114+
"--wallet-name",
115+
"--name",
116+
"--wallet_name",
117+
"--wallet.name",
118+
"--address",
119+
"--ss58",
120+
"--ss58-address",
121+
help="SS58 address or wallet name to check. Leave empty to be prompted.",
122+
)
112123
wallet_hotkey_ss58 = typer.Option(
113124
None,
114125
"--hotkey",
@@ -687,6 +698,9 @@ def __init__(self):
687698
self.wallet_app.command(
688699
"swap-coldkey", rich_help_panel=HELP_PANELS["WALLET"]["SECURITY"]
689700
)(self.wallet_swap_coldkey)
701+
self.wallet_app.command(
702+
"swap-check", rich_help_panel=HELP_PANELS["WALLET"]["SECURITY"]
703+
)(self.wallet_check_ck_swap)
690704
self.wallet_app.command(
691705
"regen-coldkey", rich_help_panel=HELP_PANELS["WALLET"]["SECURITY"]
692706
)(self.wallet_regen_coldkey)
@@ -2309,28 +2323,98 @@ def wallet_new_coldkey(
23092323

23102324
def wallet_check_ck_swap(
23112325
self,
2312-
wallet_name: Optional[str] = Options.wallet_name,
2326+
wallet_ss58_address: Optional[str] = Options.wallet_ss58_address,
23132327
wallet_path: Optional[str] = Options.wallet_path,
23142328
wallet_hotkey: Optional[str] = Options.wallet_hotkey,
2329+
scheduled_block: Optional[int] = typer.Option(
2330+
None,
2331+
"--block",
2332+
help="Block number where the swap was scheduled",
2333+
),
2334+
show_all: bool = typer.Option(
2335+
False,
2336+
"--all",
2337+
"-a",
2338+
help="Show all pending coldkey swaps",
2339+
),
23152340
network: Optional[list[str]] = Options.network,
23162341
quiet: bool = Options.quiet,
23172342
verbose: bool = Options.verbose,
23182343
):
23192344
"""
2320-
Check the status of your scheduled coldkey swap.
2345+
Check the status of scheduled coldkey swaps.
23212346
23222347
USAGE
23232348
2324-
Users should provide the old coldkey wallet to check the swap status.
2349+
This command can be used in three ways:
2350+
1. Show all pending swaps (--all)
2351+
2. Check status of a specific wallet's swap or SS58 address
2352+
3. Check detailed swap status with block number (--block)
23252353
2326-
EXAMPLE
2354+
EXAMPLES
2355+
2356+
Show all pending swaps:
2357+
[green]$[/green] btcli wallet swap-check --all
23272358
2328-
[green]$[/green] btcli wallet check_coldkey_swap
2359+
Check specific wallet's swap:
2360+
[green]$[/green] btcli wallet swap-check --wallet.name my_wallet
2361+
2362+
Check swap using SS58 address:
2363+
[green]$[/green] btcli wallet swap-check --ss58-address 5DkQ4...
2364+
2365+
Check swap details with block number:
2366+
[green]$[/green] btcli wallet swap-check --wallet.name my_wallet --block 12345
23292367
"""
23302368
self.verbosity_handler(quiet, verbose)
2331-
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey)
23322369
self.initialize_chain(network)
2333-
return self._run_command(wallets.check_coldkey_swap(wallet, self.subtensor))
2370+
2371+
if not wallet_ss58_address:
2372+
wallet_or_ss58_address = Prompt.ask(
2373+
"Enter the [blue]SS58 address[/blue] or the [blue]wallet name[/blue]. [dim]Leave blank to check all pending swaps[/dim]"
2374+
)
2375+
if not wallet_or_ss58_address:
2376+
show_all = True
2377+
else:
2378+
if is_valid_ss58_address(wallet_or_ss58_address):
2379+
return self._run_command(
2380+
wallets.check_swap_status(
2381+
self.subtensor, wallet_or_ss58_address, scheduled_block
2382+
)
2383+
)
2384+
else:
2385+
wallet_name = wallet_or_ss58_address
2386+
2387+
if show_all:
2388+
return self._run_command(
2389+
wallets.check_swap_status(self.subtensor, None, None)
2390+
)
2391+
2392+
wallet = self.wallet_ask(
2393+
wallet_name,
2394+
wallet_path,
2395+
wallet_hotkey,
2396+
ask_for=[WO.NAME, WO.PATH],
2397+
validate=WV.WALLET,
2398+
)
2399+
2400+
if not scheduled_block:
2401+
block_input = Prompt.ask(
2402+
"[blue]Enter the block number[/blue] where the swap was scheduled [dim](optional, press enter to skip)[/dim]",
2403+
default="",
2404+
)
2405+
if block_input:
2406+
try:
2407+
scheduled_block = int(block_input)
2408+
except ValueError:
2409+
console.print(
2410+
"[red]Invalid block number. Skipping block check.[/red]"
2411+
)
2412+
2413+
return self._run_command(
2414+
wallets.check_swap_status(
2415+
self.subtensor, wallet.coldkeypub.ss58_address, scheduled_block
2416+
)
2417+
)
23342418

23352419
def wallet_create_wallet(
23362420
self,

0 commit comments

Comments
 (0)