Skip to content

Commit 2f09816

Browse files
authored
Merge pull request #66 from HathorNetwork/dev
Release v0.11.0
2 parents f0d9bd3 + 6448c73 commit 2f09816

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

hathorlib/nanocontracts/on_chain_blueprint.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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
1616
from typing import NamedTuple
1717

1818
from hathorlib.conf import HathorSettings
@@ -25,14 +25,15 @@
2525
ON_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

3839
class 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."""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
[tool.poetry]
1616
name = "hathorlib"
17-
version = "0.10.0"
17+
version = "0.11.0"
1818
description = "Hathor Network base objects library"
1919
authors = ["Hathor Team <contact@hathor.network>"]
2020
license = "Apache-2.0"

tests/test_on_chain_blueprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _get_ocb(self):
1919
b'\xf6\xf0`g\x1b0\xb6\xca\x1b\xed\x83:N\xa0\x98\xd2' \
2020
b'\xdf\x02!\x00\xbe\xf85\xf6O`\xfed`Ip\xe2a\xc4\x03vv' \
2121
b'\xec\x94\ny?\xde\x90\xc3\x12\x9c\xd8\xdd\xd8\xe5\r'
22-
code = Code(CodeKind.PYTHON_GZIP, b'')
22+
code = Code(CodeKind.PYTHON_ZLIB, b'')
2323
ocb.code = code
2424
return ocb
2525

0 commit comments

Comments
 (0)