electrum

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

commit f7096010f08c3567f6fc473f2013767ccd809336
parent 79bda98ba254f021ca154d8265a1ed2a2ece1f89
Author: ThomasV <thomasv@electrum.org>
Date:   Tue, 18 Apr 2017 11:12:46 +0200

add segwit to get_preimage_script

Diffstat:
Mlib/transaction.py | 8+++++---
Mplugins/ledger/ledger.py | 9+--------
2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/lib/transaction.py b/lib/transaction.py @@ -675,6 +675,10 @@ class Transaction: elif txin['type'] == 'p2sh': pubkeys, x_pubkeys = self.get_sorted_pubkeys(txin) return multisig_script(pubkeys, txin['num_sig']) + elif txin['type'] == 'p2wpkh-p2sh': + pubkey = txin['pubkeys'][0] + pkh = bitcoin.hash_160(pubkey.decode('hex')).encode('hex') + return '76a9' + push_script(pkh) + '88ac' else: raise TypeError('Unknown txin type', _type) @@ -722,9 +726,7 @@ class Transaction: hashSequence = Hash(''.join(int_to_hex(txin.get('sequence', 0xffffffff), 4) for txin in inputs).decode('hex')).encode('hex') hashOutputs = Hash(''.join(self.serialize_output(o) for o in outputs).decode('hex')).encode('hex') outpoint = self.serialize_outpoint(txin) - pubkey = txin['pubkeys'][0] - pkh = bitcoin.hash_160(pubkey.decode('hex')).encode('hex') - scriptCode = push_script('76a9' + push_script(pkh) + '88ac') + scriptCode = push_script(self.get_preimage_script(txin)) amount = int_to_hex(txin['value'], 8) nSequence = int_to_hex(txin.get('sequence', 0xffffffff), 4) preimage = nVersion + hashPrevouts + hashSequence + outpoint + scriptCode + amount + nSequence + hashOutputs + nLocktime + nHashType diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py @@ -298,14 +298,7 @@ class Ledger_KeyStore(Hardware_KeyStore): else: self.give_error("No matching x_key for sign_transaction") # should never happen - redeemScript = txin.get('redeemScript') - if not redeemScript: - if segwitTransaction: - pkh = bitcoin.hash_160(pubkeys[0].decode('hex')).encode('hex') - redeemScript = '76a9' + push_script(pkh) + '88ac' - elif p2shTransaction: - redeemScript = Transaction.get_preimage_script(txin) - + redeemScript = Transaction.get_preimage_script(txin) inputs.append([txin['prev_tx'].raw, txin['prevout_n'], redeemScript, txin['prevout_hash'], signingPos, txin.get('sequence', 0xffffffff) ]) inputsPaths.append(hwAddress) pubKeys.append(pubkeys)