refactor: move from_binary helper from signet miner to test framework

Can be easily reviewed with `--color-moved=dimmed-zebra`.
This commit is contained in:
Sebastian Falbesoner
2022-07-16 01:56:56 +02:00
parent 597a4b35f6
commit 7c0dfec2dd
2 changed files with 15 additions and 16 deletions

View File

@@ -208,6 +208,20 @@ def tx_from_hex(hex_string):
return from_hex(CTransaction(), hex_string)
# like from_hex, but without the hex part
def from_binary(cls, stream):
"""deserialize a binary stream (or bytes object) into an object"""
# handle bytes object by turning it into a stream
was_bytes = isinstance(stream, bytes)
if was_bytes:
stream = BytesIO(stream)
obj = cls()
obj.deserialize(stream)
if was_bytes:
assert len(stream.read()) == 0
return obj
# Objects that map to bitcoind objects, which can be serialized/deserialized