Change to byte string and use de/ser_string

This commit is contained in:
Jeremiah Buddenhagen 2018-01-31 09:47:05 -08:00
parent 60f8d26a9b
commit f3dda029b6
3 changed files with 6 additions and 21 deletions

View File

@ -1,6 +1,3 @@
#!/usr/bin/env python3
# Copyright (c) 2014-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying

View File

@ -434,7 +434,7 @@ class CTransaction(object):
self.nLockTime = 0
self.sha256 = None
self.hash = None
self.txComment = ""
self.txComment = b""
else:
self.nVersion = tx.nVersion
self.vin = copy.deepcopy(tx.vin)
@ -443,7 +443,7 @@ class CTransaction(object):
self.sha256 = tx.sha256
self.hash = tx.hash
self.wit = copy.deepcopy(tx.wit)
self.txComment = '%s' % tx.txComment
self.txComment = b'%s' % tx.txComment
def deserialize(self, f):
self.nVersion = struct.unpack("<i", f.read(4))[0]
@ -463,11 +463,7 @@ class CTransaction(object):
self.wit.deserialize(f)
self.nLockTime = struct.unpack("<I", f.read(4))[0]
if self.nVersion >= 2:
tx_comment_len = deser_compact_size(f)
if tx_comment_len > 0:
self.txComment = struct.unpack("<s", f.read(tx_comment_len))[0]
else:
self.txComment = ""
self.txComment = deser_string(f)
self.sha256 = None
self.hash = None
@ -478,10 +474,7 @@ class CTransaction(object):
r += ser_vector(self.vout)
r += struct.pack("<I", self.nLockTime)
if self.nVersion >= 2:
r += ser_compact_size(len(self.txComment))
if len(self.txComment) > 0:
r += struct.pack("<s", self.txComment)
r += ser_string(self.txComment)
return r
# Only serialize with witness when explicitly called for
@ -506,10 +499,7 @@ class CTransaction(object):
r += self.wit.serialize()
r += struct.pack("<I", self.nLockTime)
if self.nVersion >= 2:
r += ser_compact_size(len(self.txComment))
if len(self.txComment) > 0:
r += struct.pack("<s", self.txComment)
r += ser_string(self.txComment)
return r
# Regular serialization is without witness -- must explicitly

View File

@ -936,8 +936,6 @@ def SegwitVersion1SignatureHash(script, txTo, inIdx, hashtype, amount):
ss += struct.pack("<i", txTo.nLockTime)
ss += struct.pack("<I", hashtype)
if txTo.nVersion >= 2:
ss += ser_compact_size(len(txTo.txComment))
if len(txTo.txComment) > 0:
ss += struct.pack("<s", txTo.txComment)
ss += ser_string(txTo.txComment)
return hash256(ss)