@@ -281,17 +281,26 @@ async def process_events(self):
281
281
self .__weight = dispatch_info ["weight" ]
282
282
283
283
if "Module" in dispatch_error :
284
- module_index = dispatch_error ["Module" ][ 0 ][ "index" ]
285
- error_index = int . from_bytes (
286
- bytes ( dispatch_error ["Module" ][0 ][ "error" ]),
287
- byteorder = "little" ,
288
- signed = False ,
289
- )
284
+ if isinstance ( dispatch_error ["Module" ], tuple ):
285
+ module_index = dispatch_error [ "Module" ][ 0 ]
286
+ error_index = dispatch_error ["Module" ][1 ]
287
+ else :
288
+ module_index = dispatch_error [ "Module" ][ "index" ]
289
+ error_index = dispatch_error [ "Module" ][ "error" ]
290
290
291
291
if isinstance (error_index , str ):
292
292
# Actual error index is first u8 in new [u8; 4] format
293
293
error_index = int (error_index [2 :4 ], 16 )
294
- module_error = self .substrate .metadata .get_module_error (
294
+
295
+ if self .block_hash :
296
+ runtime = await self .substrate .init_runtime (
297
+ block_hash = self .block_hash
298
+ )
299
+ else :
300
+ runtime = await self .substrate .init_runtime (
301
+ block_id = self .block_number
302
+ )
303
+ module_error = runtime .metadata .get_module_error (
295
304
module_index = module_index , error_index = error_index
296
305
)
297
306
self .__error_message = {
@@ -823,6 +832,7 @@ async def initialize(self):
823
832
if ss58_prefix_constant :
824
833
self .ss58_format = ss58_prefix_constant .value
825
834
runtime .ss58_format = ss58_prefix_constant .value
835
+ runtime .runtime_config .ss58_format = ss58_prefix_constant .value
826
836
self .initialized = True
827
837
self ._initializing = False
828
838
@@ -999,7 +1009,7 @@ async def decode_scale(
999
1009
else :
1000
1010
if not runtime :
1001
1011
runtime = await self .init_runtime (block_hash = block_hash )
1002
- if runtime .metadata_v15 is not None or force_legacy is True :
1012
+ if runtime .metadata_v15 is not None and force_legacy is False :
1003
1013
obj = decode_by_type_string (type_string , runtime .registry , scale_bytes )
1004
1014
if self .decode_ss58 :
1005
1015
try :
@@ -1930,7 +1940,13 @@ def convert_event_data(data):
1930
1940
if key == "who" :
1931
1941
who = ss58_encode (bytes (value [0 ]), self .ss58_format )
1932
1942
attributes ["who" ] = who
1933
- if isinstance (value , dict ):
1943
+ elif key == "from" :
1944
+ who_from = ss58_encode (bytes (value [0 ]), self .ss58_format )
1945
+ attributes ["from" ] = who_from
1946
+ elif key == "to" :
1947
+ who_to = ss58_encode (bytes (value [0 ]), self .ss58_format )
1948
+ attributes ["to" ] = who_to
1949
+ elif isinstance (value , dict ):
1934
1950
# Convert nested single-key dictionaries to their keys as strings
1935
1951
for sub_key , sub_value in value .items ():
1936
1952
if isinstance (sub_value , dict ):
@@ -1958,16 +1974,15 @@ def convert_event_data(data):
1958
1974
block_hash = await self .get_chain_head ()
1959
1975
1960
1976
storage_obj = await self .query (
1961
- module = "System" , storage_function = "Events" , block_hash = block_hash
1977
+ module = "System" ,
1978
+ storage_function = "Events" ,
1979
+ block_hash = block_hash ,
1980
+ force_legacy_decode = True ,
1962
1981
)
1982
+ # bt-decode Metadata V15 is not ideal for events. Force legacy decoding for this
1963
1983
if storage_obj :
1964
1984
for item in list (storage_obj ):
1965
- try :
1966
- events .append (convert_event_data (item ))
1967
- except (
1968
- AttributeError
1969
- ): # indicates this was legacy decoded with scalecodec
1970
- events .append (item )
1985
+ events .append (item )
1971
1986
return events
1972
1987
1973
1988
async def get_metadata (self , block_hash = None ) -> MetadataV15 :
@@ -2175,6 +2190,7 @@ async def _process_response(
2175
2190
storage_item : Optional [ScaleType ] = None ,
2176
2191
result_handler : Optional [ResultHandler ] = None ,
2177
2192
runtime : Optional [Runtime ] = None ,
2193
+ force_legacy_decode : bool = False ,
2178
2194
) -> tuple [Any , bool ]:
2179
2195
"""
2180
2196
Processes the RPC call response by decoding it, returning it as is, or setting a handler for subscriptions,
@@ -2187,6 +2203,7 @@ async def _process_response(
2187
2203
storage_item: The ScaleType object used for decoding ScaleBytes results
2188
2204
result_handler: the result handler coroutine used for handling longer-running subscriptions
2189
2205
runtime: Optional Runtime to use for decoding. If not specified, the currently-loaded `self.runtime` is used
2206
+ force_legacy_decode: Whether to force the use of the legacy Metadata V14 decoder
2190
2207
2191
2208
Returns:
2192
2209
(decoded response, completion)
@@ -2208,7 +2225,9 @@ async def _process_response(
2208
2225
q = bytes (query_value )
2209
2226
else :
2210
2227
q = query_value
2211
- result = await self .decode_scale (value_scale_type , q , runtime = runtime )
2228
+ result = await self .decode_scale (
2229
+ value_scale_type , q , runtime = runtime , force_legacy = force_legacy_decode
2230
+ )
2212
2231
if asyncio .iscoroutinefunction (result_handler ):
2213
2232
# For multipart responses as a result of subscriptions.
2214
2233
message , bool_result = await result_handler (result , subscription_id )
@@ -2223,6 +2242,7 @@ async def _make_rpc_request(
2223
2242
result_handler : Optional [ResultHandler ] = None ,
2224
2243
attempt : int = 1 ,
2225
2244
runtime : Optional [Runtime ] = None ,
2245
+ force_legacy_decode : bool = False ,
2226
2246
) -> RequestManager .RequestResults :
2227
2247
request_manager = RequestManager (payloads )
2228
2248
@@ -2267,6 +2287,7 @@ async def _make_rpc_request(
2267
2287
storage_item ,
2268
2288
result_handler ,
2269
2289
runtime = runtime ,
2290
+ force_legacy_decode = force_legacy_decode ,
2270
2291
)
2271
2292
2272
2293
request_manager .add_response (
@@ -2298,6 +2319,7 @@ async def _make_rpc_request(
2298
2319
storage_item ,
2299
2320
result_handler ,
2300
2321
attempt + 1 ,
2322
+ force_legacy_decode ,
2301
2323
)
2302
2324
2303
2325
return request_manager .get_results ()
@@ -3323,6 +3345,7 @@ async def query(
3323
3345
subscription_handler = None ,
3324
3346
reuse_block_hash : bool = False ,
3325
3347
runtime : Optional [Runtime ] = None ,
3348
+ force_legacy_decode : bool = False ,
3326
3349
) -> Optional [Union ["ScaleObj" , Any ]]:
3327
3350
"""
3328
3351
Queries substrate. This should only be used when making a single request. For multiple requests,
@@ -3355,6 +3378,7 @@ async def query(
3355
3378
storage_item ,
3356
3379
result_handler = subscription_handler ,
3357
3380
runtime = runtime ,
3381
+ force_legacy_decode = force_legacy_decode ,
3358
3382
)
3359
3383
result = responses [preprocessed .queryable ][0 ]
3360
3384
if isinstance (result , (list , tuple , int , float )):
0 commit comments