From 2fbb71f5c989e6548a0f2269b192fab39cf265f2 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 18 Nov 2020 21:30:13 +0100 Subject: [PATCH 1/2] flagbyte errors --- bitcoin/core/__init__.py | 24 +++++++++++++++++++++--- bitcoin/tests/data/tx_invalid.json | 7 +++++++ bitcoin/tests/test_transactions.py | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/bitcoin/core/__init__.py b/bitcoin/core/__init__.py index 272bec5c..9055a6e4 100644 --- a/bitcoin/core/__init__.py +++ b/bitcoin/core/__init__.py @@ -387,9 +387,9 @@ def from_txwitness(cls, txwitness): class CTransaction(ImmutableSerializable): """A transaction""" - __slots__ = ['nVersion', 'vin', 'vout', 'nLockTime', 'wit'] + __slots__ = ['nVersion', 'vin', 'vout', 'nLockTime', 'wit', 'flagbyte'] - def __init__(self, vin=(), vout=(), nLockTime=0, nVersion=1, witness=CTxWitness()): + def __init__(self, vin=(), vout=(), nLockTime=0, nVersion=1, witness=CTxWitness(), flagbyte=0): """Create a new transaction vin and vout are iterables of transaction inputs and outputs @@ -403,6 +403,7 @@ def __init__(self, vin=(), vout=(), nLockTime=0, nVersion=1, witness=CTxWitness( object.__setattr__(self, 'vin', tuple(CTxIn.from_txin(txin) for txin in vin)) object.__setattr__(self, 'vout', tuple(CTxOut.from_txout(txout) for txout in vout)) object.__setattr__(self, 'wit', CTxWitness.from_txwitness(witness)) + object.__setattr__(self, 'flagbyte', flagbyte) @classmethod def stream_deserialize(cls, f): @@ -428,8 +429,19 @@ def stream_deserialize(cls, f): wit = CTxWitness(tuple(0 for dummy in range(len(vin)))) wit = wit.stream_deserialize(f) nLockTime = struct.unpack(b"0 and markerbyte ==0 and flagbyte!=1): + vout = VectorSerializer.stream_deserialize(CTxOut, f) + wit = CTxWitness(tuple(0 for dummy in range(len(vin)))) + wit = wit.stream_deserialize(f) + nLockTime = struct.unpack(b"= 3 n = json_prevout[1] if n == -1: n = 0xffffffff From 7b1061fc40edcf47b8948113cbe98648cbed5ebd Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 18 Nov 2020 22:00:33 +0100 Subject: [PATCH 2/2] flagbyte errors, test data description --- bitcoin/tests/data/tx_invalid.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitcoin/tests/data/tx_invalid.json b/bitcoin/tests/data/tx_invalid.json index 27277537..46e2e8d5 100644 --- a/bitcoin/tests/data/tx_invalid.json +++ b/bitcoin/tests/data/tx_invalid.json @@ -71,7 +71,7 @@ [[["ad503f72c18df5801ee64d76090afe4c607fb2b822e9b7b63c5826c50e22fc3b", 0, "0x21 0x027c3a97665bf283a102a587a62a30a0c102d4d3b141015e2cae6f64e2543113e5 CHECKSIG NOT"]], "01000000013bfc220ec526583cb6b7e922b8b27f604cfe0a09764de61e80f58dc1723f50ad0000000000ffffffff0101000000000000002321027c3a97665bf283a102a587a62a30a0c102d4d3b141015e2cae6f64e2543113e5ac00000000", true], -["Witness with SigHash Single|AnyoneCanPay (same signature as previous)"], +["Witness with SigHash Single|AnyoneCanPay (same signature as previous), flagbyte set to 02"], [[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0x51", 1000], ["0000000000000000000000000000000000000000000000000000000000000100", 1, "0x00 0x14 0x4c9c3dfac4207d5d8cb89df5722cb3d712385e3f", 2000], ["0000000000000000000000000000000000000000000000000000000000000100", 2, "0x51", 3000]],