Change to byte string and use de/ser_string
This commit is contained in:
parent
60f8d26a9b
commit
f3dda029b6
@ -1,6 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
|
|||||||
@ -434,7 +434,7 @@ class CTransaction(object):
|
|||||||
self.nLockTime = 0
|
self.nLockTime = 0
|
||||||
self.sha256 = None
|
self.sha256 = None
|
||||||
self.hash = None
|
self.hash = None
|
||||||
self.txComment = ""
|
self.txComment = b""
|
||||||
else:
|
else:
|
||||||
self.nVersion = tx.nVersion
|
self.nVersion = tx.nVersion
|
||||||
self.vin = copy.deepcopy(tx.vin)
|
self.vin = copy.deepcopy(tx.vin)
|
||||||
@ -443,7 +443,7 @@ class CTransaction(object):
|
|||||||
self.sha256 = tx.sha256
|
self.sha256 = tx.sha256
|
||||||
self.hash = tx.hash
|
self.hash = tx.hash
|
||||||
self.wit = copy.deepcopy(tx.wit)
|
self.wit = copy.deepcopy(tx.wit)
|
||||||
self.txComment = '%s' % tx.txComment
|
self.txComment = b'%s' % tx.txComment
|
||||||
|
|
||||||
def deserialize(self, f):
|
def deserialize(self, f):
|
||||||
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
||||||
@ -463,11 +463,7 @@ class CTransaction(object):
|
|||||||
self.wit.deserialize(f)
|
self.wit.deserialize(f)
|
||||||
self.nLockTime = struct.unpack("<I", f.read(4))[0]
|
self.nLockTime = struct.unpack("<I", f.read(4))[0]
|
||||||
if self.nVersion >= 2:
|
if self.nVersion >= 2:
|
||||||
tx_comment_len = deser_compact_size(f)
|
self.txComment = deser_string(f)
|
||||||
if tx_comment_len > 0:
|
|
||||||
self.txComment = struct.unpack("<s", f.read(tx_comment_len))[0]
|
|
||||||
else:
|
|
||||||
self.txComment = ""
|
|
||||||
self.sha256 = None
|
self.sha256 = None
|
||||||
self.hash = None
|
self.hash = None
|
||||||
|
|
||||||
@ -478,10 +474,7 @@ class CTransaction(object):
|
|||||||
r += ser_vector(self.vout)
|
r += ser_vector(self.vout)
|
||||||
r += struct.pack("<I", self.nLockTime)
|
r += struct.pack("<I", self.nLockTime)
|
||||||
if self.nVersion >= 2:
|
if self.nVersion >= 2:
|
||||||
r += ser_compact_size(len(self.txComment))
|
r += ser_string(self.txComment)
|
||||||
if len(self.txComment) > 0:
|
|
||||||
r += struct.pack("<s", self.txComment)
|
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
# Only serialize with witness when explicitly called for
|
# Only serialize with witness when explicitly called for
|
||||||
@ -506,10 +499,7 @@ class CTransaction(object):
|
|||||||
r += self.wit.serialize()
|
r += self.wit.serialize()
|
||||||
r += struct.pack("<I", self.nLockTime)
|
r += struct.pack("<I", self.nLockTime)
|
||||||
if self.nVersion >= 2:
|
if self.nVersion >= 2:
|
||||||
r += ser_compact_size(len(self.txComment))
|
r += ser_string(self.txComment)
|
||||||
if len(self.txComment) > 0:
|
|
||||||
r += struct.pack("<s", self.txComment)
|
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
# Regular serialization is without witness -- must explicitly
|
# Regular serialization is without witness -- must explicitly
|
||||||
|
|||||||
@ -936,8 +936,6 @@ def SegwitVersion1SignatureHash(script, txTo, inIdx, hashtype, amount):
|
|||||||
ss += struct.pack("<i", txTo.nLockTime)
|
ss += struct.pack("<i", txTo.nLockTime)
|
||||||
ss += struct.pack("<I", hashtype)
|
ss += struct.pack("<I", hashtype)
|
||||||
if txTo.nVersion >= 2:
|
if txTo.nVersion >= 2:
|
||||||
ss += ser_compact_size(len(txTo.txComment))
|
ss += ser_string(txTo.txComment)
|
||||||
if len(txTo.txComment) > 0:
|
|
||||||
ss += struct.pack("<s", txTo.txComment)
|
|
||||||
|
|
||||||
return hash256(ss)
|
return hash256(ss)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user