From b042c4118f663ebd910461270229bdaf6802d7d6 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 1 Jul 2020 16:15:13 +0200 Subject: [PATCH] ledger: speed-up sign_transaction really slow to scan usb devices for e.g. every tx input... if user disconnects mid-signing, we would fail anyway. --- electrum/plugins/ledger/ledger.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py index 8dcd4f0f3..0b125c712 100644 --- a/electrum/plugins/ledger/ledger.py +++ b/electrum/plugins/ledger/ledger.py @@ -351,7 +351,7 @@ class Ledger_KeyStore(Hardware_KeyStore): p2shTransaction = False segwitTransaction = False pin = "" - self.get_client() # prompt for the PIN before displaying the dialog if necessary + client_ledger = self.get_client() # prompt for the PIN before displaying the dialog if necessary client_electrum = self.get_client_electrum() assert client_electrum @@ -450,13 +450,13 @@ class Ledger_KeyStore(Hardware_KeyStore): redeemScripts.append(bfh(utxo[2])) elif (not p2shTransaction) or client_electrum.supports_multi_output(): txtmp = bitcoinTransaction(bfh(utxo[0])) - trustedInput = self.get_client().getTrustedInput(txtmp, utxo[1]) + trustedInput = client_ledger.getTrustedInput(txtmp, utxo[1]) trustedInput['sequence'] = sequence if segwitTransaction: trustedInput['witness'] = True chipInputs.append(trustedInput) if p2shTransaction or segwitTransaction: - redeemScripts.append(bfh(utxo[2])) + redeemScripts.append(bfh(utxo[2])) else: redeemScripts.append(txtmp.outputs[utxo[1]].script) else: @@ -469,13 +469,13 @@ class Ledger_KeyStore(Hardware_KeyStore): firstTransaction = True inputIndex = 0 rawTx = tx.serialize_to_network() - self.get_client().enableAlternate2fa(False) + client_ledger.enableAlternate2fa(False) if segwitTransaction: - self.get_client().startUntrustedTransaction(True, inputIndex, + client_ledger.startUntrustedTransaction(True, inputIndex, chipInputs, redeemScripts[inputIndex], version=tx.version) # we don't set meaningful outputAddress, amount and fees # as we only care about the alternateEncoding==True branch - outputData = self.get_client().finalizeInput(b'', 0, 0, changePath, bfh(rawTx)) + outputData = client_ledger.finalizeInput(b'', 0, 0, changePath, bfh(rawTx)) outputData['outputData'] = txOutput if outputData['confirmationNeeded']: outputData['address'] = output @@ -486,9 +486,9 @@ class Ledger_KeyStore(Hardware_KeyStore): self.handler.show_message(_("Confirmed. Signing Transaction...")) while inputIndex < len(inputs): singleInput = [ chipInputs[inputIndex] ] - self.get_client().startUntrustedTransaction(False, 0, + client_ledger.startUntrustedTransaction(False, 0, singleInput, redeemScripts[inputIndex], version=tx.version) - inputSignature = self.get_client().untrustedHashSign(inputsPaths[inputIndex], pin, lockTime=tx.locktime) + inputSignature = client_ledger.untrustedHashSign(inputsPaths[inputIndex], pin, lockTime=tx.locktime) inputSignature[0] = 0x30 # force for 1.4.9+ my_pubkey = inputs[inputIndex][4] tx.add_signature_to_txin(txin_idx=inputIndex, @@ -497,11 +497,11 @@ class Ledger_KeyStore(Hardware_KeyStore): inputIndex = inputIndex + 1 else: while inputIndex < len(inputs): - self.get_client().startUntrustedTransaction(firstTransaction, inputIndex, + client_ledger.startUntrustedTransaction(firstTransaction, inputIndex, chipInputs, redeemScripts[inputIndex], version=tx.version) # we don't set meaningful outputAddress, amount and fees # as we only care about the alternateEncoding==True branch - outputData = self.get_client().finalizeInput(b'', 0, 0, changePath, bfh(rawTx)) + outputData = client_ledger.finalizeInput(b'', 0, 0, changePath, bfh(rawTx)) outputData['outputData'] = txOutput if outputData['confirmationNeeded']: outputData['address'] = output @@ -512,7 +512,7 @@ class Ledger_KeyStore(Hardware_KeyStore): self.handler.show_message(_("Confirmed. Signing Transaction...")) else: # Sign input with the provided PIN - inputSignature = self.get_client().untrustedHashSign(inputsPaths[inputIndex], pin, lockTime=tx.locktime) + inputSignature = client_ledger.untrustedHashSign(inputsPaths[inputIndex], pin, lockTime=tx.locktime) inputSignature[0] = 0x30 # force for 1.4.9+ my_pubkey = inputs[inputIndex][4] tx.add_signature_to_txin(txin_idx=inputIndex,