hw_wallet: inherit from ABC and use @abstractmethod decorators instead of raise NotImplementedError
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod, ABC
|
||||||
from typing import TYPE_CHECKING, Sequence, Optional, Type, Iterable, Any
|
from typing import TYPE_CHECKING, Sequence, Optional, Type, Iterable, Any
|
||||||
|
|
||||||
from electrum.plugin import (BasePlugin, hook, Device, DeviceMgr,
|
from electrum.plugin import (BasePlugin, hook, Device, DeviceMgr,
|
||||||
@@ -183,7 +183,7 @@ class HW_PluginBase(BasePlugin):
|
|||||||
return device.product_key in self.DEVICE_IDS
|
return device.product_key in self.DEVICE_IDS
|
||||||
|
|
||||||
|
|
||||||
class HardwareClientBase:
|
class HardwareClientBase(ABC):
|
||||||
handler = None # type: Optional['HardwareHandlerBase']
|
handler = None # type: Optional['HardwareHandlerBase']
|
||||||
|
|
||||||
def __init__(self, *, plugin: 'HW_PluginBase'):
|
def __init__(self, *, plugin: 'HW_PluginBase'):
|
||||||
@@ -195,11 +195,11 @@ class HardwareClientBase:
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def is_pairable(self) -> bool:
|
def is_pairable(self) -> bool:
|
||||||
raise NotImplementedError()
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def close(self):
|
def close(self):
|
||||||
raise NotImplementedError()
|
pass
|
||||||
|
|
||||||
def timeout(self, cutoff) -> None:
|
def timeout(self, cutoff) -> None:
|
||||||
pass
|
pass
|
||||||
@@ -207,7 +207,7 @@ class HardwareClientBase:
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def is_initialized(self) -> bool:
|
def is_initialized(self) -> bool:
|
||||||
"""True if initialized, False if wiped."""
|
"""True if initialized, False if wiped."""
|
||||||
raise NotImplementedError()
|
pass
|
||||||
|
|
||||||
def label(self) -> Optional[str]:
|
def label(self) -> Optional[str]:
|
||||||
"""The name given by the user to the device.
|
"""The name given by the user to the device.
|
||||||
@@ -230,11 +230,13 @@ class HardwareClientBase:
|
|||||||
root_fp = self.request_root_fingerprint_from_device()
|
root_fp = self.request_root_fingerprint_from_device()
|
||||||
return root_fp
|
return root_fp
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def has_usable_connection_with_device(self) -> bool:
|
def has_usable_connection_with_device(self) -> bool:
|
||||||
raise NotImplementedError()
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def get_xpub(self, bip32_path: str, xtype) -> str:
|
def get_xpub(self, bip32_path: str, xtype) -> str:
|
||||||
raise NotImplementedError()
|
pass
|
||||||
|
|
||||||
@runs_in_hwd_thread
|
@runs_in_hwd_thread
|
||||||
def request_root_fingerprint_from_device(self) -> str:
|
def request_root_fingerprint_from_device(self) -> str:
|
||||||
@@ -252,7 +254,6 @@ class HardwareClientBase:
|
|||||||
password = Xpub.get_pubkey_from_xpub(xpub, ()).hex()
|
password = Xpub.get_pubkey_from_xpub(xpub, ()).hex()
|
||||||
return password
|
return password
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def device_model_name(self) -> Optional[str]:
|
def device_model_name(self) -> Optional[str]:
|
||||||
"""Return the name of the model of this device, which might be displayed in the UI.
|
"""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".
|
E.g. for Trezor, "Trezor One" or "Trezor T".
|
||||||
|
|||||||
Reference in New Issue
Block a user