Skip to content

Commit 46ea7fd

Browse files
committed
Some edge cases
1 parent 2587a39 commit 46ea7fd

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

chia/wallet/util/clvm_streamable.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing_extensions import TypeGuard
1010

1111
from chia.types.blockchain_format.program import Program
12+
from chia.util.byte_types import hexstr_to_bytes
1213
from chia.util.streamable import (
1314
Streamable,
1415
function_to_convert_one_item,
@@ -92,6 +93,12 @@ def byte_deserialize_clvm_streamable(
9293
)
9394

9495

96+
# TODO: this is more than _just_ a Streamable, but it is also a Streamable and that's
97+
# useful for now
98+
def is_clvm_streamable_type(v: type[object]) -> bool:
99+
return isinstance(v, type) and issubclass(v, Streamable) and hasattr(v, "_clvm_streamable")
100+
101+
95102
# TODO: this is more than _just_ a Streamable, but it is also a Streamable and that's
96103
# useful for now
97104
def is_clvm_streamable(v: object) -> TypeGuard[Streamable]:
@@ -105,9 +112,9 @@ def json_deserialize_with_clvm_streamable(
105112
) -> _T_Streamable:
106113
# This function is flawed for compound types because it's highjacking the function_to_convert_one_item func
107114
# which does not call back to it. More examination is needed.
108-
if isinstance(json_dict, str):
115+
if is_clvm_streamable_type(streamable_type) and isinstance(json_dict, str):
109116
return byte_deserialize_clvm_streamable(
110-
bytes.fromhex(json_dict), streamable_type, translation_layer=translation_layer
117+
hexstr_to_bytes(json_dict), streamable_type, translation_layer=translation_layer
111118
)
112119
elif hasattr(streamable_type, "streamable_fields"):
113120
old_streamable_fields = streamable_type.streamable_fields()
@@ -126,7 +133,9 @@ def json_deserialize_with_clvm_streamable(
126133
)
127134
)
128135
setattr(streamable_type, "_streamable_fields", tuple(new_streamable_fields))
129-
return streamable_type.from_json_dict(json_dict)
136+
return streamable_type.from_json_dict(json_dict) # type: ignore[arg-type]
137+
elif hasattr(streamable_type, "from_json_dict"):
138+
return streamable_type.from_json_dict(json_dict) # type: ignore[arg-type]
130139
else:
131140
return function_to_convert_one_item( # type: ignore[return-value]
132141
streamable_type,

0 commit comments

Comments
 (0)