@@ -82,6 +82,32 @@ def decode_ss58_tuples(line: tuple):
82
82
return [decode_account_id (line [x ][0 ]) for x in range (len (line ))]
83
83
84
84
85
+ def _decode_hex_identity_dict (info_dictionary : dict [str , Any ]) -> dict [str , Any ]:
86
+ """Decodes a dictionary of hexadecimal identities."""
87
+ for k , v in info_dictionary .items ():
88
+ if isinstance (v , dict ):
89
+ item = next (iter (v .values ()))
90
+ else :
91
+ item = v
92
+ if isinstance (item , tuple ) and item :
93
+ if len (item ) > 1 :
94
+ try :
95
+ info_dictionary [k ] = (
96
+ bytes (item ).hex (sep = " " , bytes_per_sep = 2 ).upper ()
97
+ )
98
+ except UnicodeDecodeError :
99
+ logging .error (f"Could not decode: { k } : { item } ." )
100
+ else :
101
+ try :
102
+ info_dictionary [k ] = bytes (item [0 ]).decode ("utf-8" )
103
+ except UnicodeDecodeError :
104
+ logging .error (f"Could not decode: { k } : { item } ." )
105
+ else :
106
+ info_dictionary [k ] = item
107
+
108
+ return info_dictionary
109
+
110
+
85
111
class AsyncSubtensor :
86
112
"""Thin layer for interacting with Substrate Interface. Mostly a collection of frequently-used calls."""
87
113
@@ -858,7 +884,6 @@ async def neuron_for_uid(
858
884
method = "neuronInfo_getNeuron" ,
859
885
params = params , # custom rpc method
860
886
)
861
-
862
887
if not (result := json_body .get ("result" , None )):
863
888
return NeuronInfo .get_null_neuron ()
864
889
@@ -924,30 +949,6 @@ async def query_identity(
924
949
See the `Bittensor CLI documentation <https://docs.bittensor.com/reference/btcli>`_ for supported identity parameters.
925
950
"""
926
951
927
- def decode_hex_identity_dict_ (info_dictionary ):
928
- for k , v in info_dictionary .items ():
929
- if isinstance (v , dict ):
930
- item = next (iter (v .values ()))
931
- else :
932
- item = v
933
- if isinstance (item , tuple ) and item :
934
- if len (item ) > 1 :
935
- try :
936
- info_dictionary [k ] = (
937
- bytes (item ).hex (sep = " " , bytes_per_sep = 2 ).upper ()
938
- )
939
- except UnicodeDecodeError :
940
- print (f"Could not decode: { k } : { item } " )
941
- else :
942
- try :
943
- info_dictionary [k ] = bytes (item [0 ]).decode ("utf-8" )
944
- except UnicodeDecodeError :
945
- print (f"Could not decode: { k } : { item } " )
946
- else :
947
- info_dictionary [k ] = item
948
-
949
- return info_dictionary
950
-
951
952
identity_info = await self .substrate .query (
952
953
module = "Registry" ,
953
954
storage_function = "IdentityOf" ,
@@ -956,7 +957,7 @@ def decode_hex_identity_dict_(info_dictionary):
956
957
reuse_block_hash = reuse_block ,
957
958
)
958
959
try :
959
- return decode_hex_identity_dict_ (identity_info ["info" ])
960
+ return _decode_hex_identity_dict (identity_info ["info" ])
960
961
except TypeError :
961
962
return {}
962
963
0 commit comments