commit 9140c1fc8946a10966d767a727ca6e0150a7d203
parent 7c93d787ed2a21a057f1cf9bf223d3089f98dc62
Author: ThomasV <thomasv@electrum.org>
Date: Tue, 18 Apr 2017 10:43:24 +0200
fix #2352
Diffstat:
1 file changed, 12 insertions(+), 28 deletions(-)
diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py
@@ -11,7 +11,7 @@ from electrum.bitcoin import TYPE_ADDRESS, int_to_hex, var_int
from electrum.i18n import _
from electrum.plugins import BasePlugin, hook
from electrum.keystore import Hardware_KeyStore, parse_xpubkey
-from electrum.transaction import push_script
+from electrum.transaction import push_script, Transaction
from ..hw_wallet import HW_PluginBase
from electrum.util import format_satoshis_plain, print_error, is_verbose
@@ -300,11 +300,14 @@ class Ledger_KeyStore(Hardware_KeyStore):
self.give_error("No matching x_key for sign_transaction") # should never happen
redeemScript = txin.get('redeemScript')
- if segwitTransaction and not redeemScript:
- pkh = bitcoin.hash_160(pubkeys[0].decode('hex')).encode('hex')
- redeemScript = '76a9' + push_script(pkh) + '88ac'
+ 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)
- inputs.append([txin['prev_tx'].raw, txin['prevout_n'], redeemScript, txin['prevout_hash'], signingPos, txin['sequence'] ])
+ inputs.append([txin['prev_tx'].raw, txin['prevout_n'], redeemScript, txin['prevout_hash'], signingPos, txin.get('sequence', 0xffffffff) ])
inputsPaths.append(hwAddress)
pubKeys.append(pubkeys)
@@ -429,29 +432,10 @@ class Ledger_KeyStore(Hardware_KeyStore):
finally:
self.handler.clear_dialog()
- # Reformat transaction
- inputIndex = 0
- if segwitTransaction:
- for txin in tx.inputs():
- txin['signatures'] = [str(signatures[inputIndex][0:-1]).encode('hex')]
- inputIndex = inputIndex + 1
- else:
- while inputIndex < len(inputs):
- if p2shTransaction:
- signaturesPack = [signatures[inputIndex]] * len(pubKeys[inputIndex])
- inputScript = get_p2sh_input_script(redeemScripts[inputIndex], signaturesPack)
- preparedTrustedInputs.append([ ("\x00" * 4) + chipInputs[inputIndex]['value'], inputScript ])
- else:
- inputScript = get_regular_input_script(signatures[inputIndex], pubKeys[inputIndex][0].decode('hex'))
- preparedTrustedInputs.append([ chipInputs[inputIndex]['value'], inputScript ])
- inputIndex = inputIndex + 1
- updatedTransaction = format_transaction(transactionOutput, preparedTrustedInputs)
- updatedTransaction = hexlify(updatedTransaction)
-
- if reorganize:
- tx.update(updatedTransaction)
- else:
- tx.update_signatures(updatedTransaction)
+ for i, txin in enumerate(tx.inputs()):
+ signingPos = inputs[i][4]
+ txin['signatures'][signingPos] = str(signatures[i]).encode('hex')
+ tx.raw = tx.serialize()
self.signing = False