aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-06-06 19:18:55 -0400
committerAva Chow <github@achow101.com>2024-06-06 19:18:55 -0400
commit4a020ca443ba370bf41583962d16aa8551876f53 (patch)
treea060fba6f2c2c26f3694666d8d6612e772809f31 /contrib
parent1040a1fc807ed984020eeaa6e90b5bf070b61b05 (diff)
parentfa52e13ee81fcc7543890dbd6986fcb55168583f (diff)
Merge bitcoin/bitcoin#29401: test: Remove struct.pack from almost all places
fa52e13ee81fcc7543890dbd6986fcb55168583f test: Remove struct.pack from almost all places (MarcoFalke) fa826db477a981b48bff53021f9695a5f6682dc0 scripted-diff: test: Use int.to_bytes over struct packing (MarcoFalke) faf2a975ad46799d075e3a70c699da0d8182aab9 test: Use int.to_bytes over struct packing (MarcoFalke) faf3cd659a72473a1aa73c4367a145f4ec64f146 test: Normalize struct.pack format (MarcoFalke) Pull request description: `struct.pack` has many issues: * The format string consists of characters that may be confusing and may need to be looked up in the documentation, as opposed to using easy to understand self-documenting code. This lead to many test bugs, which weren't hit, which is fine, but still confusing. Ref: https://github.com/bitcoin/bitcoin/pull/29400, https://github.com/bitcoin/bitcoin/pull/29399, https://github.com/bitcoin/bitcoin/pull/29363, fa3886b7c69cbbe564478f30bb2c35e9e6b1cffa, ... Fix all issues by using the built-in `int` helpers `to_bytes` via a scripted diff. Review notes: * For `struct.pack` and `int.to_bytes` the error behavior is the same, although the error messages are not identical. * Two `struct.pack` remain. One for float serialization in a C++ code comment, and one for native serialization. ACKs for top commit: achow101: ACK fa52e13ee81fcc7543890dbd6986fcb55168583f rkrux: tACK [fa52e13](https://github.com/bitcoin/bitcoin/pull/29401/commits/fa52e13ee81fcc7543890dbd6986fcb55168583f) theStack: Code-review ACK fa52e13ee81fcc7543890dbd6986fcb55168583f Tree-SHA512: ee80d935b68ae43d1654b047e84ceb80abbd20306df35cca848b3f7874634b518560ddcbc7e714e2e7a19241e153dee64556dc4701287ae811e26e4f8c57fe3e
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/seeds/generate-seeds.py13
-rwxr-xr-xcontrib/signet/miner4
2 files changed, 8 insertions, 9 deletions
diff --git a/contrib/seeds/generate-seeds.py b/contrib/seeds/generate-seeds.py
index e921757802..f67e7b0f4c 100755
--- a/contrib/seeds/generate-seeds.py
+++ b/contrib/seeds/generate-seeds.py
@@ -29,7 +29,6 @@ These should be pasted into `src/chainparamsseeds.h`.
from base64 import b32decode
from enum import Enum
-import struct
import sys
import os
import re
@@ -115,13 +114,13 @@ 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)
+ r = (253).to_bytes(1, "little") + l.to_bytes(2, "little")
elif l < 0x100000000:
- r = struct.pack("<BI", 254, l)
+ r = (254).to_bytes(1, "little") + l.to_bytes(4, "little")
else:
- r = struct.pack("<BQ", 255, l)
+ r = (255).to_bytes(1, "little") + l.to_bytes(8, "little")
return r
def bip155_serialize(spec):
@@ -129,10 +128,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):
diff --git a/contrib/signet/miner b/contrib/signet/miner
index e5daf9f993..7b7b3feb39 100755
--- a/contrib/signet/miner
+++ b/contrib/signet/miner
@@ -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