Skip to content

Commit 50e70b2

Browse files
committed
Fix events decoding.
1 parent 01f4e71 commit 50e70b2

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from websockets.asyncio.client import connect
3535
from websockets.exceptions import ConnectionClosed, WebSocketException
3636

37-
from async_substrate_interface.const import SS58_FORMAT
3837
from async_substrate_interface.errors import (
3938
SubstrateRequestException,
4039
ExtrinsicNotFound,
@@ -989,7 +988,7 @@ async def decode_scale(
989988
return None
990989
if type_string == "scale_info::0": # Is an AccountId
991990
# Decode AccountId bytes to SS58 address
992-
return ss58_encode(scale_bytes, SS58_FORMAT)
991+
return ss58_encode(scale_bytes, self.ss58_format)
993992
else:
994993
if not runtime:
995994
runtime = await self.init_runtime(block_hash=block_hash)
@@ -1911,11 +1910,16 @@ def convert_event_data(data):
19111910
attributes = attributes_data
19121911
if isinstance(attributes, dict):
19131912
for key, value in attributes.items():
1913+
if key == "who":
1914+
who = ss58_encode(bytes(value[0]), self.ss58_format)
1915+
attributes["who"] = who
19141916
if isinstance(value, dict):
19151917
# Convert nested single-key dictionaries to their keys as strings
1916-
sub_key = next(iter(value.keys()))
1917-
if value[sub_key] == ():
1918-
attributes[key] = sub_key
1918+
for sub_key, sub_value in value.items():
1919+
if isinstance(sub_value, dict):
1920+
for sub_sub_key, sub_sub_value in sub_value.items():
1921+
if sub_sub_value == ():
1922+
attributes[key][sub_key] = sub_sub_key
19191923

19201924
# Create the converted dictionary
19211925
converted = {

async_substrate_interface/sync_substrate.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from websockets.sync.client import connect, ClientConnection
1818
from websockets.exceptions import ConnectionClosed
1919

20-
from async_substrate_interface.const import SS58_FORMAT
2120
from async_substrate_interface.errors import (
2221
ExtrinsicNotFound,
2322
SubstrateRequestException,
@@ -688,7 +687,7 @@ def decode_scale(
688687
"""
689688
if type_string == "scale_info::0": # Is an AccountId
690689
# Decode AccountId bytes to SS58 address
691-
return ss58_encode(scale_bytes, SS58_FORMAT)
690+
return ss58_encode(scale_bytes, self.ss58_format)
692691
else:
693692
if self.runtime.metadata_v15 is not None:
694693
obj = decode_by_type_string(
@@ -1583,11 +1582,16 @@ def convert_event_data(data):
15831582
attributes = attributes_data
15841583
if isinstance(attributes, dict):
15851584
for key, value in attributes.items():
1585+
if key == "who":
1586+
who = ss58_encode(bytes(value[0]), self.ss58_format)
1587+
attributes["who"] = who
15861588
if isinstance(value, dict):
15871589
# Convert nested single-key dictionaries to their keys as strings
1588-
sub_key = next(iter(value.keys()))
1589-
if value[sub_key] == ():
1590-
attributes[key] = sub_key
1590+
for sub_key, sub_value in value.items():
1591+
if isinstance(sub_value, dict):
1592+
for sub_sub_key, sub_sub_value in sub_value.items():
1593+
if sub_sub_value == ():
1594+
attributes[key][sub_key] = sub_sub_key
15911595

15921596
# Create the converted dictionary
15931597
converted = {

0 commit comments

Comments
 (0)