commit a6841cbd5fb826eb12cf562eaeaf4929248a6dc8
parent 87aee100470be979bb324d186559441e5c914b6a
Author: SomberNight <somber.night@protonmail.com>
Date: Tue, 13 Mar 2018 01:02:03 +0100
fix #4099: serialisation of txns with negative version number
Diffstat:
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/lib/bitcoin.py b/lib/bitcoin.py
@@ -144,6 +144,9 @@ def rev_hex(s):
def int_to_hex(i, length=1):
assert isinstance(i, int)
+ if i < 0:
+ # two's complement
+ i = pow(256, length) + i
s = hex(i)[2:].rstrip('L')
s = "0"*(2*length - len(s)) + s
return rev_hex(s)
diff --git a/lib/tests/test_transaction.py b/lib/tests/test_transaction.py
@@ -265,6 +265,11 @@ class TestTransaction(unittest.TestCase):
txid = 'f570d5d1e965ee61bcc7005f8fefb1d3abbed9d7ddbe035e2a68fa07e5fc4a0d'
self._run_naive_tests_on_tx(raw_tx, txid)
+ def test_txid_negative_version_num(self):
+ raw_tx = 'f0b47b9a01ecf5e5c3bbf2cf1f71ecdc7f708b0b222432e914b394e24aad1494a42990ddfc000000008b483045022100852744642305a99ad74354e9495bf43a1f96ded470c256cd32e129290f1fa191022030c11d294af6a61b3da6ed2c0c296251d21d113cfd71ec11126517034b0dcb70014104a0fe6e4a600f859a0932f701d3af8e0ecd4be886d91045f06a5a6b931b95873aea1df61da281ba29cadb560dad4fc047cf47b4f7f2570da4c0b810b3dfa7e500ffffffff0240420f00000000001976a9147eeacb8a9265cd68c92806611f704fc55a21e1f588ac05f00d00000000001976a914eb3bd8ccd3ba6f1570f844b59ba3e0a667024a6a88acff7f0000'
+ txid = 'c659729a7fea5071361c2c1a68551ca2bf77679b27086cc415adeeb03852e369'
+ self._run_naive_tests_on_tx(raw_tx, txid)
+
# these transactions are from Bitcoin Core unit tests --->
# https://github.com/bitcoin/bitcoin/blob/11376b5583a283772c82f6d32d0007cdbf5b8ef0/src/test/data/tx_valid.json