URI: 
       tMerge pull request #3867 from SomberNight/check_trezor_version - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 670194b92037dba020ef8b6bfe5922560c7f5b26
   DIR parent 94ebfd578d5ab587c01976ab2af9cd068e614542
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Fri,  9 Feb 2018 12:15:15 +0100
       
       Merge pull request #3867 from SomberNight/check_trezor_version
       
       check trezorlib version
       Diffstat:
         M lib/util.py                         |       7 +++++--
         M plugins/hw_wallet/qt.py             |      12 +++++++-----
         M plugins/ledger/ledger.py            |      11 ++++-------
         M plugins/trezor/trezor.py            |      16 +++++++++++++++-
       
       4 files changed, 31 insertions(+), 15 deletions(-)
       ---
   DIR diff --git a/lib/util.py b/lib/util.py
       t@@ -734,4 +734,8 @@ def setup_thread_excepthook():
        
                self.run = run_with_except_hook
        
       -    threading.Thread.__init__ = init
       -\ No newline at end of file
       +    threading.Thread.__init__ = init
       +
       +
       +def versiontuple(v):
       +    return tuple(map(int, (v.split("."))))
   DIR diff --git a/plugins/hw_wallet/qt.py b/plugins/hw_wallet/qt.py
       t@@ -1,4 +1,4 @@
       -#!/usr/bin/env python2
       +#!/usr/bin/env python3
        # -*- mode: python -*-
        #
        # Electrum - lightweight Bitcoin client
       t@@ -184,10 +184,12 @@ class QtPluginBase(object):
                    if not isinstance(keystore, self.keystore_class):
                        continue
                    if not self.libraries_available:
       -                window.show_error(
       -                    _("Cannot find python library for") + " '%s'.\n" % self.name \
       -                    + _("Make sure you install it with python3")
       -                )
       +                if hasattr(self, 'libraries_available_message'):
       +                    message = self.libraries_available_message + '\n'
       +                else:
       +                    message = _("Cannot find python library for") + " '%s'.\n" % self.name
       +                message += _("Make sure you install it with python3")
       +                window.show_error(message)
                        return
                    tooltip = self.device + '\n' + (keystore.label or 'unnamed')
                    cb = partial(self.show_settings_dialog, window, keystore)
   DIR diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py
       t@@ -10,7 +10,7 @@ from electrum.plugins import BasePlugin
        from electrum.keystore import Hardware_KeyStore
        from electrum.transaction import Transaction
        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:
            import hid
       t@@ -57,9 +57,6 @@ class Ledger_Client():
            def i4b(self, x):
                return pack('>I', x)
        
       -    def versiontuple(self, v):
       -        return tuple(map(int, (v.split("."))))
       -
            def test_pin_unlocked(func):
                """Function decorator to test the Ledger for being unlocked, and if not,
                raise a human-readable exception.
       t@@ -140,9 +137,9 @@ class Ledger_Client():
                try:
                    firmwareInfo = self.dongleObject.getFirmwareVersion()
                    firmware = firmwareInfo['version']
       -            self.multiOutputSupported = self.versiontuple(firmware) >= self.versiontuple(MULTI_OUTPUT_SUPPORT)
       -            self.nativeSegwitSupported = self.versiontuple(firmware) >= self.versiontuple(SEGWIT_SUPPORT)
       -            self.segwitSupported = self.nativeSegwitSupported or (firmwareInfo['specialVersion'] == 0x20 and self.versiontuple(firmware) >= self.versiontuple(SEGWIT_SUPPORT_SPECIAL))
       +            self.multiOutputSupported = versiontuple(firmware) >= versiontuple(MULTI_OUTPUT_SUPPORT)
       +            self.nativeSegwitSupported = versiontuple(firmware) >= versiontuple(SEGWIT_SUPPORT)
       +            self.segwitSupported = self.nativeSegwitSupported or (firmwareInfo['specialVersion'] == 0x20 and versiontuple(firmware) >= versiontuple(SEGWIT_SUPPORT_SPECIAL))
        
                    if not checkFirmware(firmwareInfo):
                        self.dongleObject.dongle.close()
   DIR diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py
       t@@ -2,7 +2,7 @@ import threading
        
        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,
                                      TYPE_ADDRESS, TYPE_SCRIPT, NetworkConstants)
        from electrum.i18n import _
       t@@ -86,6 +86,7 @@ class TrezorPlugin(HW_PluginBase):
            libraries_URL = 'https://github.com/trezor/python-trezor'
            minimum_firmware = (1, 5, 2)
            keystore_class = TrezorKeyStore
       +    minimum_library = (0, 9, 0)
        
            MAX_LABEL_LEN = 32
        
       t@@ -96,6 +97,19 @@ class TrezorPlugin(HW_PluginBase):
                try:
                    # Minimal test if python-trezor is installed
                    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
                except ImportError:
                    self.libraries_available = False