mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
scripted-diff: test: Use int from_bytes and to_bytes over struct packing
-BEGIN VERIFY SCRIPT- sed -i --regexp-extended 's!struct.unpack\("(|<|>)B", (.*)\)\[0\]!int.from_bytes(\2, "little")!g' ./test/functional/test_framework/messages.py sed -i --regexp-extended 's!struct.unpack\("<(H|I|Q)", (.*)\)\[0\]!int.from_bytes(\2, "little")!g' ./test/functional/test_framework/messages.py sed -i --regexp-extended 's!struct.unpack\("<(h|i|q)", (.*)\)\[0\]!int.from_bytes(\2, "little", signed=True)!g' ./test/functional/test_framework/messages.py sed -i --regexp-extended 's!struct.unpack\(">(H|I|Q)", (.*)\)\[0\]!int.from_bytes(\2, "big")!g' ./test/functional/test_framework/messages.py sed -i --regexp-extended 's!struct.pack\("<?B", (.*)\)!\1.to_bytes(1, "little")!g' ./test/functional/test_framework/messages.py sed -i --regexp-extended 's!struct.pack\("<I", (.*)\)!\1.to_bytes(4, "little")!g' ./test/functional/test_framework/messages.py sed -i --regexp-extended 's!struct.pack\("<i", (.*)\)!\1.to_bytes(4, "little", signed=True)!g' ./test/functional/test_framework/messages.py sed -i --regexp-extended 's!struct.pack\("<Q", (.*)\)!\1.to_bytes(8, "little")!g' ./test/functional/test_framework/messages.py sed -i --regexp-extended 's!struct.pack\("<q", (.*)\)!\1.to_bytes(8, "little", signed=True)!g' ./test/functional/test_framework/messages.py sed -i --regexp-extended 's!struct.pack\(">H", (.*)\)!\1.to_bytes(2, "big")!g' ./test/functional/test_framework/messages.py -END VERIFY SCRIPT-
This commit is contained in:
parent
fafc0d68ee
commit
fa3fa86dda
1 changed files with 98 additions and 98 deletions
|
@ -90,7 +90,7 @@ def hash256(s):
|
|||
def ser_compact_size(l):
|
||||
r = b""
|
||||
if l < 253:
|
||||
r = struct.pack("B", l)
|
||||
r = l.to_bytes(1, "little")
|
||||
elif l < 0x10000:
|
||||
r = struct.pack("<BH", 253, l)
|
||||
elif l < 0x100000000:
|
||||
|
@ -101,13 +101,13 @@ def ser_compact_size(l):
|
|||
|
||||
|
||||
def deser_compact_size(f):
|
||||
nit = struct.unpack("<B", f.read(1))[0]
|
||||
nit = int.from_bytes(f.read(1), "little")
|
||||
if nit == 253:
|
||||
nit = struct.unpack("<H", f.read(2))[0]
|
||||
nit = int.from_bytes(f.read(2), "little")
|
||||
elif nit == 254:
|
||||
nit = struct.unpack("<I", f.read(4))[0]
|
||||
nit = int.from_bytes(f.read(4), "little")
|
||||
elif nit == 255:
|
||||
nit = struct.unpack("<Q", f.read(8))[0]
|
||||
nit = int.from_bytes(f.read(8), "little")
|
||||
return nit
|
||||
|
||||
|
||||
|
@ -272,13 +272,13 @@ class CAddress:
|
|||
"""Deserialize from addrv1 format (pre-BIP155)"""
|
||||
if with_time:
|
||||
# VERSION messages serialize CAddress objects without time
|
||||
self.time = struct.unpack("<I", f.read(4))[0]
|
||||
self.nServices = struct.unpack("<Q", f.read(8))[0]
|
||||
self.time = int.from_bytes(f.read(4), "little")
|
||||
self.nServices = int.from_bytes(f.read(8), "little")
|
||||
# We only support IPv4 which means skip 12 bytes and read the next 4 as IPv4 address.
|
||||
f.read(12)
|
||||
self.net = self.NET_IPV4
|
||||
self.ip = socket.inet_ntoa(f.read(4))
|
||||
self.port = struct.unpack(">H", f.read(2))[0]
|
||||
self.port = int.from_bytes(f.read(2), "big")
|
||||
|
||||
def serialize(self, *, with_time=True):
|
||||
"""Serialize in addrv1 format (pre-BIP155)"""
|
||||
|
@ -286,20 +286,20 @@ class CAddress:
|
|||
r = b""
|
||||
if with_time:
|
||||
# VERSION messages serialize CAddress objects without time
|
||||
r += struct.pack("<I", self.time)
|
||||
r += struct.pack("<Q", self.nServices)
|
||||
r += self.time.to_bytes(4, "little")
|
||||
r += self.nServices.to_bytes(8, "little")
|
||||
r += b"\x00" * 10 + b"\xff" * 2
|
||||
r += socket.inet_aton(self.ip)
|
||||
r += struct.pack(">H", self.port)
|
||||
r += self.port.to_bytes(2, "big")
|
||||
return r
|
||||
|
||||
def deserialize_v2(self, f):
|
||||
"""Deserialize from addrv2 format (BIP155)"""
|
||||
self.time = struct.unpack("<I", f.read(4))[0]
|
||||
self.time = int.from_bytes(f.read(4), "little")
|
||||
|
||||
self.nServices = deser_compact_size(f)
|
||||
|
||||
self.net = struct.unpack("B", f.read(1))[0]
|
||||
self.net = int.from_bytes(f.read(1), "little")
|
||||
assert self.net in self.ADDRV2_NET_NAME
|
||||
|
||||
address_length = deser_compact_size(f)
|
||||
|
@ -322,15 +322,15 @@ class CAddress:
|
|||
else:
|
||||
raise Exception(f"Address type not supported")
|
||||
|
||||
self.port = struct.unpack(">H", f.read(2))[0]
|
||||
self.port = int.from_bytes(f.read(2), "big")
|
||||
|
||||
def serialize_v2(self):
|
||||
"""Serialize in addrv2 format (BIP155)"""
|
||||
assert self.net in self.ADDRV2_NET_NAME
|
||||
r = b""
|
||||
r += struct.pack("<I", self.time)
|
||||
r += self.time.to_bytes(4, "little")
|
||||
r += ser_compact_size(self.nServices)
|
||||
r += struct.pack("B", self.net)
|
||||
r += self.net.to_bytes(1, "little")
|
||||
r += ser_compact_size(self.ADDRV2_ADDRESS_LENGTH[self.net])
|
||||
if self.net == self.NET_IPV4:
|
||||
r += socket.inet_aton(self.ip)
|
||||
|
@ -348,7 +348,7 @@ class CAddress:
|
|||
r += socket.inet_pton(socket.AF_INET6, self.ip)
|
||||
else:
|
||||
raise Exception(f"Address type not supported")
|
||||
r += struct.pack(">H", self.port)
|
||||
r += self.port.to_bytes(2, "big")
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -375,12 +375,12 @@ class CInv:
|
|||
self.hash = h
|
||||
|
||||
def deserialize(self, f):
|
||||
self.type = struct.unpack("<I", f.read(4))[0]
|
||||
self.type = int.from_bytes(f.read(4), "little")
|
||||
self.hash = deser_uint256(f)
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<I", self.type)
|
||||
r += self.type.to_bytes(4, "little")
|
||||
r += ser_uint256(self.hash)
|
||||
return r
|
||||
|
||||
|
@ -421,12 +421,12 @@ class COutPoint:
|
|||
|
||||
def deserialize(self, f):
|
||||
self.hash = deser_uint256(f)
|
||||
self.n = struct.unpack("<I", f.read(4))[0]
|
||||
self.n = int.from_bytes(f.read(4), "little")
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += ser_uint256(self.hash)
|
||||
r += struct.pack("<I", self.n)
|
||||
r += self.n.to_bytes(4, "little")
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -448,13 +448,13 @@ class CTxIn:
|
|||
self.prevout = COutPoint()
|
||||
self.prevout.deserialize(f)
|
||||
self.scriptSig = deser_string(f)
|
||||
self.nSequence = struct.unpack("<I", f.read(4))[0]
|
||||
self.nSequence = int.from_bytes(f.read(4), "little")
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += self.prevout.serialize()
|
||||
r += ser_string(self.scriptSig)
|
||||
r += struct.pack("<I", self.nSequence)
|
||||
r += self.nSequence.to_bytes(4, "little")
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -471,12 +471,12 @@ class CTxOut:
|
|||
self.scriptPubKey = scriptPubKey
|
||||
|
||||
def deserialize(self, f):
|
||||
self.nValue = struct.unpack("<q", f.read(8))[0]
|
||||
self.nValue = int.from_bytes(f.read(8), "little", signed=True)
|
||||
self.scriptPubKey = deser_string(f)
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<q", self.nValue)
|
||||
r += self.nValue.to_bytes(8, "little", signed=True)
|
||||
r += ser_string(self.scriptPubKey)
|
||||
return r
|
||||
|
||||
|
@ -575,11 +575,11 @@ class CTransaction:
|
|||
self.wit = copy.deepcopy(tx.wit)
|
||||
|
||||
def deserialize(self, f):
|
||||
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
||||
self.nVersion = int.from_bytes(f.read(4), "little", signed=True)
|
||||
self.vin = deser_vector(f, CTxIn)
|
||||
flags = 0
|
||||
if len(self.vin) == 0:
|
||||
flags = struct.unpack("<B", f.read(1))[0]
|
||||
flags = int.from_bytes(f.read(1), "little")
|
||||
# Not sure why flags can't be zero, but this
|
||||
# matches the implementation in bitcoind
|
||||
if (flags != 0):
|
||||
|
@ -592,16 +592,16 @@ class CTransaction:
|
|||
self.wit.deserialize(f)
|
||||
else:
|
||||
self.wit = CTxWitness()
|
||||
self.nLockTime = struct.unpack("<I", f.read(4))[0]
|
||||
self.nLockTime = int.from_bytes(f.read(4), "little")
|
||||
self.sha256 = None
|
||||
self.hash = None
|
||||
|
||||
def serialize_without_witness(self):
|
||||
r = b""
|
||||
r += struct.pack("<i", self.nVersion)
|
||||
r += self.nVersion.to_bytes(4, "little", signed=True)
|
||||
r += ser_vector(self.vin)
|
||||
r += ser_vector(self.vout)
|
||||
r += struct.pack("<I", self.nLockTime)
|
||||
r += self.nLockTime.to_bytes(4, "little")
|
||||
return r
|
||||
|
||||
# Only serialize with witness when explicitly called for
|
||||
|
@ -610,11 +610,11 @@ class CTransaction:
|
|||
if not self.wit.is_null():
|
||||
flags |= 1
|
||||
r = b""
|
||||
r += struct.pack("<i", self.nVersion)
|
||||
r += self.nVersion.to_bytes(4, "little", signed=True)
|
||||
if flags:
|
||||
dummy = []
|
||||
r += ser_vector(dummy)
|
||||
r += struct.pack("<B", flags)
|
||||
r += flags.to_bytes(1, "little")
|
||||
r += ser_vector(self.vin)
|
||||
r += ser_vector(self.vout)
|
||||
if flags & 1:
|
||||
|
@ -624,7 +624,7 @@ class CTransaction:
|
|||
for _ in range(len(self.wit.vtxinwit), len(self.vin)):
|
||||
self.wit.vtxinwit.append(CTxInWitness())
|
||||
r += self.wit.serialize()
|
||||
r += struct.pack("<I", self.nLockTime)
|
||||
r += self.nLockTime.to_bytes(4, "little")
|
||||
return r
|
||||
|
||||
# Regular serialization is with witness -- must explicitly
|
||||
|
@ -703,34 +703,34 @@ class CBlockHeader:
|
|||
self.hash = None
|
||||
|
||||
def deserialize(self, f):
|
||||
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
||||
self.nVersion = int.from_bytes(f.read(4), "little", signed=True)
|
||||
self.hashPrevBlock = deser_uint256(f)
|
||||
self.hashMerkleRoot = deser_uint256(f)
|
||||
self.nTime = struct.unpack("<I", f.read(4))[0]
|
||||
self.nBits = struct.unpack("<I", f.read(4))[0]
|
||||
self.nNonce = struct.unpack("<I", f.read(4))[0]
|
||||
self.nTime = int.from_bytes(f.read(4), "little")
|
||||
self.nBits = int.from_bytes(f.read(4), "little")
|
||||
self.nNonce = int.from_bytes(f.read(4), "little")
|
||||
self.sha256 = None
|
||||
self.hash = None
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<i", self.nVersion)
|
||||
r += self.nVersion.to_bytes(4, "little", signed=True)
|
||||
r += ser_uint256(self.hashPrevBlock)
|
||||
r += ser_uint256(self.hashMerkleRoot)
|
||||
r += struct.pack("<I", self.nTime)
|
||||
r += struct.pack("<I", self.nBits)
|
||||
r += struct.pack("<I", self.nNonce)
|
||||
r += self.nTime.to_bytes(4, "little")
|
||||
r += self.nBits.to_bytes(4, "little")
|
||||
r += self.nNonce.to_bytes(4, "little")
|
||||
return r
|
||||
|
||||
def calc_sha256(self):
|
||||
if self.sha256 is None:
|
||||
r = b""
|
||||
r += struct.pack("<i", self.nVersion)
|
||||
r += self.nVersion.to_bytes(4, "little", signed=True)
|
||||
r += ser_uint256(self.hashPrevBlock)
|
||||
r += ser_uint256(self.hashMerkleRoot)
|
||||
r += struct.pack("<I", self.nTime)
|
||||
r += struct.pack("<I", self.nBits)
|
||||
r += struct.pack("<I", self.nNonce)
|
||||
r += self.nTime.to_bytes(4, "little")
|
||||
r += self.nBits.to_bytes(4, "little")
|
||||
r += self.nNonce.to_bytes(4, "little")
|
||||
self.sha256 = uint256_from_str(hash256(r))
|
||||
self.hash = hash256(r)[::-1].hex()
|
||||
|
||||
|
@ -874,12 +874,12 @@ class P2PHeaderAndShortIDs:
|
|||
|
||||
def deserialize(self, f):
|
||||
self.header.deserialize(f)
|
||||
self.nonce = struct.unpack("<Q", f.read(8))[0]
|
||||
self.nonce = int.from_bytes(f.read(8), "little")
|
||||
self.shortids_length = deser_compact_size(f)
|
||||
for _ in range(self.shortids_length):
|
||||
# shortids are defined to be 6 bytes in the spec, so append
|
||||
# two zero bytes and read it in as an 8-byte number
|
||||
self.shortids.append(struct.unpack("<Q", f.read(6) + b'\x00\x00')[0])
|
||||
self.shortids.append(int.from_bytes(f.read(6) + b'\x00\x00', "little"))
|
||||
self.prefilled_txn = deser_vector(f, PrefilledTransaction)
|
||||
self.prefilled_txn_length = len(self.prefilled_txn)
|
||||
|
||||
|
@ -887,11 +887,11 @@ class P2PHeaderAndShortIDs:
|
|||
def serialize(self, with_witness=False):
|
||||
r = b""
|
||||
r += self.header.serialize()
|
||||
r += struct.pack("<Q", self.nonce)
|
||||
r += self.nonce.to_bytes(8, "little")
|
||||
r += ser_compact_size(self.shortids_length)
|
||||
for x in self.shortids:
|
||||
# We only want the first 6 bytes
|
||||
r += struct.pack("<Q", x)[0:6]
|
||||
r += x.to_bytes(8, "little")[0:6]
|
||||
if with_witness:
|
||||
r += ser_vector(self.prefilled_txn, "serialize_with_witness")
|
||||
else:
|
||||
|
@ -956,10 +956,10 @@ class HeaderAndShortIDs:
|
|||
|
||||
def get_siphash_keys(self):
|
||||
header_nonce = self.header.serialize()
|
||||
header_nonce += struct.pack("<Q", self.nonce)
|
||||
header_nonce += self.nonce.to_bytes(8, "little")
|
||||
hash_header_nonce_as_str = sha256(header_nonce)
|
||||
key0 = struct.unpack("<Q", hash_header_nonce_as_str[0:8])[0]
|
||||
key1 = struct.unpack("<Q", hash_header_nonce_as_str[8:16])[0]
|
||||
key0 = int.from_bytes(hash_header_nonce_as_str[0:8], "little")
|
||||
key1 = int.from_bytes(hash_header_nonce_as_str[8:16], "little")
|
||||
return [ key0, key1 ]
|
||||
|
||||
# Version 2 compact blocks use wtxid in shortids (rather than txid)
|
||||
|
@ -1057,7 +1057,7 @@ class CPartialMerkleTree:
|
|||
self.vBits = []
|
||||
|
||||
def deserialize(self, f):
|
||||
self.nTransactions = struct.unpack("<i", f.read(4))[0]
|
||||
self.nTransactions = int.from_bytes(f.read(4), "little", signed=True)
|
||||
self.vHash = deser_uint256_vector(f)
|
||||
vBytes = deser_string(f)
|
||||
self.vBits = []
|
||||
|
@ -1066,7 +1066,7 @@ class CPartialMerkleTree:
|
|||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<i", self.nTransactions)
|
||||
r += self.nTransactions.to_bytes(4, "little", signed=True)
|
||||
r += ser_uint256_vector(self.vHash)
|
||||
vBytesArray = bytearray([0x00] * ((len(self.vBits) + 7)//8))
|
||||
for i in range(len(self.vBits)):
|
||||
|
@ -1117,18 +1117,18 @@ class msg_version:
|
|||
self.relay = 0
|
||||
|
||||
def deserialize(self, f):
|
||||
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
||||
self.nServices = struct.unpack("<Q", f.read(8))[0]
|
||||
self.nTime = struct.unpack("<q", f.read(8))[0]
|
||||
self.nVersion = int.from_bytes(f.read(4), "little", signed=True)
|
||||
self.nServices = int.from_bytes(f.read(8), "little")
|
||||
self.nTime = int.from_bytes(f.read(8), "little", signed=True)
|
||||
self.addrTo = CAddress()
|
||||
self.addrTo.deserialize(f, with_time=False)
|
||||
|
||||
self.addrFrom = CAddress()
|
||||
self.addrFrom.deserialize(f, with_time=False)
|
||||
self.nNonce = struct.unpack("<Q", f.read(8))[0]
|
||||
self.nNonce = int.from_bytes(f.read(8), "little")
|
||||
self.strSubVer = deser_string(f).decode('utf-8')
|
||||
|
||||
self.nStartingHeight = struct.unpack("<i", f.read(4))[0]
|
||||
self.nStartingHeight = int.from_bytes(f.read(4), "little", signed=True)
|
||||
|
||||
# Relay field is optional for version 70001 onwards
|
||||
# But, unconditionally check it to match behaviour in bitcoind
|
||||
|
@ -1136,14 +1136,14 @@ class msg_version:
|
|||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<i", self.nVersion)
|
||||
r += struct.pack("<Q", self.nServices)
|
||||
r += struct.pack("<q", self.nTime)
|
||||
r += self.nVersion.to_bytes(4, "little", signed=True)
|
||||
r += self.nServices.to_bytes(8, "little")
|
||||
r += self.nTime.to_bytes(8, "little", signed=True)
|
||||
r += self.addrTo.serialize(with_time=False)
|
||||
r += self.addrFrom.serialize(with_time=False)
|
||||
r += struct.pack("<Q", self.nNonce)
|
||||
r += self.nNonce.to_bytes(8, "little")
|
||||
r += ser_string(self.strSubVer.encode('utf-8'))
|
||||
r += struct.pack("<i", self.nStartingHeight)
|
||||
r += self.nStartingHeight.to_bytes(4, "little", signed=True)
|
||||
r += self.relay.to_bytes(1, "little")
|
||||
return r
|
||||
|
||||
|
@ -1390,11 +1390,11 @@ class msg_ping:
|
|||
self.nonce = nonce
|
||||
|
||||
def deserialize(self, f):
|
||||
self.nonce = struct.unpack("<Q", f.read(8))[0]
|
||||
self.nonce = int.from_bytes(f.read(8), "little")
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<Q", self.nonce)
|
||||
r += self.nonce.to_bytes(8, "little")
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -1409,11 +1409,11 @@ class msg_pong:
|
|||
self.nonce = nonce
|
||||
|
||||
def deserialize(self, f):
|
||||
self.nonce = struct.unpack("<Q", f.read(8))[0]
|
||||
self.nonce = int.from_bytes(f.read(8), "little")
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<Q", self.nonce)
|
||||
r += self.nonce.to_bytes(8, "little")
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -1554,16 +1554,16 @@ class msg_filterload:
|
|||
|
||||
def deserialize(self, f):
|
||||
self.data = deser_string(f)
|
||||
self.nHashFuncs = struct.unpack("<I", f.read(4))[0]
|
||||
self.nTweak = struct.unpack("<I", f.read(4))[0]
|
||||
self.nFlags = struct.unpack("<B", f.read(1))[0]
|
||||
self.nHashFuncs = int.from_bytes(f.read(4), "little")
|
||||
self.nTweak = int.from_bytes(f.read(4), "little")
|
||||
self.nFlags = int.from_bytes(f.read(1), "little")
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += ser_string(self.data)
|
||||
r += struct.pack("<I", self.nHashFuncs)
|
||||
r += struct.pack("<I", self.nTweak)
|
||||
r += struct.pack("<B", self.nFlags)
|
||||
r += self.nHashFuncs.to_bytes(4, "little")
|
||||
r += self.nTweak.to_bytes(4, "little")
|
||||
r += self.nFlags.to_bytes(1, "little")
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -1615,11 +1615,11 @@ class msg_feefilter:
|
|||
self.feerate = feerate
|
||||
|
||||
def deserialize(self, f):
|
||||
self.feerate = struct.unpack("<Q", f.read(8))[0]
|
||||
self.feerate = int.from_bytes(f.read(8), "little")
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<Q", self.feerate)
|
||||
r += self.feerate.to_bytes(8, "little")
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -1636,12 +1636,12 @@ class msg_sendcmpct:
|
|||
|
||||
def deserialize(self, f):
|
||||
self.announce = struct.unpack("<?", f.read(1))[0]
|
||||
self.version = struct.unpack("<Q", f.read(8))[0]
|
||||
self.version = int.from_bytes(f.read(8), "little")
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<?", self.announce)
|
||||
r += struct.pack("<Q", self.version)
|
||||
r += self.version.to_bytes(8, "little")
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -1724,14 +1724,14 @@ class msg_getcfilters:
|
|||
self.stop_hash = stop_hash
|
||||
|
||||
def deserialize(self, f):
|
||||
self.filter_type = struct.unpack("<B", f.read(1))[0]
|
||||
self.start_height = struct.unpack("<I", f.read(4))[0]
|
||||
self.filter_type = int.from_bytes(f.read(1), "little")
|
||||
self.start_height = int.from_bytes(f.read(4), "little")
|
||||
self.stop_hash = deser_uint256(f)
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<B", self.filter_type)
|
||||
r += struct.pack("<I", self.start_height)
|
||||
r += self.filter_type.to_bytes(1, "little")
|
||||
r += self.start_height.to_bytes(4, "little")
|
||||
r += ser_uint256(self.stop_hash)
|
||||
return r
|
||||
|
||||
|
@ -1749,13 +1749,13 @@ class msg_cfilter:
|
|||
self.filter_data = filter_data
|
||||
|
||||
def deserialize(self, f):
|
||||
self.filter_type = struct.unpack("<B", f.read(1))[0]
|
||||
self.filter_type = int.from_bytes(f.read(1), "little")
|
||||
self.block_hash = deser_uint256(f)
|
||||
self.filter_data = deser_string(f)
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<B", self.filter_type)
|
||||
r += self.filter_type.to_bytes(1, "little")
|
||||
r += ser_uint256(self.block_hash)
|
||||
r += ser_string(self.filter_data)
|
||||
return r
|
||||
|
@ -1774,14 +1774,14 @@ class msg_getcfheaders:
|
|||
self.stop_hash = stop_hash
|
||||
|
||||
def deserialize(self, f):
|
||||
self.filter_type = struct.unpack("<B", f.read(1))[0]
|
||||
self.start_height = struct.unpack("<I", f.read(4))[0]
|
||||
self.filter_type = int.from_bytes(f.read(1), "little")
|
||||
self.start_height = int.from_bytes(f.read(4), "little")
|
||||
self.stop_hash = deser_uint256(f)
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<B", self.filter_type)
|
||||
r += struct.pack("<I", self.start_height)
|
||||
r += self.filter_type.to_bytes(1, "little")
|
||||
r += self.start_height.to_bytes(4, "little")
|
||||
r += ser_uint256(self.stop_hash)
|
||||
return r
|
||||
|
||||
|
@ -1800,14 +1800,14 @@ class msg_cfheaders:
|
|||
self.hashes = hashes
|
||||
|
||||
def deserialize(self, f):
|
||||
self.filter_type = struct.unpack("<B", f.read(1))[0]
|
||||
self.filter_type = int.from_bytes(f.read(1), "little")
|
||||
self.stop_hash = deser_uint256(f)
|
||||
self.prev_header = deser_uint256(f)
|
||||
self.hashes = deser_uint256_vector(f)
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<B", self.filter_type)
|
||||
r += self.filter_type.to_bytes(1, "little")
|
||||
r += ser_uint256(self.stop_hash)
|
||||
r += ser_uint256(self.prev_header)
|
||||
r += ser_uint256_vector(self.hashes)
|
||||
|
@ -1826,12 +1826,12 @@ class msg_getcfcheckpt:
|
|||
self.stop_hash = stop_hash
|
||||
|
||||
def deserialize(self, f):
|
||||
self.filter_type = struct.unpack("<B", f.read(1))[0]
|
||||
self.filter_type = int.from_bytes(f.read(1), "little")
|
||||
self.stop_hash = deser_uint256(f)
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<B", self.filter_type)
|
||||
r += self.filter_type.to_bytes(1, "little")
|
||||
r += ser_uint256(self.stop_hash)
|
||||
return r
|
||||
|
||||
|
@ -1849,13 +1849,13 @@ class msg_cfcheckpt:
|
|||
self.headers = headers
|
||||
|
||||
def deserialize(self, f):
|
||||
self.filter_type = struct.unpack("<B", f.read(1))[0]
|
||||
self.filter_type = int.from_bytes(f.read(1), "little")
|
||||
self.stop_hash = deser_uint256(f)
|
||||
self.headers = deser_uint256_vector(f)
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<B", self.filter_type)
|
||||
r += self.filter_type.to_bytes(1, "little")
|
||||
r += ser_uint256(self.stop_hash)
|
||||
r += ser_uint256_vector(self.headers)
|
||||
return r
|
||||
|
@ -1873,13 +1873,13 @@ class msg_sendtxrcncl:
|
|||
self.salt = 0
|
||||
|
||||
def deserialize(self, f):
|
||||
self.version = struct.unpack("<I", f.read(4))[0]
|
||||
self.salt = struct.unpack("<Q", f.read(8))[0]
|
||||
self.version = int.from_bytes(f.read(4), "little")
|
||||
self.salt = int.from_bytes(f.read(8), "little")
|
||||
|
||||
def serialize(self):
|
||||
r = b""
|
||||
r += struct.pack("<I", self.version)
|
||||
r += struct.pack("<Q", self.salt)
|
||||
r += self.version.to_bytes(4, "little")
|
||||
r += self.salt.to_bytes(8, "little")
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue