@@ -999,7 +999,7 @@ async def decode_scale(
999999 else :
10001000 if not runtime :
10011001 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 :
10031003 obj = decode_by_type_string (type_string , runtime .registry , scale_bytes )
10041004 if self .decode_ss58 :
10051005 try :
@@ -1930,7 +1930,13 @@ def convert_event_data(data):
19301930 if key == "who" :
19311931 who = ss58_encode (bytes (value [0 ]), self .ss58_format )
19321932 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 ):
19341940 # Convert nested single-key dictionaries to their keys as strings
19351941 for sub_key , sub_value in value .items ():
19361942 if isinstance (sub_value , dict ):
@@ -1958,16 +1964,12 @@ def convert_event_data(data):
19581964 block_hash = await self .get_chain_head ()
19591965
19601966 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
19621968 )
1969+ # bt-decode Metadata V15 is not ideal for events. Force legacy decoding for this
19631970 if storage_obj :
19641971 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 )
19711973 return events
19721974
19731975 async def get_metadata (self , block_hash = None ) -> MetadataV15 :
@@ -2175,6 +2177,7 @@ async def _process_response(
21752177 storage_item : Optional [ScaleType ] = None ,
21762178 result_handler : Optional [ResultHandler ] = None ,
21772179 runtime : Optional [Runtime ] = None ,
2180+ force_legacy_decode : bool = False
21782181 ) -> tuple [Any , bool ]:
21792182 """
21802183 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(
21872190 storage_item: The ScaleType object used for decoding ScaleBytes results
21882191 result_handler: the result handler coroutine used for handling longer-running subscriptions
21892192 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
21902194
21912195 Returns:
21922196 (decoded response, completion)
@@ -2208,7 +2212,7 @@ async def _process_response(
22082212 q = bytes (query_value )
22092213 else :
22102214 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 )
22122216 if asyncio .iscoroutinefunction (result_handler ):
22132217 # For multipart responses as a result of subscriptions.
22142218 message , bool_result = await result_handler (result , subscription_id )
@@ -2223,6 +2227,7 @@ async def _make_rpc_request(
22232227 result_handler : Optional [ResultHandler ] = None ,
22242228 attempt : int = 1 ,
22252229 runtime : Optional [Runtime ] = None ,
2230+ force_legacy_decode : bool = False
22262231 ) -> RequestManager .RequestResults :
22272232 request_manager = RequestManager (payloads )
22282233
@@ -2267,6 +2272,7 @@ async def _make_rpc_request(
22672272 storage_item ,
22682273 result_handler ,
22692274 runtime = runtime ,
2275+ force_legacy_decode = force_legacy_decode
22702276 )
22712277
22722278 request_manager .add_response (
@@ -2298,6 +2304,7 @@ async def _make_rpc_request(
22982304 storage_item ,
22992305 result_handler ,
23002306 attempt + 1 ,
2307+ force_legacy_decode
23012308 )
23022309
23032310 return request_manager .get_results ()
@@ -3323,6 +3330,7 @@ async def query(
33233330 subscription_handler = None ,
33243331 reuse_block_hash : bool = False ,
33253332 runtime : Optional [Runtime ] = None ,
3333+ force_legacy_decode : bool = False
33263334 ) -> Optional [Union ["ScaleObj" , Any ]]:
33273335 """
33283336 Queries substrate. This should only be used when making a single request. For multiple requests,
@@ -3355,6 +3363,7 @@ async def query(
33553363 storage_item ,
33563364 result_handler = subscription_handler ,
33573365 runtime = runtime ,
3366+ force_legacy_decode = force_legacy_decode
33583367 )
33593368 result = responses [preprocessed .queryable ][0 ]
33603369 if isinstance (result , (list , tuple , int , float )):
0 commit comments