From e2d5ae958245aab1f25a7384e682cb69ce1f8e39 Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Thu, 28 Sep 2023 10:55:59 +0200 Subject: [PATCH] api: fix `Map` key processing --- neo3/api/helpers/unwrap.py | 7 +++++++ neo3/api/noderpc.py | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/neo3/api/helpers/unwrap.py b/neo3/api/helpers/unwrap.py index 5562006..a6e1f06 100644 --- a/neo3/api/helpers/unwrap.py +++ b/neo3/api/helpers/unwrap.py @@ -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() diff --git a/neo3/api/noderpc.py b/neo3/api/noderpc.py index 95aac47..9d04708 100644 --- a/neo3/api/noderpc.py +++ b/neo3/api/noderpc.py @@ -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_)