Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: fix Map key processing #283

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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