16
16
from rich .padding import Padding
17
17
from rich .prompt import Confirm
18
18
19
- from bittensor_cli .src import COLOR_PALETTE
19
+ from bittensor_cli .src import COLOR_PALETTE , COLORS
20
20
from bittensor_cli .src .bittensor import utils
21
21
from bittensor_cli .src .bittensor .balances import Balance
22
22
from bittensor_cli .src .bittensor .chain_data import (
@@ -1510,8 +1510,8 @@ async def schedule_coldkey_swap(
1510
1510
1511
1511
prompt = (
1512
1512
"You are [red]swapping[/red] your [blue]coldkey[/blue] to a new address.\n "
1513
- f"Current ss58: [{ COLOR_PALETTE [ 'GENERAL' ][ 'COLDKEY' ] } ]{ wallet .coldkeypub .ss58_address } [/{ COLOR_PALETTE [ 'GENERAL' ][ 'COLDKEY' ] } ]\n "
1514
- f"New ss58: [{ COLOR_PALETTE [ 'GENERAL' ][ 'COLDKEY' ] } ]{ new_coldkey_ss58 } [/{ COLOR_PALETTE [ 'GENERAL' ][ 'COLDKEY' ] } ]\n "
1513
+ f"Current ss58: [{ COLORS . G . CK } ]{ wallet .coldkeypub .ss58_address } [/{ COLORS . G . CK } ]\n "
1514
+ f"New ss58: [{ COLORS . G . CK } ]{ new_coldkey_ss58 } [/{ COLORS . G . CK } ]\n "
1515
1515
"Are you sure you want to continue?"
1516
1516
)
1517
1517
if not Confirm .ask (prompt ):
@@ -1520,12 +1520,15 @@ async def schedule_coldkey_swap(
1520
1520
if not unlock_key (wallet ).success :
1521
1521
return False
1522
1522
1523
- call = await subtensor .substrate .compose_call (
1524
- call_module = "SubtensorModule" ,
1525
- call_function = "schedule_swap_coldkey" ,
1526
- call_params = {
1527
- "new_coldkey" : new_coldkey_ss58 ,
1528
- },
1523
+ block_pre_call , call = await asyncio .gather (
1524
+ subtensor .substrate .get_block_number (),
1525
+ subtensor .substrate .compose_call (
1526
+ call_module = "SubtensorModule" ,
1527
+ call_function = "schedule_swap_coldkey" ,
1528
+ call_params = {
1529
+ "new_coldkey" : new_coldkey_ss58 ,
1530
+ },
1531
+ ),
1529
1532
)
1530
1533
1531
1534
with console .status (":satellite: Scheduling coldkey swap on-chain..." ):
@@ -1535,6 +1538,7 @@ async def schedule_coldkey_swap(
1535
1538
wait_for_inclusion = True ,
1536
1539
wait_for_finalization = True ,
1537
1540
)
1541
+ block_post_call = await subtensor .substrate .get_block_number ()
1538
1542
1539
1543
if not success :
1540
1544
print_error (f"Failed to schedule coldkey swap: { err_msg } " )
@@ -1543,4 +1547,59 @@ async def schedule_coldkey_swap(
1543
1547
console .print (
1544
1548
":white_heavy_check_mark: [green]Successfully scheduled coldkey swap"
1545
1549
)
1550
+
1551
+ block_num , dest_coldkey = await find_coldkey_swap_extrinsic (
1552
+ subtensor = subtensor ,
1553
+ start_block = block_pre_call ,
1554
+ end_block = block_post_call ,
1555
+ wallet_ss58 = wallet .coldkeypub .ss58_address ,
1556
+ )
1557
+
1558
+ if block_num is not None :
1559
+ console .print (
1560
+ f"\n [green]Coldkey swap details:[/green]"
1561
+ f"\n Block number: { block_num } "
1562
+ f"\n Original address: [{ COLORS .G .CK } ]{ wallet .coldkeypub .ss58_address } [/{ COLORS .G .CK } ]"
1563
+ f"\n Destination address: [{ COLORS .G .CK } ]{ dest_coldkey } [/{ COLORS .G .CK } ]"
1564
+ f"\n \n You can provide this block number to `btcli wallet swap check`"
1565
+ )
1566
+ else :
1567
+ console .print (
1568
+ "[yellow]Warning: Could not find the swap extrinsic in recent blocks"
1569
+ )
1546
1570
return True
1571
+
1572
+
1573
+ async def find_coldkey_swap_extrinsic (
1574
+ subtensor : SubtensorInterface ,
1575
+ start_block : int ,
1576
+ end_block : int ,
1577
+ wallet_ss58 : str ,
1578
+ ) -> tuple [Optional [int ], Optional [str ]]:
1579
+ """Search for a coldkey swap extrinsic in a range of blocks.
1580
+
1581
+ Args:
1582
+ subtensor: SubtensorInterface for chain queries
1583
+ start_block: Starting block number to search
1584
+ end_block: Ending block number to search (inclusive)
1585
+ wallet_ss58: SS58 address of the signing wallet
1586
+
1587
+ Returns:
1588
+ tuple[Optional[int], Optional[str]]:
1589
+ (block number, destination coldkey ss58) if found,
1590
+ (None, None) if not found
1591
+ """
1592
+ for block_num in range (start_block , end_block + 1 ):
1593
+ block_data = await subtensor .substrate .get_block (block_number = block_num )
1594
+ for extrinsic in block_data ["extrinsics" ]:
1595
+ extrinsic_data = extrinsic .value
1596
+ if (
1597
+ "call" in extrinsic_data
1598
+ and extrinsic_data ["call" ].get ("call_function" )
1599
+ == "schedule_swap_coldkey"
1600
+ and extrinsic_data .get ("address" ) == wallet_ss58
1601
+ ):
1602
+ new_coldkey_ss58 = extrinsic_data ["call" ]["call_args" ][0 ]["value" ]
1603
+ return block_num , new_coldkey_ss58
1604
+
1605
+ return None , None
0 commit comments