Skip to content

Commit

Permalink
update test framework tx (de)serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
aguycalled committed Mar 25, 2023
1 parent 14dbc73 commit 6980f93
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def deser_string(f):
def ser_string(s):
return ser_compact_size(len(s)) + s

def deser_bytes(f, count):
return f.read(count)

def ser_bytes(s):
return s

def deser_uint256(f):
r = 0
for i in range(8):
Expand Down Expand Up @@ -448,11 +454,11 @@ def __init__(self, point=b"\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
self.p = point

def deserialize(self, f):
self.p = deser_string(f)
self.p = deser_bytes(f, 48)

def serialize(self):
r = b""
r += ser_string(self.p)
r += ser_bytes(self.p)
return r

class MclScalar:
Expand All @@ -462,11 +468,11 @@ def __init__(self, scalar=b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
self.s = scalar

def deserialize(self, f):
self.s = deser_string(f)
self.s = deser_bytes(f, 32)

def serialize(self):
r = b""
r += ser_string(self.s)
r += ser_bytes(self.s)
return r

class BLSCTSignature:
Expand All @@ -476,11 +482,11 @@ def __init__(self, signature=b"\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
self.sig = signature

def deserialize(self, f):
self.sig = deser_string(f)
self.sig = deser_bytes(f, 96)

def serialize(self):
r = b""
r += ser_string(self.sig)
r += ser_bytes(self.sig)
return r

class RangeProof:
Expand Down Expand Up @@ -714,9 +720,9 @@ def is_null(self):

class CTransaction:
__slots__ = ("hash", "nLockTime", "nVersion", "sha256", "vin", "vout",
"wit", "txSig", "balanceSig")
"wit", "txSig")

def __init__(self, tx=None, txSig = BLSCTSignature(), balanceSig = BLSCTSignature()):
def __init__(self, tx=None, txSig = BLSCTSignature()):
if tx is None:
self.nVersion = 2
self.vin = []
Expand All @@ -734,7 +740,6 @@ def __init__(self, tx=None, txSig = BLSCTSignature(), balanceSig = BLSCTSignatur
self.hash = tx.hash
self.wit = copy.deepcopy(tx.wit)
self.txSig = txSig
self.balanceSig = balanceSig

def deserialize(self, f):
self.nVersion = struct.unpack("<i", f.read(4))[0]
Expand All @@ -756,7 +761,6 @@ def deserialize(self, f):
self.wit = CTxWitness()
self.nLockTime = struct.unpack("<I", f.read(4))[0]
if self.nVersion & TX_VERSION_BLSCT_MARKER:
self.balanceSig.deserialize(f)
self.txSig.deserialize(f)
self.sha256 = None
self.hash = None
Expand All @@ -768,7 +772,6 @@ def serialize_without_witness(self):
r += ser_vector(self.vout)
r += struct.pack("<I", self.nLockTime)
if self.nVersion & TX_VERSION_BLSCT_MARKER:
r += self.balanceSig.serialize()
r += self.txSig.serialize()
return r

Expand All @@ -794,7 +797,6 @@ def serialize_with_witness(self):
r += self.wit.serialize()
r += struct.pack("<I", self.nLockTime)
if self.nVersion & TX_VERSION_BLSCT_MARKER:
r += self.balanceSig.serialize()
r += self.txSig.serialize()
return r

Expand Down

0 comments on commit 6980f93

Please sign in to comment.