Skip to content

Commit 3b1a9c4

Browse files
committed
Updates wallet check swap
1 parent 6b794ca commit 3b1a9c4

File tree

1 file changed

+106
-1
lines changed

1 file changed

+106
-1
lines changed

bittensor_cli/src/commands/wallets.py

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ async def schedule_coldkey_swap(
15561556
end_block=block_post_call,
15571557
wallet_ss58=wallet.coldkeypub.ss58_address,
15581558
),
1559-
subtensor.get_coldkey_swap_schedule_duration()
1559+
subtensor.get_coldkey_swap_schedule_duration(),
15601560
)
15611561

15621562
if block_num is not None:
@@ -1608,3 +1608,108 @@ async def find_coldkey_swap_extrinsic(
16081608
return block_num, new_coldkey_ss58
16091609

16101610
return None, None
1611+
1612+
1613+
async def check_swap_status(
1614+
subtensor: SubtensorInterface,
1615+
origin_ss58: Optional[str] = None,
1616+
expected_block_number: Optional[int] = None,
1617+
) -> None:
1618+
"""
1619+
Check the status of a coldkey swap.
1620+
1621+
Args:
1622+
subtensor: Connection to the network
1623+
origin_ss58: The SS58 address of the original coldkey
1624+
block_number: Optional block number where the swap was scheduled
1625+
"""
1626+
scheduled_swaps = await subtensor.get_scheduled_coldkey_swap()
1627+
1628+
if not origin_ss58:
1629+
if not scheduled_swaps:
1630+
console.print("[yellow]No pending coldkey swaps found.[/yellow]")
1631+
return
1632+
1633+
table = Table(
1634+
Column(
1635+
"Original Coldkey",
1636+
justify="Left",
1637+
style=COLOR_PALETTE["GENERAL"]["SUBHEADING_MAIN"],
1638+
no_wrap=True,
1639+
),
1640+
Column(
1641+
"Status",
1642+
style="dark_sea_green3"
1643+
),
1644+
title=f"\n[{COLOR_PALETTE['GENERAL']['HEADER']}]Pending Coldkey Swaps\n",
1645+
show_header=True,
1646+
show_edge=False,
1647+
header_style="bold white",
1648+
border_style="bright_black",
1649+
style="bold",
1650+
title_justify="center",
1651+
show_lines=False,
1652+
pad_edge=True,
1653+
)
1654+
1655+
for coldkey in scheduled_swaps:
1656+
table.add_row(
1657+
coldkey,
1658+
"Pending"
1659+
)
1660+
1661+
console.print(table)
1662+
console.print(
1663+
"\n[dim]Tip: Check specific swap details by providing the original coldkey SS58 address[/dim]"
1664+
)
1665+
return
1666+
1667+
is_pending = origin_ss58 in scheduled_swaps
1668+
1669+
if not is_pending:
1670+
console.print(
1671+
f"[red]No pending swap found for coldkey:[/red] [{COLORS.G.CK}]{origin_ss58}[/{COLORS.G.CK}]"
1672+
)
1673+
return
1674+
1675+
console.print(
1676+
f"[green]Found pending swap for coldkey:[/green] [{COLORS.G.CK}]{origin_ss58}[/{COLORS.G.CK}]"
1677+
)
1678+
1679+
if expected_block_number is None:
1680+
return
1681+
1682+
# Find the swap extrinsic details
1683+
block_num, dest_coldkey = await find_coldkey_swap_extrinsic(
1684+
subtensor=subtensor,
1685+
start_block=expected_block_number,
1686+
end_block=expected_block_number,
1687+
wallet_ss58=origin_ss58,
1688+
)
1689+
1690+
if block_num is None:
1691+
console.print(
1692+
f"[yellow]Warning: Could not find swap extrinsic at block {expected_block_number}[/yellow]"
1693+
)
1694+
return
1695+
1696+
current_block, schedule_duration = await asyncio.gather(
1697+
subtensor.substrate.get_block_number(),
1698+
subtensor.get_coldkey_swap_schedule_duration(),
1699+
)
1700+
1701+
completion_block = block_num + schedule_duration
1702+
remaining_blocks = completion_block - current_block
1703+
1704+
if remaining_blocks <= 0:
1705+
console.print("[green]Swap period has completed![/green]")
1706+
return
1707+
1708+
console.print(
1709+
"\n[green]Coldkey swap details:[/green]"
1710+
f"\nScheduled at block: {block_num}"
1711+
f"\nOriginal address: [{COLORS.G.CK}]{origin_ss58}[/{COLORS.G.CK}]"
1712+
f"\nDestination address: [{COLORS.G.CK}]{dest_coldkey}[/{COLORS.G.CK}]"
1713+
f"\nCompletion block: {completion_block}"
1714+
f"\nTime remaining: {blocks_to_duration(remaining_blocks)}"
1715+
)

0 commit comments

Comments
 (0)