More keepkey / trezor commonizing and cleanup
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
from electrum.wallet import BIP32_Hardware_Wallet
|
||||
|
||||
from plugins.trezor.gui_mixin import GuiMixin
|
||||
from plugins.trezor.plugin_generic import TrezorCompatiblePlugin
|
||||
from plugins.trezor.client import trezor_client_class
|
||||
from plugins.trezor.plugin import TrezorCompatiblePlugin
|
||||
|
||||
try:
|
||||
from trezorlib.client import proto, BaseClient, ProtocolMixin
|
||||
from trezorlib.transport import ConnectionError
|
||||
from trezorlib.transport_hid import HidTransport
|
||||
TREZOR = True
|
||||
except ImportError:
|
||||
TREZOR = False
|
||||
@@ -17,46 +15,14 @@ class TrezorWallet(BIP32_Hardware_Wallet):
|
||||
root_derivation = "m/44'/0'"
|
||||
device = 'Trezor'
|
||||
|
||||
|
||||
class TrezorPlugin(TrezorCompatiblePlugin):
|
||||
wallet_type = 'trezor'
|
||||
client_class = trezor_client_class(ProtocolMixin, BaseClient, proto)
|
||||
firmware_URL = 'https://www.mytrezor.com'
|
||||
libraries_URL = 'https://github.com/trezor/python-trezor'
|
||||
libraries_available = TREZOR
|
||||
minimum_firmware = (1, 2, 1)
|
||||
wallet_class = TrezorWallet
|
||||
import trezorlib.ckd_public as ckd_public
|
||||
from trezorlib.client import types
|
||||
|
||||
@staticmethod
|
||||
def libraries_available():
|
||||
return TREZOR
|
||||
|
||||
def constructor(self, s):
|
||||
return TrezorWallet(s)
|
||||
|
||||
def get_client(self):
|
||||
if not TREZOR:
|
||||
self.give_error('please install github.com/trezor/python-trezor')
|
||||
|
||||
if not self.client or self.client.bad:
|
||||
d = HidTransport.enumerate()
|
||||
if not d:
|
||||
self.give_error('Could not connect to your Trezor. Please verify the cable is connected and that no other app is using it.')
|
||||
self.transport = HidTransport(d[0])
|
||||
self.client = QtGuiTrezorClient(self.transport)
|
||||
self.client.handler = self.handler
|
||||
self.client.set_tx_api(self)
|
||||
self.client.bad = False
|
||||
if not self.atleast_version(1, 2, 1):
|
||||
self.client = None
|
||||
self.give_error('Outdated Trezor firmware. Please update the firmware from https://www.mytrezor.com')
|
||||
return self.client
|
||||
|
||||
if TREZOR:
|
||||
class QtGuiTrezorClient(ProtocolMixin, GuiMixin, BaseClient):
|
||||
protocol = proto
|
||||
device = 'Trezor'
|
||||
|
||||
def call_raw(self, msg):
|
||||
try:
|
||||
resp = BaseClient.call_raw(self, msg)
|
||||
except ConnectionError:
|
||||
self.bad = True
|
||||
raise
|
||||
|
||||
return resp
|
||||
from trezorlib.transport_hid import HidTransport
|
||||
|
||||
Reference in New Issue
Block a user