scripted-diff: test: Use int.to_bytes over struct packing

-BEGIN VERIFY SCRIPT-
 sed -i --regexp-extended 's!struct.pack\(.<?B., (.*)\)!\1.to_bytes(1, "little")!g'             $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<I., (.*)\)!\1.to_bytes(4, "little")!g'              $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<H., (.*)\)!\1.to_bytes(2, "little")!g'              $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<i., (.*)\)!\1.to_bytes(4, "little", signed=True)!g' $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<q., (.*)\)!\1.to_bytes(8, "little", signed=True)!g' $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.>H., (.*)\)!\1.to_bytes(2, "big")!g'                 $( git grep -l struct.pack )
-END VERIFY SCRIPT-
This commit is contained in:
MarcoFalke
2024-02-07 11:26:05 +01:00
parent faf2a975ad
commit fa826db477
6 changed files with 32 additions and 32 deletions

View File

@@ -115,7 +115,7 @@ def parse_spec(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:
@@ -129,10 +129,10 @@ def bip155_serialize(spec):
Serialize (networkID, addr, port) tuple to BIP155 binary format.
'''
r = b""
r += struct.pack('B', spec[0].value)
r += spec[0].value.to_bytes(1, "little")
r += ser_compact_size(len(spec[1]))
r += spec[1]
r += struct.pack('>H', spec[2])
r += spec[2].to_bytes(2, "big")
return r
def process_nodes(g, f, structname):

View File

@@ -52,10 +52,10 @@ def signet_txs(block, challenge):
mroot = block.get_merkle_root(hashes)
sd = b""
sd += struct.pack("<i", block.nVersion)
sd += block.nVersion.to_bytes(4, "little", signed=True)
sd += ser_uint256(block.hashPrevBlock)
sd += ser_uint256(mroot)
sd += struct.pack("<I", block.nTime)
sd += block.nTime.to_bytes(4, "little")
to_spend = CTransaction()
to_spend.nVersion = 0