electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 3337af0734cf17b7510783bf9bdecb8e4c4f6f17
parent 4eeb944b3c9f8eded2579bca844aef797b75f522
Author: ghost43 <somber.night@protonmail.com>
Date:   Wed,  9 May 2018 19:16:01 +0200

transaction.py: (txin guess) fix some false positive matches of p2sh-segwit (#4336)


Diffstat:
Mlib/tests/test_transaction.py | 5+++++
Mlib/transaction.py | 12++++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/lib/tests/test_transaction.py b/lib/tests/test_transaction.py @@ -290,6 +290,11 @@ class TestTransaction(unittest.TestCase): txid = 'c659729a7fea5071361c2c1a68551ca2bf77679b27086cc415adeeb03852e369' self._run_naive_tests_on_tx(raw_tx, txid) + def test_txid_regression_issue_4333(self): + raw_tx = '0100000001a300499298b3f03200c05d1a15aa111a33c769aff6fb355c6bf52ebdb58ca37100000000171600756161616161616161616161616161616161616151fdffffff01c40900000000000017a914001975d5f07f3391674416c1fcd67fd511d257ff871bc71300' + txid = '9b9f39e314662a7433aadaa5c94a2f1e24c7e7bf55fc9e1f83abd72be933eb95' + 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 diff --git a/lib/transaction.py b/lib/transaction.py @@ -384,6 +384,15 @@ def parse_scriptSig(d, _bytes): bh2u(_bytes)) +def _revise_txin_type_guess_for_txin(txin): + _type = txin.get('type', 'unknown') + # fix incorrect guess of p2sh-segwit + we_guessed_segwit_input_type = Transaction.is_segwit_inputtype(_type) + has_zero_witness = txin.get('witness', '00') in ('00', None) + if we_guessed_segwit_input_type and has_zero_witness: + txin['type'] = 'unknown' + + def parse_redeemScript_multisig(redeem_script: bytes): dec2 = [ x for x in script_GetOp(redeem_script) ] try: @@ -567,6 +576,9 @@ def deserialize(raw): txin = d['inputs'][i] parse_witness(vds, txin) d['lockTime'] = vds.read_uint32() + for i in range(n_vin): + txin = d['inputs'][i] + _revise_txin_type_guess_for_txin(txin) return d