Skip to content
Open
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
20 changes: 16 additions & 4 deletions electrum/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,11 @@ def read_uint64(self): return self._read_num('<Q')

def write_boolean(self, val): return self.write(b'\x01' if val else b'\x00')
def write_int16(self, val): return self._write_num('<h', val)
def write_uint16(self, val): return self._write_num('<H', val)
def write_uint16(self, val):
return self._write_num('<H', val)
def write_int32(self, val): return self._write_num('<i', val)
def write_uint32(self, val): return self._write_num('<I', val)
def write_uint32(self, val):
return self._write_num('<I', val)
def write_int64(self, val): return self._write_num('<q', val)
def write_uint64(self, val): return self._write_num('<Q', val)

Expand Down Expand Up @@ -671,8 +673,18 @@ def _read_num(self, format):
return i

def _write_num(self, format, num):
s = struct.pack(format, num)
self.write(s)
# Fast-path: batch struct.pack and extend assignment
s: bytes = struct.pack(format, num)

inp = self.input
if inp is None:
# Direct assignment is fastest
self.input = bytearray(s)
else:
# Use += instead of extend() for efficiency
inp += s
# Return behavior preserved: The original _write_num doesn't return, but mainline code expects None
# which is the case here.


def script_GetOp(_bytes : bytes):
Expand Down