1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from enum import Enum
15+ from enum import IntEnum , unique
1616from typing import NamedTuple
1717
1818from hathorlib .conf import HathorSettings
2525ON_CHAIN_BLUEPRINT_VERSION : int = 1
2626
2727
28- class CodeKind (Enum ):
28+ @unique
29+ class CodeKind (IntEnum ):
2930 """ Represents what type of code and format is being used, to allow new code/compression types in the future.
3031 """
3132
32- PYTHON_GZIP = 'python+gzip'
33+ PYTHON_ZLIB = 1
3334
3435 def __bytes__ (self ) -> bytes :
35- return self .value . encode ( )
36+ return int_to_bytes ( number = self .value , size = 1 )
3637
3738
3839class Code (NamedTuple ):
@@ -47,11 +48,10 @@ class Code(NamedTuple):
4748
4849 def __bytes__ (self ) -> bytes :
4950 # Code serialization format: [kind:variable bytes][null byte][data:variable bytes]
50- if self .kind is not CodeKind .PYTHON_GZIP :
51+ if self .kind is not CodeKind .PYTHON_ZLIB :
5152 raise ValueError ('Invalid code kind value' )
5253 buf = bytearray ()
5354 buf .extend (bytes (self .kind ))
54- buf .append (0 )
5555 buf .extend (self .data )
5656 return bytes (buf )
5757
@@ -63,11 +63,10 @@ def from_bytes(cls, data: bytes) -> 'Code':
6363 check that.
6464 """
6565 data = bytearray (data )
66- cut_at = data .index (0 )
67- kind = CodeKind (data [0 :cut_at ].decode ())
68- if kind is not CodeKind .PYTHON_GZIP :
66+ kind = CodeKind (data [0 ])
67+ if kind is not CodeKind .PYTHON_ZLIB :
6968 raise ValueError ('Code kind not supported' )
70- compressed_code = data [cut_at + 1 :]
69+ compressed_code = data [1 :]
7170 return cls (kind , compressed_code )
7271
7372
@@ -83,7 +82,7 @@ def __init__(self) -> None:
8382 self .nc_pubkey : bytes = b''
8483 self .nc_signature : bytes = b''
8584
86- self .code : Code = Code (CodeKind .PYTHON_GZIP , b'' )
85+ self .code : Code = Code (CodeKind .PYTHON_ZLIB , b'' )
8786
8887 def serialize_code (self ) -> bytes :
8988 """Serialization of self.code, to be used for the serialization of this transaction type."""
0 commit comments