Skip to content

Freeze cbor tags as they are supposed to be hashable #227

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

Closed
wants to merge 1 commit into from
Closed
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
94 changes: 89 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions pycardano/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from frozenlist import FrozenList
import re
import typing
from collections import OrderedDict, UserList, defaultdict
Expand Down Expand Up @@ -149,10 +150,10 @@ def default_encoder(
encoder: CBOREncoder, value: Union[CBORSerializable, IndefiniteList]
):
"""A fallback function that encodes CBORSerializable to CBOR"""
assert isinstance(value, (CBORSerializable, IndefiniteList, RawCBOR)), (
assert isinstance(value, (CBORSerializable, IndefiniteList, RawCBOR, FrozenList)), (
f"Type of input value is not CBORSerializable, " f"got {type(value)} instead."
)
if isinstance(value, IndefiniteList):
if isinstance(value, IndefiniteList) or isinstance(value, FrozenList):
# Currently, cbor2 doesn't support indefinite list, therefore we need special
# handling here to explicitly write header (b'\x9f'), each body item, and footer (b'\xff') to
# the output bytestring.
Expand Down Expand Up @@ -253,7 +254,9 @@ def _dfs(value):
elif isinstance(value, IndefiniteList):
return IndefiniteList([_helper(k) for k in value])
elif isinstance(value, CBORTag):
return CBORTag(value.tag, _helper(value.value))
value_list = FrozenList(_helper(value.value))
value_list.freeze()
return CBORTag(value.tag, value_list)
else:
return value

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cose = "0.9.dev8"
pprintpp = "^0.4.0"
mnemonic = "^0.20"
ECPy = "^1.2.5"
frozenlist = "^1.3.3"

[tool.poetry.dev-dependencies]
Sphinx = "^4.3.2"
Expand Down