Merge pull request #3867 from SomberNight/check_trezor_version

check trezorlib version
This commit is contained in:
ThomasV 2018-02-09 12:15:15 +01:00 committed by GitHub
commit 670194b920
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 14 deletions

View File

@ -734,4 +734,8 @@ def setup_thread_excepthook():
self.run = run_with_except_hook self.run = run_with_except_hook
threading.Thread.__init__ = init threading.Thread.__init__ = init
def versiontuple(v):
return tuple(map(int, (v.split("."))))

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# -*- mode: python -*- # -*- mode: python -*-
# #
# Electrum - lightweight Bitcoin client # Electrum - lightweight Bitcoin client
@ -184,10 +184,12 @@ class QtPluginBase(object):
if not isinstance(keystore, self.keystore_class): if not isinstance(keystore, self.keystore_class):
continue continue
if not self.libraries_available: if not self.libraries_available:
window.show_error( if hasattr(self, 'libraries_available_message'):
_("Cannot find python library for") + " '%s'.\n" % self.name \ message = self.libraries_available_message + '\n'
+ _("Make sure you install it with python3") else:
) message = _("Cannot find python library for") + " '%s'.\n" % self.name
message += _("Make sure you install it with python3")
window.show_error(message)
return return
tooltip = self.device + '\n' + (keystore.label or 'unnamed') tooltip = self.device + '\n' + (keystore.label or 'unnamed')
cb = partial(self.show_settings_dialog, window, keystore) cb = partial(self.show_settings_dialog, window, keystore)

View File

@ -10,7 +10,7 @@ from electrum.plugins import BasePlugin
from electrum.keystore import Hardware_KeyStore from electrum.keystore import Hardware_KeyStore
from electrum.transaction import Transaction from electrum.transaction import Transaction
from ..hw_wallet import HW_PluginBase from ..hw_wallet import HW_PluginBase
from electrum.util import print_error, is_verbose, bfh, bh2u from electrum.util import print_error, is_verbose, bfh, bh2u, versiontuple
try: try:
import hid import hid
@ -57,9 +57,6 @@ class Ledger_Client():
def i4b(self, x): def i4b(self, x):
return pack('>I', x) return pack('>I', x)
def versiontuple(self, v):
return tuple(map(int, (v.split("."))))
def test_pin_unlocked(func): def test_pin_unlocked(func):
"""Function decorator to test the Ledger for being unlocked, and if not, """Function decorator to test the Ledger for being unlocked, and if not,
raise a human-readable exception. raise a human-readable exception.
@ -140,9 +137,9 @@ class Ledger_Client():
try: try:
firmwareInfo = self.dongleObject.getFirmwareVersion() firmwareInfo = self.dongleObject.getFirmwareVersion()
firmware = firmwareInfo['version'] firmware = firmwareInfo['version']
self.multiOutputSupported = self.versiontuple(firmware) >= self.versiontuple(MULTI_OUTPUT_SUPPORT) self.multiOutputSupported = versiontuple(firmware) >= versiontuple(MULTI_OUTPUT_SUPPORT)
self.nativeSegwitSupported = self.versiontuple(firmware) >= self.versiontuple(SEGWIT_SUPPORT) self.nativeSegwitSupported = versiontuple(firmware) >= versiontuple(SEGWIT_SUPPORT)
self.segwitSupported = self.nativeSegwitSupported or (firmwareInfo['specialVersion'] == 0x20 and self.versiontuple(firmware) >= self.versiontuple(SEGWIT_SUPPORT_SPECIAL)) self.segwitSupported = self.nativeSegwitSupported or (firmwareInfo['specialVersion'] == 0x20 and versiontuple(firmware) >= versiontuple(SEGWIT_SUPPORT_SPECIAL))
if not checkFirmware(firmwareInfo): if not checkFirmware(firmwareInfo):
self.dongleObject.dongle.close() self.dongleObject.dongle.close()

View File

@ -2,7 +2,7 @@ import threading
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from electrum.util import bfh, bh2u from electrum.util import bfh, bh2u, versiontuple
from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey, from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey,
TYPE_ADDRESS, TYPE_SCRIPT, NetworkConstants) TYPE_ADDRESS, TYPE_SCRIPT, NetworkConstants)
from electrum.i18n import _ from electrum.i18n import _
@ -86,6 +86,7 @@ class TrezorPlugin(HW_PluginBase):
libraries_URL = 'https://github.com/trezor/python-trezor' libraries_URL = 'https://github.com/trezor/python-trezor'
minimum_firmware = (1, 5, 2) minimum_firmware = (1, 5, 2)
keystore_class = TrezorKeyStore keystore_class = TrezorKeyStore
minimum_library = (0, 9, 0)
MAX_LABEL_LEN = 32 MAX_LABEL_LEN = 32
@ -96,6 +97,19 @@ class TrezorPlugin(HW_PluginBase):
try: try:
# Minimal test if python-trezor is installed # Minimal test if python-trezor is installed
import trezorlib import trezorlib
try:
library_version = trezorlib.__version__
except AttributeError:
# python-trezor only introduced __version__ in 0.9.0
library_version = 'unknown'
if library_version == 'unknown' or \
versiontuple(library_version) < self.minimum_library:
self.libraries_available_message = (
_("Library version for '{}' is too old.").format(name)
+ '\nInstalled: {}, Needed: {}'
.format(library_version, self.minimum_library))
self.print_stderr(self.libraries_available_message)
raise ImportError()
self.libraries_available = True self.libraries_available = True
except ImportError: except ImportError:
self.libraries_available = False self.libraries_available = False