Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions hathor/transaction/headers/nano_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _serialize_action(self, action: NanoHeaderAction) -> bytes:
]
return b''.join(ret)

def _serialize_without_header_id(self, *, skip_signature: bool) -> deque[bytes]:
def _serialize(self, *, skip_signature: bool) -> bytes:
"""Serialize the header with the option to skip the signature."""
encoded_method = self.nc_method.encode('ascii')

Expand All @@ -230,16 +230,14 @@ def _serialize_without_header_id(self, *, skip_signature: bool) -> deque[bytes]:
ret.append(self.nc_script)
else:
ret.append(leb128.encode_unsigned(0, max_bytes=_NC_SCRIPT_LEN_MAX_BYTES))
return ret

def serialize(self) -> bytes:
ret = self._serialize_without_header_id(skip_signature=False)
ret.appendleft(VertexHeaderId.NANO_HEADER.value)
return b''.join(ret)

def serialize(self) -> bytes:
return self._serialize(skip_signature=False)

def get_sighash_bytes(self) -> bytes:
ret = self._serialize_without_header_id(skip_signature=True)
return b''.join(ret)
return self._serialize(skip_signature=True)

def is_creating_a_new_contract(self) -> bool:
"""Return true if this transaction is creating a new contract."""
Expand Down
4 changes: 2 additions & 2 deletions tests/nanocontracts/test_nanocontract.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
MissingStackItems,
TooManySigOps,
)
from hathor.transaction.headers import NanoHeader, VertexHeaderId
from hathor.transaction.headers import NanoHeader
from hathor.transaction.headers.nano_header import NanoHeaderAction
from hathor.transaction.scripts import P2PKH, HathorScript, Opcode
from hathor.transaction.validation_state import ValidationState
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_serialization_skip_signature(self) -> None:
nc = self._get_nc()
nano_header = nc.get_nano_header()
sighash_bytes = nano_header.get_sighash_bytes()
deserialized, buf = NanoHeader.deserialize(Transaction(), VertexHeaderId.NANO_HEADER.value + sighash_bytes)
deserialized, buf = NanoHeader.deserialize(Transaction(), sighash_bytes)

assert len(buf) == 0
assert deserialized.nc_seqnum == nano_header.nc_seqnum
Expand Down
Loading