9
9
from typing_extensions import TypeGuard
10
10
11
11
from chia .types .blockchain_format .program import Program
12
+ from chia .util .byte_types import hexstr_to_bytes
12
13
from chia .util .streamable import (
13
14
Streamable ,
14
15
function_to_convert_one_item ,
@@ -92,6 +93,12 @@ def byte_deserialize_clvm_streamable(
92
93
)
93
94
94
95
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
+
95
102
# TODO: this is more than _just_ a Streamable, but it is also a Streamable and that's
96
103
# useful for now
97
104
def is_clvm_streamable (v : object ) -> TypeGuard [Streamable ]:
@@ -105,9 +112,9 @@ def json_deserialize_with_clvm_streamable(
105
112
) -> _T_Streamable :
106
113
# This function is flawed for compound types because it's highjacking the function_to_convert_one_item func
107
114
# 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 ):
109
116
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
111
118
)
112
119
elif hasattr (streamable_type , "streamable_fields" ):
113
120
old_streamable_fields = streamable_type .streamable_fields ()
@@ -126,7 +133,9 @@ def json_deserialize_with_clvm_streamable(
126
133
)
127
134
)
128
135
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]
130
139
else :
131
140
return function_to_convert_one_item ( # type: ignore[return-value]
132
141
streamable_type ,
0 commit comments