@@ -735,9 +735,9 @@ def serialize(self, value: Union[list, bytes]) -> Union[list, str]:
735
735
else :
736
736
return f'0x{ value .hex ()} '
737
737
738
- def deserialize (self , value : Union [list , str , bytes ]) -> Union [list , bytes ]:
738
+ def deserialize (self , value : Union [list , str , bytes , bytearray ]) -> Union [list , bytes ]:
739
739
740
- if type (value ) not in [list , str , bytes ]:
740
+ if type (value ) not in [list , str , bytes , bytearray ]:
741
741
raise ScaleDeserializeException ('value should be of type list, str or bytes' )
742
742
743
743
if type (value ) is str :
@@ -749,6 +749,9 @@ def deserialize(self, value: Union[list, str, bytes]) -> Union[list, bytes]:
749
749
if len (value ) != self .length :
750
750
raise ScaleDeserializeException ('Length of array does not match size of value' )
751
751
752
+ if type (value ) is bytearray :
753
+ value = bytes (value )
754
+
752
755
if type (value ) is bytes :
753
756
if self .type_def is not U8 :
754
757
raise ScaleDeserializeException ('Only an Array of U8 can be represented as (hex)bytes' )
@@ -950,10 +953,13 @@ def _encode(self, value: Union[str, bytes]) -> ScaleBytes:
950
953
def serialize (self , value : bytes ) -> str :
951
954
return f'0x{ value .hex ()} '
952
955
953
- def deserialize (self , value : Union [str , bytes ]) -> bytes :
956
+ def deserialize (self , value : Union [str , bytes , bytearray ]) -> bytes :
954
957
if type (value ) is str :
955
958
value = bytes .fromhex (value [2 :])
956
959
960
+ if type (value ) is bytearray :
961
+ value = bytes (value )
962
+
957
963
if type (value ) is not bytes :
958
964
raise ScaleDeserializeException ('value should be of type str or bytes' )
959
965
0 commit comments