@@ -1611,7 +1611,8 @@ def _update_curr_block(
1611
1611
"""
1612
1612
Update the current block data with the provided block information and difficulty.
1613
1613
1614
- This function updates the current block and its difficulty in a thread-safe manner. It sets the current block
1614
+ This function updates the current block
1615
+ and its difficulty in a thread-safe manner. It sets the current block
1615
1616
number, hashes the block with the hotkey, updates the current block bytes, and packs the difficulty.
1616
1617
1617
1618
:param curr_diff: Shared array to store the current difficulty.
@@ -1745,6 +1746,7 @@ async def swap_hotkey_extrinsic(
1745
1746
subtensor : "SubtensorInterface" ,
1746
1747
wallet : Wallet ,
1747
1748
new_wallet : Wallet ,
1749
+ netuid : Optional [int ] = None ,
1748
1750
prompt : bool = False ,
1749
1751
) -> bool :
1750
1752
"""
@@ -1756,43 +1758,81 @@ async def swap_hotkey_extrinsic(
1756
1758
netuids_registered = await subtensor .get_netuids_for_hotkey (
1757
1759
wallet .hotkey .ss58_address , block_hash = block_hash
1758
1760
)
1759
- if not len (netuids_registered ) > 0 :
1761
+ netuids_registered_new_hotkey = await subtensor .get_netuids_for_hotkey (
1762
+ new_wallet .hotkey .ss58_address , block_hash = block_hash
1763
+ )
1764
+
1765
+ if netuid is not None and netuid not in netuids_registered :
1766
+ err_console .print (
1767
+ f":cross_mark: [red]Failed[/red]: Original hotkey { wallet .hotkey .ss58_address } is not registered on subnet { netuid } "
1768
+ )
1769
+ return False
1770
+
1771
+ elif not len (netuids_registered ) > 0 :
1760
1772
err_console .print (
1761
- f"Destination hotkey [dark_orange]{ new_wallet .hotkey .ss58_address } [/dark_orange] is not registered. "
1773
+ f"Original hotkey [dark_orange]{ wallet .hotkey .ss58_address } [/dark_orange] is not registered on any subnet . "
1762
1774
f"Please register and try again"
1763
1775
)
1764
1776
return False
1765
1777
1778
+ if netuid is not None :
1779
+ if netuid in netuids_registered_new_hotkey :
1780
+ err_console .print (
1781
+ f":cross_mark: [red]Failed[/red]: New hotkey { new_wallet .hotkey .ss58_address } "
1782
+ f"is already registered on subnet { netuid } "
1783
+ )
1784
+ return False
1785
+ else :
1786
+ if len (netuids_registered_new_hotkey ) > 0 :
1787
+ err_console .print (
1788
+ f":cross_mark: [red]Failed[/red]: New hotkey { new_wallet .hotkey .ss58_address } "
1789
+ f"is already registered on subnet(s) { netuids_registered_new_hotkey } "
1790
+ )
1791
+ return False
1792
+
1766
1793
if not unlock_key (wallet ).success :
1767
1794
return False
1768
1795
1769
1796
if prompt :
1770
1797
# Prompt user for confirmation.
1771
- if not Confirm .ask (
1772
- f"Do you want to swap [dark_orange]{ wallet .name } [/dark_orange] hotkey \n \t "
1773
- f"[dark_orange]{ wallet .hotkey .ss58_address } [/dark_orange] with hotkey \n \t "
1774
- f"[dark_orange]{ new_wallet .hotkey .ss58_address } [/dark_orange]\n "
1775
- "This operation will cost [bold cyan]1 TAO t (recycled)[/bold cyan]"
1776
- ):
1798
+ if netuid is not None :
1799
+ confirm_message = (
1800
+ f"Do you want to swap [dark_orange]{ wallet .name } [/dark_orange] hotkey \n \t "
1801
+ f"[dark_orange]{ wallet .hotkey .ss58_address } ({ wallet .hotkey_str } )[/dark_orange] with hotkey \n \t "
1802
+ f"[dark_orange]{ new_wallet .hotkey .ss58_address } ({ new_wallet .hotkey_str } )[/dark_orange] on subnet { netuid } \n "
1803
+ "This operation will cost [bold cyan]1 TAO (recycled)[/bold cyan]"
1804
+ )
1805
+ else :
1806
+ confirm_message = (
1807
+ f"Do you want to swap [dark_orange]{ wallet .name } [/dark_orange] hotkey \n \t "
1808
+ f"[dark_orange]{ wallet .hotkey .ss58_address } ({ wallet .hotkey_str } )[/dark_orange] with hotkey \n \t "
1809
+ f"[dark_orange]{ new_wallet .hotkey .ss58_address } ({ new_wallet .hotkey_str } )[/dark_orange] on all subnets\n "
1810
+ "This operation will cost [bold cyan]1 TAO (recycled)[/bold cyan]"
1811
+ )
1812
+
1813
+ if not Confirm .ask (confirm_message ):
1777
1814
return False
1778
1815
print_verbose (
1779
- f"Swapping { wallet .name } 's hotkey ({ wallet .hotkey .ss58_address } ) with "
1780
- f"{ new_wallet .name } s hotkey ({ new_wallet .hotkey .ss58_address } )"
1816
+ f"Swapping { wallet .name } 's hotkey ({ wallet .hotkey .ss58_address } - { wallet . hotkey_str } ) with "
1817
+ f"{ new_wallet .name } ' s hotkey ({ new_wallet .hotkey .ss58_address } - { new_wallet . hotkey_str } )"
1781
1818
)
1782
1819
with console .status (":satellite: Swapping hotkeys..." , spinner = "aesthetic" ):
1820
+ call_params = {
1821
+ "hotkey" : wallet .hotkey .ss58_address ,
1822
+ "new_hotkey" : new_wallet .hotkey .ss58_address ,
1823
+ "netuid" : netuid ,
1824
+ }
1825
+
1783
1826
call = await subtensor .substrate .compose_call (
1784
1827
call_module = "SubtensorModule" ,
1785
1828
call_function = "swap_hotkey" ,
1786
- call_params = {
1787
- "hotkey" : wallet .hotkey .ss58_address ,
1788
- "new_hotkey" : new_wallet .hotkey .ss58_address ,
1789
- },
1829
+ call_params = call_params ,
1790
1830
)
1791
1831
success , err_msg = await subtensor .sign_and_send_extrinsic (call , wallet )
1792
1832
1793
1833
if success :
1794
1834
console .print (
1795
- f"Hotkey { wallet .hotkey } swapped for new hotkey: { new_wallet .hotkey } "
1835
+ f"Hotkey { wallet .hotkey . ss58_address } ( { wallet . hotkey_str } ) swapped for new hotkey: { new_wallet .hotkey . ss58_address } ( { new_wallet . hotkey_str } ) "
1796
1836
)
1797
1837
return True
1798
1838
else :
0 commit comments