1313from scalecodec import ss58_decode
1414
1515
16- def stake_info_decode_vec_legacy_compatibility (item ) -> list [dict [str , Union [str , int , bytes , bool ]]]:
16+ def stake_info_decode_vec_legacy_compatibility (
17+ item ,
18+ ) -> list [dict [str , Union [str , int , bytes , bool ]]]:
1719 stake_infos : list [StakeInfo ] = StakeInfo .decode_vec (item )
18- NewStakeInfo = namedtuple ("NewStakeInfo" , ["netuid" , "hotkey" , "coldkey" , "stake" , "locked" , "emission" , "drain" , "is_registered" ])
20+ NewStakeInfo = namedtuple (
21+ "NewStakeInfo" ,
22+ [
23+ "netuid" ,
24+ "hotkey" ,
25+ "coldkey" ,
26+ "stake" ,
27+ "locked" ,
28+ "emission" ,
29+ "drain" ,
30+ "is_registered" ,
31+ ],
32+ )
1933 output = []
2034 for stake_info in stake_infos :
2135 output .append (
22- NewStakeInfo (0 , stake_info .hotkey , stake_info .coldkey , stake_info .stake , 0 , 0 , 0 , False )
36+ NewStakeInfo (
37+ 0 ,
38+ stake_info .hotkey ,
39+ stake_info .coldkey ,
40+ stake_info .stake ,
41+ 0 ,
42+ 0 ,
43+ 0 ,
44+ False ,
45+ )
2346 )
2447 return output
2548
2649
50+ def preprocess_get_stake_info_for_coldkeys (addrs ):
51+ output = []
52+ if isinstance (addrs [0 ], list ): # I think
53+ for addr in addrs [0 ]:
54+ output .append (list (bytes .fromhex (ss58_decode (addr ))))
55+ else :
56+ if isinstance (addrs [0 ], dict ):
57+ for addr in addrs [0 ]["coldkey_accounts" ]:
58+ output .append (list (bytes .fromhex (ss58_decode (addr ))))
59+ return output
60+
61+
2762_TYPE_REGISTRY : dict [str , dict ] = {
2863 "types" : {
2964 "Balance" : "u64" , # Need to override default u128
@@ -114,7 +149,17 @@ def stake_info_decode_vec_legacy_compatibility(item) -> list[dict[str, Union[str
114149 ],
115150 "type" : "Vec<u8>" ,
116151 "encoder" : lambda addr , reg : encode (
117- "Vec<u8>" , reg , list (bytes .fromhex (ss58_decode (addr [0 ] if isinstance (addr , list ) else addr ["coldkey" ])))
152+ "Vec<u8>" ,
153+ reg ,
154+ list (
155+ bytes .fromhex (
156+ ss58_decode (
157+ addr [0 ]
158+ if isinstance (addr , list )
159+ else addr ["coldkey_account" ]
160+ )
161+ )
162+ ),
118163 ),
119164 "decoder" : stake_info_decode_vec_legacy_compatibility ,
120165 },
@@ -129,7 +174,7 @@ def stake_info_decode_vec_legacy_compatibility(item) -> list[dict[str, Union[str
129174 "encoder" : lambda addrs , reg : encode (
130175 "Vec<Vec<u8>>" ,
131176 reg ,
132- [ list ( bytes . fromhex ( ss58_decode ( addr ))) for addr in addrs ] ,
177+ preprocess_get_stake_info_for_coldkeys ( addrs ) ,
133178 ),
134179 "decoder" : StakeInfo .decode_vec_tuple_vec ,
135180 },
0 commit comments