Skip to content

Commit 7c0dfec

Browse files
committed
refactor: move from_binary helper from signet miner to test framework
Can be easily reviewed with `--color-moved=dimmed-zebra`.
1 parent 597a4b3 commit 7c0dfec

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

contrib/signet/miner

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ import sys
1515
import time
1616
import subprocess
1717

18-
from io import BytesIO
19-
2018
PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
2119
PATH_BASE_TEST_FUNCTIONAL = os.path.abspath(os.path.join(PATH_BASE_CONTRIB_SIGNET, "..", "..", "test", "functional"))
2220
sys.path.insert(0, PATH_BASE_TEST_FUNCTIONAL)
2321

2422
from test_framework.blocktools import get_witness_script, script_BIP34_coinbase_height # noqa: E402
25-
from test_framework.messages import CBlock, CBlockHeader, COutPoint, CTransaction, CTxIn, CTxInWitness, CTxOut, from_hex, deser_string, ser_compact_size, ser_string, ser_uint256, tx_from_hex # noqa: E402
23+
from test_framework.messages import CBlock, CBlockHeader, COutPoint, CTransaction, CTxIn, CTxInWitness, CTxOut, from_binary, from_hex, deser_string, ser_compact_size, ser_string, ser_uint256, tx_from_hex # noqa: E402
2624
from test_framework.script import CScriptOp # noqa: E402
2725

2826
logging.basicConfig(
@@ -36,19 +34,6 @@ RE_MULTIMINER = re.compile("^(\d+)(-(\d+))?/(\d+)$")
3634

3735
# #### some helpers that could go into test_framework
3836

39-
# like from_hex, but without the hex part
40-
def from_binary(cls, stream):
41-
"""deserialize a binary stream (or bytes object) into an object"""
42-
# handle bytes object by turning it into a stream
43-
was_bytes = isinstance(stream, bytes)
44-
if was_bytes:
45-
stream = BytesIO(stream)
46-
obj = cls()
47-
obj.deserialize(stream)
48-
if was_bytes:
49-
assert len(stream.read()) == 0
50-
return obj
51-
5237
class PSBTMap:
5338
"""Class for serializing and deserializing PSBT maps"""
5439

test/functional/test_framework/messages.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ def tx_from_hex(hex_string):
208208
return from_hex(CTransaction(), hex_string)
209209

210210

211+
# like from_hex, but without the hex part
212+
def from_binary(cls, stream):
213+
"""deserialize a binary stream (or bytes object) into an object"""
214+
# handle bytes object by turning it into a stream
215+
was_bytes = isinstance(stream, bytes)
216+
if was_bytes:
217+
stream = BytesIO(stream)
218+
obj = cls()
219+
obj.deserialize(stream)
220+
if was_bytes:
221+
assert len(stream.read()) == 0
222+
return obj
223+
224+
211225
# Objects that map to bitcoind objects, which can be serialized/deserialized
212226

213227

0 commit comments

Comments
 (0)