Skip to content

Commit

Permalink
api: fix Map key processing
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Sep 28, 2023
1 parent 4ac098c commit e2d5ae9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 7 additions & 0 deletions neo3/api/helpers/unwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ def as_dict(res: noderpc.ExecutionResult, idx: int = 0) -> dict:
Raises:
ValueError: if the index is out of range, or the value cannot be converted to a dict.
Warning:
Accepted key types on the Virtual Machine side are `int`, `str` and `bytes`.
However, when data is returned there is no way to differentiate between
the key being of type `str` or `bytes` as the RPC node will encode both as a `ByteString`.
The dictionary returned will return such types as `bytes` and it is the user responsibility to decode
them to a `str` if needed.
"""
return item(res, idx).as_dict()

Expand Down
5 changes: 0 additions & 5 deletions neo3/api/noderpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,6 @@ def _parse_stack_item(item: _Item) -> StackItem:
map_ = []
for stack_item in item["value"]:
key = ExecutionResult._parse_stack_item(stack_item["key"])
key_type = StackItemType(stack_item["key"]["type"])
if key_type == StackItemType.BYTE_STRING:
key.value = key.value.decode()
else:
key.value = str(key.value)
value = ExecutionResult._parse_stack_item(stack_item["value"])
map_.append((key, value))
return MapStackItem(type_, map_)
Expand Down

0 comments on commit e2d5ae9

Please sign in to comment.