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.
This commit is contained in:
@@ -351,7 +351,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
|||||||
p2shTransaction = False
|
p2shTransaction = False
|
||||||
segwitTransaction = False
|
segwitTransaction = False
|
||||||
pin = ""
|
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()
|
client_electrum = self.get_client_electrum()
|
||||||
assert client_electrum
|
assert client_electrum
|
||||||
|
|
||||||
@@ -450,13 +450,13 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
|||||||
redeemScripts.append(bfh(utxo[2]))
|
redeemScripts.append(bfh(utxo[2]))
|
||||||
elif (not p2shTransaction) or client_electrum.supports_multi_output():
|
elif (not p2shTransaction) or client_electrum.supports_multi_output():
|
||||||
txtmp = bitcoinTransaction(bfh(utxo[0]))
|
txtmp = bitcoinTransaction(bfh(utxo[0]))
|
||||||
trustedInput = self.get_client().getTrustedInput(txtmp, utxo[1])
|
trustedInput = client_ledger.getTrustedInput(txtmp, utxo[1])
|
||||||
trustedInput['sequence'] = sequence
|
trustedInput['sequence'] = sequence
|
||||||
if segwitTransaction:
|
if segwitTransaction:
|
||||||
trustedInput['witness'] = True
|
trustedInput['witness'] = True
|
||||||
chipInputs.append(trustedInput)
|
chipInputs.append(trustedInput)
|
||||||
if p2shTransaction or segwitTransaction:
|
if p2shTransaction or segwitTransaction:
|
||||||
redeemScripts.append(bfh(utxo[2]))
|
redeemScripts.append(bfh(utxo[2]))
|
||||||
else:
|
else:
|
||||||
redeemScripts.append(txtmp.outputs[utxo[1]].script)
|
redeemScripts.append(txtmp.outputs[utxo[1]].script)
|
||||||
else:
|
else:
|
||||||
@@ -469,13 +469,13 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
|||||||
firstTransaction = True
|
firstTransaction = True
|
||||||
inputIndex = 0
|
inputIndex = 0
|
||||||
rawTx = tx.serialize_to_network()
|
rawTx = tx.serialize_to_network()
|
||||||
self.get_client().enableAlternate2fa(False)
|
client_ledger.enableAlternate2fa(False)
|
||||||
if segwitTransaction:
|
if segwitTransaction:
|
||||||
self.get_client().startUntrustedTransaction(True, inputIndex,
|
client_ledger.startUntrustedTransaction(True, inputIndex,
|
||||||
chipInputs, redeemScripts[inputIndex], version=tx.version)
|
chipInputs, redeemScripts[inputIndex], version=tx.version)
|
||||||
# we don't set meaningful outputAddress, amount and fees
|
# we don't set meaningful outputAddress, amount and fees
|
||||||
# as we only care about the alternateEncoding==True branch
|
# 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
|
outputData['outputData'] = txOutput
|
||||||
if outputData['confirmationNeeded']:
|
if outputData['confirmationNeeded']:
|
||||||
outputData['address'] = output
|
outputData['address'] = output
|
||||||
@@ -486,9 +486,9 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
|||||||
self.handler.show_message(_("Confirmed. Signing Transaction..."))
|
self.handler.show_message(_("Confirmed. Signing Transaction..."))
|
||||||
while inputIndex < len(inputs):
|
while inputIndex < len(inputs):
|
||||||
singleInput = [ chipInputs[inputIndex] ]
|
singleInput = [ chipInputs[inputIndex] ]
|
||||||
self.get_client().startUntrustedTransaction(False, 0,
|
client_ledger.startUntrustedTransaction(False, 0,
|
||||||
singleInput, redeemScripts[inputIndex], version=tx.version)
|
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+
|
inputSignature[0] = 0x30 # force for 1.4.9+
|
||||||
my_pubkey = inputs[inputIndex][4]
|
my_pubkey = inputs[inputIndex][4]
|
||||||
tx.add_signature_to_txin(txin_idx=inputIndex,
|
tx.add_signature_to_txin(txin_idx=inputIndex,
|
||||||
@@ -497,11 +497,11 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
|||||||
inputIndex = inputIndex + 1
|
inputIndex = inputIndex + 1
|
||||||
else:
|
else:
|
||||||
while inputIndex < len(inputs):
|
while inputIndex < len(inputs):
|
||||||
self.get_client().startUntrustedTransaction(firstTransaction, inputIndex,
|
client_ledger.startUntrustedTransaction(firstTransaction, inputIndex,
|
||||||
chipInputs, redeemScripts[inputIndex], version=tx.version)
|
chipInputs, redeemScripts[inputIndex], version=tx.version)
|
||||||
# we don't set meaningful outputAddress, amount and fees
|
# we don't set meaningful outputAddress, amount and fees
|
||||||
# as we only care about the alternateEncoding==True branch
|
# 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
|
outputData['outputData'] = txOutput
|
||||||
if outputData['confirmationNeeded']:
|
if outputData['confirmationNeeded']:
|
||||||
outputData['address'] = output
|
outputData['address'] = output
|
||||||
@@ -512,7 +512,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
|||||||
self.handler.show_message(_("Confirmed. Signing Transaction..."))
|
self.handler.show_message(_("Confirmed. Signing Transaction..."))
|
||||||
else:
|
else:
|
||||||
# Sign input with the provided PIN
|
# 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+
|
inputSignature[0] = 0x30 # force for 1.4.9+
|
||||||
my_pubkey = inputs[inputIndex][4]
|
my_pubkey = inputs[inputIndex][4]
|
||||||
tx.add_signature_to_txin(txin_idx=inputIndex,
|
tx.add_signature_to_txin(txin_idx=inputIndex,
|
||||||
|
|||||||
Reference in New Issue
Block a user