Browse Source

hw plugins: (cleanup) Plugin objects should not have a Handler field

Handlers are per-client (connected device), plugins are ~singletons.
These were mostly remnants of old code.
master
SomberNight 4 years ago
parent
commit
30623c3529
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/plugins/bitbox02/bitbox02.py
  2. 13
      electrum/plugins/digitalbitbox/digitalbitbox.py
  3. 3
      electrum/plugins/ledger/ledger.py

9
electrum/plugins/bitbox02/bitbox02.py

@ -22,7 +22,7 @@ from electrum.bitcoin import OnchainOutputType
import electrum.bitcoin as bitcoin
import electrum.ecc as ecc
from ..hw_wallet import HW_PluginBase, HardwareClientBase
from ..hw_wallet import HW_PluginBase, HardwareClientBase, HardwareHandlerBase
_logger = get_logger(__name__)
@ -47,7 +47,7 @@ except ImportError as e:
class BitBox02Client(HardwareClientBase):
# handler is a BitBox02_Handler, importing it would lead to a circular dependency
def __init__(self, handler: Any, device: Device, config: SimpleConfig, *, plugin: HW_PluginBase):
def __init__(self, handler: HardwareHandlerBase, device: Device, config: SimpleConfig, *, plugin: HW_PluginBase):
HardwareClientBase.__init__(self, plugin=plugin)
self.bitbox02_device = None # type: Optional[bitbox02.BitBox02]
self.handler = handler
@ -653,11 +653,8 @@ class BitBox02Plugin(HW_PluginBase):
else:
raise ImportError()
# handler is a BitBox02_Handler
@runs_in_hwd_thread
def create_client(self, device: Device, handler: Any) -> BitBox02Client:
if not handler:
self.handler = handler
def create_client(self, device, handler) -> BitBox02Client:
return BitBox02Client(handler, device, self.config, plugin=self)
def setup_device(

13
electrum/plugins/digitalbitbox/digitalbitbox.py

@ -32,7 +32,7 @@ from electrum.network import Network
from electrum.logging import get_logger
from electrum.plugin import runs_in_hwd_thread, run_in_hwd_thread
from ..hw_wallet import HW_PluginBase, HardwareClientBase
from ..hw_wallet import HW_PluginBase, HardwareClientBase, HardwareHandlerBase
_logger = get_logger(__name__)
@ -597,7 +597,7 @@ class DigitalBitbox_KeyStore(Hardware_KeyStore):
if self.plugin.is_mobile_paired() and tx_dbb_serialized is not None:
reply['tx'] = tx_dbb_serialized
self.plugin.comserver_post_notification(reply)
self.plugin.comserver_post_notification(reply, handler=self.handler)
if steps > 1:
self.handler.show_message(_("Signing large transaction. Please be patient ...") + "\n\n" +
@ -683,8 +683,6 @@ class DigitalBitboxPlugin(HW_PluginBase):
def create_client(self, device, handler):
if device.interface_number == 0 or device.usage_page == 0xffff:
if handler:
self.handler = handler
client = self.get_dbb_device(device)
if client is not None:
client = DigitalBitbox_Client(self, client)
@ -707,7 +705,7 @@ class DigitalBitboxPlugin(HW_PluginBase):
return ENCRYPTION_PRIVKEY_KEY in self.digitalbitbox_config
def comserver_post_notification(self, payload):
def comserver_post_notification(self, payload, *, handler: 'HardwareHandlerBase'):
assert self.is_mobile_paired(), "unexpected mobile pairing error"
url = 'https://digitalbitbox.com/smartverification/index.php'
key_s = base64.b64decode(self.digitalbitbox_config[ENCRYPTION_PRIVKEY_KEY])
@ -719,7 +717,8 @@ class DigitalBitboxPlugin(HW_PluginBase):
text = Network.send_http_on_proxy('post', url, body=args.encode('ascii'), headers={'content-type': 'application/x-www-form-urlencoded'})
_logger.info(f'digitalbitbox reply from server {text}')
except Exception as e:
self.handler.show_error(repr(e)) # repr because str(Exception()) == ''
_logger.exception("")
handler.show_error(repr(e)) # repr because str(Exception()) == ''
def get_xpub(self, device_id, derivation, xtype, wizard):
@ -763,4 +762,4 @@ class DigitalBitboxPlugin(HW_PluginBase):
"type": 'p2pkh',
"echo": xpub['echo'],
}
self.comserver_post_notification(verify_request_payload)
self.comserver_post_notification(verify_request_payload, handler=keystore.handler)

3
electrum/plugins/ledger/ledger.py

@ -687,9 +687,6 @@ class LedgerPlugin(HW_PluginBase):
@runs_in_hwd_thread
def create_client(self, device, handler):
if handler:
self.handler = handler
client = self.get_btchip_device(device)
if client is not None:
client = Ledger_Client(client, product_key=device.product_key, plugin=self)

Loading…
Cancel
Save