1717 format_error_message ,
1818 group_subnets ,
1919 get_subnet_name ,
20+ unlock_key ,
2021)
2122
2223if TYPE_CHECKING :
@@ -621,10 +622,7 @@ async def move_stake(
621622 raise typer .Exit ()
622623
623624 # Perform moving operation.
624- try :
625- wallet .unlock_coldkey ()
626- except KeyFileError :
627- err_console .print ("Error decrypting coldkey (possibly incorrect password)" )
625+ if not unlock_key (wallet ).success :
628626 return False
629627 with console .status (
630628 f"\n :satellite: Moving [blue]{ amount_to_move_as_balance } [/blue] from [blue]{ origin_hotkey } [/blue] on netuid: [blue]{ origin_netuid } [/blue] \n to "
@@ -697,6 +695,7 @@ async def transfer_stake(
697695 wallet : Wallet ,
698696 subtensor : "SubtensorInterface" ,
699697 amount : float ,
698+ origin_hotkey : str ,
700699 origin_netuid : int ,
701700 dest_netuid : int ,
702701 dest_coldkey_ss58 : str ,
@@ -709,6 +708,7 @@ async def transfer_stake(
709708 wallet (Wallet): Bittensor wallet object.
710709 subtensor (SubtensorInterface): Subtensor interface instance.
711710 amount (float): Amount to transfer.
711+ origin_hotkey (str): The hotkey SS58 to transfer the stake from.
712712 origin_netuid (int): The netuid to transfer stake from.
713713 dest_netuid (int): The netuid to transfer stake to.
714714 dest_coldkey_ss58 (str): The destination coldkey to transfer stake to.
@@ -739,16 +739,15 @@ async def transfer_stake(
739739 return False
740740
741741 # Get current stake balances
742- hotkey_ss58 = wallet .hotkey .ss58_address
743742 with console .status (f"Retrieving stake data from { subtensor .network } ..." ):
744743 current_stake = await subtensor .get_stake (
745744 coldkey_ss58 = wallet .coldkeypub .ss58_address ,
746- hotkey_ss58 = hotkey_ss58 ,
745+ hotkey_ss58 = origin_hotkey ,
747746 netuid = origin_netuid ,
748747 )
749748 current_dest_stake = await subtensor .get_stake (
750749 coldkey_ss58 = dest_coldkey_ss58 ,
751- hotkey_ss58 = hotkey_ss58 ,
750+ hotkey_ss58 = origin_hotkey ,
752751 netuid = dest_netuid ,
753752 )
754753 amount_to_transfer = Balance .from_tao (amount ).set_unit (origin_netuid )
@@ -768,19 +767,16 @@ async def transfer_stake(
768767 subtensor = subtensor ,
769768 origin_netuid = origin_netuid ,
770769 destination_netuid = dest_netuid ,
771- origin_hotkey = hotkey_ss58 ,
772- destination_hotkey = hotkey_ss58 ,
770+ origin_hotkey = origin_hotkey ,
771+ destination_hotkey = origin_hotkey ,
773772 amount_to_move = amount_to_transfer ,
774773 )
775774
776775 if not Confirm .ask ("Would you like to continue?" ):
777776 raise typer .Exit ()
778777
779778 # Perform transfer operation
780- try :
781- wallet .unlock_coldkey ()
782- except KeyFileError :
783- err_console .print ("Error decrypting coldkey (possibly incorrect password)" )
779+ if not unlock_key (wallet ).success :
784780 return False
785781
786782 with console .status ("\n :satellite: Transferring stake ..." ):
@@ -789,7 +785,7 @@ async def transfer_stake(
789785 call_function = "transfer_stake" ,
790786 call_params = {
791787 "destination_coldkey" : dest_coldkey_ss58 ,
792- "hotkey" : hotkey_ss58 ,
788+ "hotkey" : origin_hotkey ,
793789 "origin_netuid" : origin_netuid ,
794790 "destination_netuid" : dest_netuid ,
795791 "alpha_amount" : amount_to_transfer .rao ,
@@ -820,12 +816,12 @@ async def transfer_stake(
820816 new_stake , new_dest_stake = await asyncio .gather (
821817 subtensor .get_stake (
822818 coldkey_ss58 = wallet .coldkeypub .ss58_address ,
823- hotkey_ss58 = hotkey_ss58 ,
819+ hotkey_ss58 = origin_hotkey ,
824820 netuid = origin_netuid ,
825821 ),
826822 subtensor .get_stake (
827823 coldkey_ss58 = dest_coldkey_ss58 ,
828- hotkey_ss58 = hotkey_ss58 ,
824+ hotkey_ss58 = origin_hotkey ,
829825 netuid = dest_netuid ,
830826 ),
831827 )
@@ -933,10 +929,7 @@ async def swap_stake(
933929 raise typer .Exit ()
934930
935931 # Perform swap operation
936- try :
937- wallet .unlock_coldkey ()
938- except KeyFileError :
939- err_console .print ("Error decrypting coldkey (possibly incorrect password)" )
932+ if not unlock_key (wallet ).success :
940933 return False
941934
942935 with console .status (
0 commit comments