@@ -999,7 +999,7 @@ async def decode_scale(
999
999
else :
1000
1000
if not runtime :
1001
1001
runtime = await self .init_runtime (block_hash = block_hash )
1002
- if runtime .metadata_v15 is not None or force_legacy is True :
1002
+ if runtime .metadata_v15 is not None and force_legacy is False :
1003
1003
obj = decode_by_type_string (type_string , runtime .registry , scale_bytes )
1004
1004
if self .decode_ss58 :
1005
1005
try :
@@ -1930,7 +1930,13 @@ def convert_event_data(data):
1930
1930
if key == "who" :
1931
1931
who = ss58_encode (bytes (value [0 ]), self .ss58_format )
1932
1932
attributes ["who" ] = who
1933
- if isinstance (value , dict ):
1933
+ elif key == "from" :
1934
+ who_from = ss58_encode (bytes (value [0 ]), self .ss58_format )
1935
+ attributes ["from" ] = who_from
1936
+ elif key == "to" :
1937
+ who_to = ss58_encode (bytes (value [0 ]), self .ss58_format )
1938
+ attributes ["to" ] = who_to
1939
+ elif isinstance (value , dict ):
1934
1940
# Convert nested single-key dictionaries to their keys as strings
1935
1941
for sub_key , sub_value in value .items ():
1936
1942
if isinstance (sub_value , dict ):
@@ -1958,16 +1964,12 @@ def convert_event_data(data):
1958
1964
block_hash = await self .get_chain_head ()
1959
1965
1960
1966
storage_obj = await self .query (
1961
- module = "System" , storage_function = "Events" , block_hash = block_hash
1967
+ module = "System" , storage_function = "Events" , block_hash = block_hash , force_legacy_decode = True
1962
1968
)
1969
+ # bt-decode Metadata V15 is not ideal for events. Force legacy decoding for this
1963
1970
if storage_obj :
1964
1971
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 )
1972
+ events .append (item )
1971
1973
return events
1972
1974
1973
1975
async def get_metadata (self , block_hash = None ) -> MetadataV15 :
@@ -2175,6 +2177,7 @@ async def _process_response(
2175
2177
storage_item : Optional [ScaleType ] = None ,
2176
2178
result_handler : Optional [ResultHandler ] = None ,
2177
2179
runtime : Optional [Runtime ] = None ,
2180
+ force_legacy_decode : bool = False
2178
2181
) -> tuple [Any , bool ]:
2179
2182
"""
2180
2183
Processes the RPC call response by decoding it, returning it as is, or setting a handler for subscriptions,
@@ -2187,6 +2190,7 @@ async def _process_response(
2187
2190
storage_item: The ScaleType object used for decoding ScaleBytes results
2188
2191
result_handler: the result handler coroutine used for handling longer-running subscriptions
2189
2192
runtime: Optional Runtime to use for decoding. If not specified, the currently-loaded `self.runtime` is used
2193
+ force_legacy_decode: Whether to force the use of the legacy Metadata V14 decoder
2190
2194
2191
2195
Returns:
2192
2196
(decoded response, completion)
@@ -2208,7 +2212,7 @@ async def _process_response(
2208
2212
q = bytes (query_value )
2209
2213
else :
2210
2214
q = query_value
2211
- result = await self .decode_scale (value_scale_type , q , runtime = runtime )
2215
+ result = await self .decode_scale (value_scale_type , q , runtime = runtime , force_legacy = force_legacy_decode )
2212
2216
if asyncio .iscoroutinefunction (result_handler ):
2213
2217
# For multipart responses as a result of subscriptions.
2214
2218
message , bool_result = await result_handler (result , subscription_id )
@@ -2223,6 +2227,7 @@ async def _make_rpc_request(
2223
2227
result_handler : Optional [ResultHandler ] = None ,
2224
2228
attempt : int = 1 ,
2225
2229
runtime : Optional [Runtime ] = None ,
2230
+ force_legacy_decode : bool = False
2226
2231
) -> RequestManager .RequestResults :
2227
2232
request_manager = RequestManager (payloads )
2228
2233
@@ -2267,6 +2272,7 @@ async def _make_rpc_request(
2267
2272
storage_item ,
2268
2273
result_handler ,
2269
2274
runtime = runtime ,
2275
+ force_legacy_decode = force_legacy_decode
2270
2276
)
2271
2277
2272
2278
request_manager .add_response (
@@ -2298,6 +2304,7 @@ async def _make_rpc_request(
2298
2304
storage_item ,
2299
2305
result_handler ,
2300
2306
attempt + 1 ,
2307
+ force_legacy_decode
2301
2308
)
2302
2309
2303
2310
return request_manager .get_results ()
@@ -3323,6 +3330,7 @@ async def query(
3323
3330
subscription_handler = None ,
3324
3331
reuse_block_hash : bool = False ,
3325
3332
runtime : Optional [Runtime ] = None ,
3333
+ force_legacy_decode : bool = False
3326
3334
) -> Optional [Union ["ScaleObj" , Any ]]:
3327
3335
"""
3328
3336
Queries substrate. This should only be used when making a single request. For multiple requests,
@@ -3355,6 +3363,7 @@ async def query(
3355
3363
storage_item ,
3356
3364
result_handler = subscription_handler ,
3357
3365
runtime = runtime ,
3366
+ force_legacy_decode = force_legacy_decode
3358
3367
)
3359
3368
result = responses [preprocessed .queryable ][0 ]
3360
3369
if isinstance (result , (list , tuple , int , float )):
0 commit comments