75
75
u16_normalized_float ,
76
76
_decode_hex_identity_dict ,
77
77
Certificate ,
78
+ u64_normalized_float ,
78
79
)
79
80
from bittensor .utils .balance import (
80
81
Balance ,
@@ -891,7 +892,7 @@ async def get_children(
891
892
block : Optional [int ] = None ,
892
893
block_hash : Optional [str ] = None ,
893
894
reuse_block : bool = False ,
894
- ) -> tuple [bool , list , str ]:
895
+ ) -> tuple [bool , list [ tuple [ float , str ]] , str ]:
895
896
"""
896
897
This method retrieves the children of a given hotkey and netuid. It queries the SubtensorModule's ChildKeys
897
898
storage function to get the children and formats them before returning as a tuple.
@@ -921,8 +922,8 @@ async def get_children(
921
922
for proportion , child in children .value :
922
923
# Convert U64 to int
923
924
formatted_child = decode_account_id (child [0 ])
924
- int_proportion = int (proportion )
925
- formatted_children .append ((int_proportion , formatted_child ))
925
+ normalized_proportion = u64_normalized_float (proportion )
926
+ formatted_children .append ((normalized_proportion , formatted_child ))
926
927
return True , formatted_children , ""
927
928
else :
928
929
return True , [], ""
@@ -1665,6 +1666,40 @@ async def get_stake_for_coldkey(
1665
1666
1666
1667
get_stake_info_for_coldkey = get_stake_for_coldkey
1667
1668
1669
+ async def get_stake_for_hotkey (
1670
+ self ,
1671
+ hotkey_ss58 : str ,
1672
+ netuid : int ,
1673
+ block : Optional [int ] = None ,
1674
+ block_hash : Optional [str ] = None ,
1675
+ reuse_block : bool = False ,
1676
+ ) -> Balance :
1677
+ """
1678
+ Retrieves the stake information for a given hotkey.
1679
+
1680
+ Args:
1681
+ hotkey_ss58: The SS58 address of the hotkey.
1682
+ netuid: The subnet ID to query for.
1683
+ block: The block number at which to query the stake information. Do not specify if also specifying
1684
+ block_hash or reuse_block
1685
+ block_hash: The hash of the blockchain block number for the query. Do not specify if also specifying block
1686
+ or reuse_block
1687
+ reuse_block: Whether to reuse for this query the last-used block. Do not specify if also specifying block
1688
+ or block_hash.
1689
+ """
1690
+ hotkey_alpha_query = await self .query_subtensor (
1691
+ name = "TotalHotkeyAlpha" ,
1692
+ params = [hotkey_ss58 , netuid ],
1693
+ block = block ,
1694
+ block_hash = block_hash ,
1695
+ reuse_block = reuse_block ,
1696
+ )
1697
+ balance = Balance .from_rao (hotkey_alpha_query .value )
1698
+ balance .set_unit (netuid = netuid )
1699
+ return balance
1700
+
1701
+ get_hotkey_stake = get_stake_for_hotkey
1702
+
1668
1703
async def get_subnet_burn_cost (
1669
1704
self ,
1670
1705
block : Optional [int ] = None ,
@@ -2683,6 +2718,9 @@ async def sign_and_send_extrinsic(
2683
2718
wait_for_inclusion : bool = True ,
2684
2719
wait_for_finalization : bool = False ,
2685
2720
sign_with : str = "coldkey" ,
2721
+ use_nonce : bool = False ,
2722
+ period : Optional [int ] = None ,
2723
+ nonce_key : str = "hotkey" ,
2686
2724
) -> tuple [bool , str ]:
2687
2725
"""
2688
2726
Helper method to sign and submit an extrinsic call to chain.
@@ -2697,14 +2735,26 @@ async def sign_and_send_extrinsic(
2697
2735
Returns:
2698
2736
(success, error message)
2699
2737
"""
2700
- if sign_with not in ("coldkey" , "hotkey" , "coldkeypub" ):
2738
+ possible_keys = ("coldkey" , "hotkey" , "coldkeypub" )
2739
+ if sign_with not in possible_keys :
2701
2740
raise AttributeError (
2702
2741
f"'sign_with' must be either 'coldkey', 'hotkey' or 'coldkeypub', not '{ sign_with } '"
2703
2742
)
2743
+ signing_keypair = getattr (wallet , sign_with )
2744
+ extrinsic_data = {"call" : call , "keypair" : signing_keypair }
2745
+ if use_nonce :
2746
+ if nonce_key not in possible_keys :
2747
+ raise AttributeError (
2748
+ f"'nonce_key' must be either 'coldkey', 'hotkey' or 'coldkeypub', not '{ nonce_key } '"
2749
+ )
2750
+ next_nonce = await self .substrate .get_account_next_index (
2751
+ getattr (wallet , nonce_key ).ss58_address
2752
+ )
2753
+ extrinsic_data ["nonce" ] = next_nonce
2754
+ if period is not None :
2755
+ extrinsic_data ["era" ] = {"period" : period }
2704
2756
2705
- extrinsic = await self .substrate .create_signed_extrinsic (
2706
- call = call , keypair = getattr (wallet , sign_with )
2707
- )
2757
+ extrinsic = await self .substrate .create_signed_extrinsic (** extrinsic_data )
2708
2758
try :
2709
2759
response = await self .substrate .submit_extrinsic (
2710
2760
extrinsic ,
0 commit comments