Skip to content

Commit 7d39145

Browse files
authored
Merge pull request #485 from opentensor/fix/thewhaleking/btcli-swap-status
Better checks the swap status
2 parents dd0ce41 + c83f798 commit 7d39145

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

bittensor_cli/src/commands/wallets.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,11 +2002,12 @@ async def check_swap_status(
20022002
Args:
20032003
subtensor: Connection to the network
20042004
origin_ss58: The SS58 address of the original coldkey
2005-
block_number: Optional block number where the swap was scheduled
2005+
expected_block_number: Optional block number where the swap was scheduled
2006+
20062007
"""
2007-
scheduled_swaps = await subtensor.get_scheduled_coldkey_swap()
20082008

20092009
if not origin_ss58:
2010+
scheduled_swaps = await subtensor.get_scheduled_coldkey_swap()
20102011
if not scheduled_swaps:
20112012
console.print("[yellow]No pending coldkey swaps found.[/yellow]")
20122013
return
@@ -2035,11 +2036,20 @@ async def check_swap_status(
20352036

20362037
console.print(table)
20372038
console.print(
2038-
"\n[dim]Tip: Check specific swap details by providing the original coldkey SS58 address and the block number.[/dim]"
2039+
"\n[dim]Tip: Check specific swap details by providing the original coldkey "
2040+
"SS58 address and the block number.[/dim]"
20392041
)
20402042
return
2041-
2042-
is_pending = origin_ss58 in scheduled_swaps
2043+
chain_reported_completion_block, destination_address = await subtensor.query(
2044+
"SubtensorModule", "ColdkeySwapScheduled", [origin_ss58]
2045+
)
2046+
if (
2047+
chain_reported_completion_block != 0
2048+
and destination_address != "5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM"
2049+
):
2050+
is_pending = True
2051+
else:
2052+
is_pending = False
20432053

20442054
if not is_pending:
20452055
console.print(
@@ -2052,33 +2062,19 @@ async def check_swap_status(
20522062
)
20532063

20542064
if expected_block_number is None:
2055-
return
2056-
2057-
swap_info = await find_coldkey_swap_extrinsic(
2058-
subtensor=subtensor,
2059-
start_block=expected_block_number,
2060-
end_block=expected_block_number,
2061-
wallet_ss58=origin_ss58,
2062-
)
2063-
2064-
if not swap_info:
2065-
console.print(
2066-
f"[yellow]Warning: Could not find swap extrinsic at block {expected_block_number}[/yellow]"
2067-
)
2068-
return
2065+
expected_block_number = chain_reported_completion_block
20692066

20702067
current_block = await subtensor.substrate.get_block_number()
2071-
remaining_blocks = swap_info["execution_block"] - current_block
2068+
remaining_blocks = expected_block_number - current_block
20722069

20732070
if remaining_blocks <= 0:
20742071
console.print("[green]Swap period has completed![/green]")
20752072
return
20762073

20772074
console.print(
20782075
"\n[green]Coldkey swap details:[/green]"
2079-
f"\nScheduled at block: {swap_info['block_num']}"
20802076
f"\nOriginal address: [{COLORS.G.CK}]{origin_ss58}[/{COLORS.G.CK}]"
2081-
f"\nDestination address: [{COLORS.G.CK}]{swap_info['dest_coldkey']}[/{COLORS.G.CK}]"
2082-
f"\nCompletion block: {swap_info['execution_block']}"
2077+
f"\nDestination address: [{COLORS.G.CK}]{destination_address}[/{COLORS.G.CK}]"
2078+
f"\nCompletion block: {chain_reported_completion_block}"
20832079
f"\nTime remaining: {blocks_to_duration(remaining_blocks)}"
20842080
)

0 commit comments

Comments
 (0)