Merge pull request #4005 from SomberNight/trezor_segwit_offline_signing
trezor: segwit offline signing
This commit is contained in:
commit
7e501115cd
|
@ -40,6 +40,7 @@ from .bitcoin import *
|
||||||
from .interface import Connection, Interface
|
from .interface import Connection, Interface
|
||||||
from . import blockchain
|
from . import blockchain
|
||||||
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
||||||
|
from .i18n import _
|
||||||
|
|
||||||
|
|
||||||
NODES_RETRY_INTERVAL = 60
|
NODES_RETRY_INTERVAL = 60
|
||||||
|
@ -1069,7 +1070,7 @@ class Network(util.DaemonThread):
|
||||||
try:
|
try:
|
||||||
r = q.get(True, timeout)
|
r = q.get(True, timeout)
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
raise BaseException('Server did not answer')
|
raise util.TimeoutException(_('Server did not answer'))
|
||||||
if r.get('error'):
|
if r.get('error'):
|
||||||
raise BaseException(r.get('error'))
|
raise BaseException(r.get('error'))
|
||||||
return r.get('result')
|
return r.get('result')
|
||||||
|
|
10
lib/util.py
10
lib/util.py
|
@ -74,6 +74,16 @@ class FileExportFailed(Exception):
|
||||||
return _("Failed to export to file.") + "\n" + self.message
|
return _("Failed to export to file.") + "\n" + self.message
|
||||||
|
|
||||||
|
|
||||||
|
class TimeoutException(Exception):
|
||||||
|
def __init__(self, message=''):
|
||||||
|
self.message = str(message)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
if not self.message:
|
||||||
|
return _("Operation timed out.")
|
||||||
|
return self.message
|
||||||
|
|
||||||
|
|
||||||
# Throw this exception to unwind the stack like when an error occurs.
|
# Throw this exception to unwind the stack like when an error occurs.
|
||||||
# However unlike other exceptions the user won't be informed.
|
# However unlike other exceptions the user won't be informed.
|
||||||
class UserCancelled(Exception):
|
class UserCancelled(Exception):
|
||||||
|
|
|
@ -44,7 +44,7 @@ import sys
|
||||||
|
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
|
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
|
||||||
format_satoshis, NoDynamicFeeEstimates)
|
format_satoshis, NoDynamicFeeEstimates, TimeoutException)
|
||||||
|
|
||||||
from .bitcoin import *
|
from .bitcoin import *
|
||||||
from .version import *
|
from .version import *
|
||||||
|
@ -1401,21 +1401,28 @@ class Abstract_Wallet(PrintError):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_input_tx(self, tx_hash):
|
def get_input_tx(self, tx_hash, ignore_timeout=False):
|
||||||
# First look up an input transaction in the wallet where it
|
# First look up an input transaction in the wallet where it
|
||||||
# will likely be. If co-signing a transaction it may not have
|
# will likely be. If co-signing a transaction it may not have
|
||||||
# all the input txs, in which case we ask the network.
|
# all the input txs, in which case we ask the network.
|
||||||
tx = self.transactions.get(tx_hash)
|
tx = self.transactions.get(tx_hash, None)
|
||||||
if not tx and self.network:
|
if not tx and self.network:
|
||||||
request = ('blockchain.transaction.get', [tx_hash])
|
request = ('blockchain.transaction.get', [tx_hash])
|
||||||
|
try:
|
||||||
tx = Transaction(self.network.synchronous_get(request))
|
tx = Transaction(self.network.synchronous_get(request))
|
||||||
|
except TimeoutException as e:
|
||||||
|
self.print_error('getting input txn from network timed out for {}'.format(tx_hash))
|
||||||
|
if not ignore_timeout:
|
||||||
|
raise e
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def add_hw_info(self, tx):
|
def add_hw_info(self, tx):
|
||||||
# add previous tx for hw wallets
|
# add previous tx for hw wallets
|
||||||
for txin in tx.inputs():
|
for txin in tx.inputs():
|
||||||
tx_hash = txin['prevout_hash']
|
tx_hash = txin['prevout_hash']
|
||||||
txin['prev_tx'] = self.get_input_tx(tx_hash)
|
# segwit inputs might not be needed for some hw wallets
|
||||||
|
ignore_timeout = Transaction.is_segwit_input(txin)
|
||||||
|
txin['prev_tx'] = self.get_input_tx(tx_hash, ignore_timeout)
|
||||||
# add output info for hw wallets
|
# add output info for hw wallets
|
||||||
info = {}
|
info = {}
|
||||||
xpubs = self.get_master_public_keys()
|
xpubs = self.get_master_public_keys()
|
||||||
|
|
|
@ -434,6 +434,9 @@ class TrezorPlugin(HW_PluginBase):
|
||||||
|
|
||||||
def electrum_tx_to_txtype(self, tx):
|
def electrum_tx_to_txtype(self, tx):
|
||||||
t = self.types.TransactionType()
|
t = self.types.TransactionType()
|
||||||
|
if tx is None:
|
||||||
|
# probably for segwit input and we don't need this prev txn
|
||||||
|
return t
|
||||||
d = deserialize(tx.raw)
|
d = deserialize(tx.raw)
|
||||||
t.version = d['version']
|
t.version = d['version']
|
||||||
t.lock_time = d['lockTime']
|
t.lock_time = d['lockTime']
|
||||||
|
|
Loading…
Reference in New Issue