1
0

hww: mark device_model_name(self) as @abstractmethod and override in hww clients that did not define it.

This commit is contained in:
Sander van Grieken
2023-09-06 12:36:16 +02:00
parent d68e6a69c1
commit 087718f3a7
5 changed files with 16 additions and 4 deletions

View File

@@ -72,6 +72,9 @@ class BitBox02Client(HardwareClientBase):
if self.bitbox_hid_info is None:
raise Exception("No BitBox02 detected")
def device_model_name(self) -> Optional[str]:
return 'BitBox02'
def is_initialized(self) -> bool:
return True

View File

@@ -59,7 +59,6 @@ CKCC_SIMULATED_PID = CKCC_PID ^ 0x55aa
class CKCCClient(HardwareClientBase):
def __init__(self, plugin, handler, dev_path, *, is_simulator=False):
HardwareClientBase.__init__(self, plugin=plugin)
self.device = plugin.device
@@ -80,6 +79,9 @@ class CKCCClient(HardwareClientBase):
# NOTE: MiTM test is delayed until we have a hint as to what XPUB we
# should expect. It's also kinda slow.
def device_model_name(self) -> Optional[str]:
return 'Coldcard'
def __repr__(self):
return '<CKCCClient: xfp=%s label=%r>' % (xfp2str(self.dev.master_fingerprint),
self.label())

View File

@@ -15,7 +15,7 @@ import struct
import sys
import time
import copy
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from electrum.crypto import sha256d, EncodeAES_bytes, DecodeAES_bytes, hmac_oneshot
from electrum.bitcoin import public_key_to_p2pkh
@@ -69,8 +69,8 @@ MIN_MAJOR_VERSION = 5
ENCRYPTION_PRIVKEY_KEY = 'encryptionprivkey'
CHANNEL_ID_KEY = 'comserverchannelid'
class DigitalBitbox_Client(HardwareClientBase):
class DigitalBitbox_Client(HardwareClientBase):
def __init__(self, plugin, hidDevice):
HardwareClientBase.__init__(self, plugin=plugin)
self.dbb_hid = hidDevice
@@ -80,6 +80,9 @@ class DigitalBitbox_Client(HardwareClientBase):
self.setupRunning = False
self.usbReportSize = 64 # firmware > v2.0.0
def device_model_name(self) -> Optional[str]:
return 'Digital BitBox'
@runs_in_hwd_thread
def close(self):
if self.opened:

View File

@@ -23,7 +23,7 @@
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from abc import abstractmethod
from typing import TYPE_CHECKING, Sequence, Optional, Type, Iterable, Any
from electrum.plugin import (BasePlugin, hook, Device, DeviceMgr,
@@ -249,6 +249,7 @@ class HardwareClientBase:
password = Xpub.get_pubkey_from_xpub(xpub, ()).hex()
return password
@abstractmethod
def device_model_name(self) -> Optional[str]:
"""Return the name of the model of this device, which might be displayed in the UI.
E.g. for Trezor, "Trezor One" or "Trezor T".

View File

@@ -117,6 +117,9 @@ class SafeTClientBase(HardwareClientBase, GuiMixin, Logger):
Logger.__init__(self)
self.used()
def device_model_name(self) -> Optional[str]:
return 'Safe-T'
def __str__(self):
return "%s/%s" % (self.label(), self.features.device_id)