@@ -1611,7 +1611,8 @@ def _update_curr_block(
16111611 """
16121612 Update the current block data with the provided block information and difficulty.
16131613
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
16151616 number, hashes the block with the hotkey, updates the current block bytes, and packs the difficulty.
16161617
16171618 :param curr_diff: Shared array to store the current difficulty.
@@ -1745,6 +1746,7 @@ async def swap_hotkey_extrinsic(
17451746 subtensor : "SubtensorInterface" ,
17461747 wallet : Wallet ,
17471748 new_wallet : Wallet ,
1749+ netuid : Optional [int ] = None ,
17481750 prompt : bool = False ,
17491751) -> bool :
17501752 """
@@ -1756,37 +1758,76 @@ async def swap_hotkey_extrinsic(
17561758 netuids_registered = await subtensor .get_netuids_for_hotkey (
17571759 wallet .hotkey .ss58_address , block_hash = block_hash
17581760 )
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 :
17601772 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 . "
17621774 f"Please register and try again"
17631775 )
17641776 return False
17651777
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+
17661793 if not unlock_key (wallet ).success :
17671794 return False
17681795
17691796 if prompt :
17701797 # 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 } [/dark_orange] with hotkey \n \t "
1802+ f"[dark_orange]{ new_wallet .hotkey .ss58_address } [/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 } [/dark_orange] with hotkey \n \t "
1809+ f"[dark_orange]{ new_wallet .hotkey .ss58_address } [/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 ):
17771814 return False
17781815 print_verbose (
17791816 f"Swapping { wallet .name } 's hotkey ({ wallet .hotkey .ss58_address } ) with "
1780- f"{ new_wallet .name } s hotkey ({ new_wallet .hotkey .ss58_address } )"
1817+ f"{ new_wallet .name } ' s hotkey ({ new_wallet .hotkey .ss58_address } )"
17811818 )
17821819 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+ }
1824+ if netuid is not None :
1825+ call_params ["netuid" ] = netuid
1826+
17831827 call = await subtensor .substrate .compose_call (
17841828 call_module = "SubtensorModule" ,
17851829 call_function = "swap_hotkey" ,
1786- call_params = {
1787- "hotkey" : wallet .hotkey .ss58_address ,
1788- "new_hotkey" : new_wallet .hotkey .ss58_address ,
1789- },
1830+ call_params = call_params ,
17901831 )
17911832 success , err_msg = await subtensor .sign_and_send_extrinsic (call , wallet )
17921833
0 commit comments