gurudesh/pytracebugs huggingface dataset:
# Buggy code
def on_hw_derivation(self, name, device_info: "DeviceInfo", derivation, xtype):
    from .keystore import hardware_keystore

    devmgr = self.plugins.device_manager
    assert isinstance(self.plugin, HW_PluginBase)
    try:
        xpub = self.plugin.get_xpub(device_info.device.id_, derivation, xtype, self)
        client = devmgr.client_by_id(device_info.device.id_)
        if not client:
            raise Exception("failed to find client for device id")
        root_fingerprint = client.request_root_fingerprint_from_device()
        label = client.label()  # use this as device_info.label might be outdated!
    except ScriptTypeNotSupported:
        raise  # this is handled in derivation_dialog
    except BaseException as e:
        self.logger.exception("")
        self.show_error(e)
        return
    d = {
        "type": "hardware",
        "hw_type": name,
        "derivation": derivation,
        "root_fingerprint": root_fingerprint,
        "xpub": xpub,
        "label": label,
    }
    k = hardware_keystore(d)
    self.on_keystore(k)


# Traceback (electrum.plugin.DeviceUnpairableError)
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/gui/qt/util.py", line 718, in run
result = task.task()
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 179, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 457, in client_for_keystore
client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 505, in force_pair_xpub
'receive will be unspendable.').format(plugin.device))
electrum.plugin.DeviceUnpairableError: Electrum cannot pair with your Trezor.

# Fixed code
def on_hw_derivation(self, name, device_info: "DeviceInfo", derivation, xtype):
    from .keystore import hardware_keystore

    devmgr = self.plugins.device_manager
    assert isinstance(self.plugin, HW_PluginBase)
    try:
        xpub = self.plugin.get_xpub(device_info.device.id_, derivation, xtype, self)
        client = devmgr.client_by_id(device_info.device.id_)
        if not client:
            raise Exception("failed to find client for device id")
        root_fingerprint = client.request_root_fingerprint_from_device()
        label = client.label()  # use this as device_info.label might be outdated!
        soft_device_id = (
            client.get_soft_device_id()
        )  # use this as device_info.device_id might be outdated!
    except ScriptTypeNotSupported:
        raise  # this is handled in derivation_dialog
    except BaseException as e:
        self.logger.exception("")
        self.show_error(e)
        return
    d = {
        "type": "hardware",
        "hw_type": name,
        "derivation": derivation,
        "root_fingerprint": root_fingerprint,
        "xpub": xpub,
        "label": label,
        "soft_device_id": soft_device_id,
    }
    k = hardware_keystore(d)
    self.on_keystore(k)
# Buggy code
def create_storage(self, path):
    if os.path.exists(path):
        raise Exception("file already exists at path")
    if not self.pw_args:
        return
    pw_args = self.pw_args
    self.pw_args = None  # clean-up so that it can get GC-ed
    storage = WalletStorage(path)
    if pw_args.encrypt_storage:
        storage.set_password(pw_args.password, enc_version=pw_args.storage_enc_version)
    db = WalletDB("", manual_upgrades=False)
    db.set_keystore_encryption(bool(pw_args.password) and pw_args.encrypt_keystore)
    for key, value in self.data.items():
        db.put(key, value)
    db.load_plugins()
    db.write(storage)
    return storage, db


# Traceback (electrum.plugin.DeviceUnpairableError)
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/gui/qt/util.py", line 718, in run
result = task.task()
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 179, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 457, in client_for_keystore
client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 505, in force_pair_xpub
'receive will be unspendable.').format(plugin.device))
electrum.plugin.DeviceUnpairableError: Electrum cannot pair with your Trezor.

# Fixed code
def create_storage(self, path):
    if os.path.exists(path):
        raise Exception("file already exists at path")
    if not self.pw_args:
        return  # FIXME
    pw_args = self.pw_args
    self.pw_args = None  # clean-up so that it can get GC-ed
    storage = WalletStorage(path)
    if pw_args.encrypt_storage:
        storage.set_password(pw_args.password, enc_version=pw_args.storage_enc_version)
    db = WalletDB("", manual_upgrades=False)
    db.set_keystore_encryption(bool(pw_args.password) and pw_args.encrypt_keystore)
    for key, value in self.data.items():
        db.put(key, value)
    db.load_plugins()
    db.write(storage)
    return storage, db
# Buggy code
def __init__(self, d):
    Xpub.__init__(
        self,
        derivation_prefix=d.get("derivation"),
        root_fingerprint=d.get("root_fingerprint"),
    )
    KeyStore.__init__(self)
    # Errors and other user interaction is done through the wallet's
    # handler.  The handler is per-window and preserved across
    # device reconnects
    self.xpub = d.get("xpub")
    self.label = d.get("label")
    self.handler = None  # type: Optional[HardwareHandlerBase]
    run_hook("init_keystore", self)


# Traceback (electrum.plugin.DeviceUnpairableError)
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/gui/qt/util.py", line 718, in run
result = task.task()
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 179, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 457, in client_for_keystore
client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 505, in force_pair_xpub
'receive will be unspendable.').format(plugin.device))
electrum.plugin.DeviceUnpairableError: Electrum cannot pair with your Trezor.

# Fixed code
def __init__(self, d):
    Xpub.__init__(
        self,
        derivation_prefix=d.get("derivation"),
        root_fingerprint=d.get("root_fingerprint"),
    )
    KeyStore.__init__(self)
    # Errors and other user interaction is done through the wallet's
    # handler.  The handler is per-window and preserved across
    # device reconnects
    self.xpub = d.get("xpub")
    self.label = d.get("label")
    self.soft_device_id = d.get("soft_device_id")  # type: Optional[str]
    self.handler = None  # type: Optional[HardwareHandlerBase]
    run_hook("init_keystore", self)
# Buggy code
def dump(self):
    return {
        "type": self.type,
        "hw_type": self.hw_type,
        "xpub": self.xpub,
        "derivation": self.get_derivation_prefix(),
        "root_fingerprint": self.get_root_fingerprint(),
        "label": self.label,
    }


# Traceback (electrum.plugin.DeviceUnpairableError)
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/gui/qt/util.py", line 718, in run
result = task.task()
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 179, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 457, in client_for_keystore
client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 505, in force_pair_xpub
'receive will be unspendable.').format(plugin.device))
electrum.plugin.DeviceUnpairableError: Electrum cannot pair with your Trezor.

# Fixed code
def dump(self):
    return {
        "type": self.type,
        "hw_type": self.hw_type,
        "xpub": self.xpub,
        "derivation": self.get_derivation_prefix(),
        "root_fingerprint": self.get_root_fingerprint(),
        "label": self.label,
        "soft_device_id": self.soft_device_id,
    }
# Buggy code
def opportunistically_fill_in_missing_info_from_device(
    self, client: "HardwareClientBase"
):
    assert client is not None
    if self._root_fingerprint is None:
        self._root_fingerprint = client.request_root_fingerprint_from_device()
        self.is_requesting_to_be_rewritten_to_wallet_file = True
    if self.label != client.label():
        self.label = client.label()
        self.is_requesting_to_be_rewritten_to_wallet_file = True


# Traceback (electrum.plugin.DeviceUnpairableError)
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/gui/qt/util.py", line 718, in run
result = task.task()
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 179, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 457, in client_for_keystore
client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 505, in force_pair_xpub
'receive will be unspendable.').format(plugin.device))
electrum.plugin.DeviceUnpairableError: Electrum cannot pair with your Trezor.

# Fixed code
def opportunistically_fill_in_missing_info_from_device(
    self, client: "HardwareClientBase"
):
    assert client is not None
    if self._root_fingerprint is None:
        self._root_fingerprint = client.request_root_fingerprint_from_device()
        self.is_requesting_to_be_rewritten_to_wallet_file = True
    if self.label != client.label():
        self.label = client.label()
        self.is_requesting_to_be_rewritten_to_wallet_file = True
    if self.soft_device_id != client.get_soft_device_id():
        self.soft_device_id = client.get_soft_device_id()
        self.is_requesting_to_be_rewritten_to_wallet_file = True
# Buggy code
def __init__(self, hidDevice, *, is_hw1: bool = False):
    self.dongleObject = btchip(hidDevice)
    self.preflightDone = False
    self._is_hw1 = is_hw1


# Traceback (electrum.plugin.DeviceUnpairableError)
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/gui/qt/util.py", line 718, in run
result = task.task()
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 179, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 457, in client_for_keystore
client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 505, in force_pair_xpub
'receive will be unspendable.').format(plugin.device))
electrum.plugin.DeviceUnpairableError: Electrum cannot pair with your Trezor.

# Fixed code
def __init__(self, hidDevice, *, is_hw1: bool = False):
    self.dongleObject = btchip(hidDevice)
    self.preflightDone = False
    self._is_hw1 = is_hw1
    self._soft_device_id = None
# Buggy code
def label(self) -> str:
    """The name given by the user to the device."""
    raise NotImplementedError()


# Traceback (electrum.plugin.DeviceUnpairableError)
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/gui/qt/util.py", line 718, in run
result = task.task()
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 179, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 457, in client_for_keystore
client = self.force_pair_xpub(plugin, handler, info, xpub, derivation, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 505, in force_pair_xpub
'receive will be unspendable.').format(plugin.device))
electrum.plugin.DeviceUnpairableError: Electrum cannot pair with your Trezor.

# Fixed code
def label(self) -> str:
    """The name given by the user to the device.

    Note: labels are shown to the user to help distinguish their devices,
    and they are also used as a fallback to distinguish devices programmatically.
    So ideally, different devices would have different labels.
    """
    raise NotImplementedError()
# Buggy code
def __init__(self, d):
    Xpub.__init__(
        self,
        derivation_prefix=d.get("derivation"),
        root_fingerprint=d.get("root_fingerprint"),
    )
    KeyStore.__init__(self)
    # Errors and other user interaction is done through the wallet's
    # handler.  The handler is per-window and preserved across
    # device reconnects
    self.xpub = d.get("xpub")
    self.label = d.get("label")
    self.handler = None
    run_hook("init_keystore", self)


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def __init__(self, d):
    Xpub.__init__(
        self,
        derivation_prefix=d.get("derivation"),
        root_fingerprint=d.get("root_fingerprint"),
    )
    KeyStore.__init__(self)
    # Errors and other user interaction is done through the wallet's
    # handler.  The handler is per-window and preserved across
    # device reconnects
    self.xpub = d.get("xpub")
    self.label = d.get("label")
    self.handler = None  # type: Optional[HardwareHandlerBase]
    run_hook("init_keystore", self)
# Buggy code
def create_client(
    self, device: "Device", handler, plugin: "HW_PluginBase"
) -> Optional["HardwareClientBase"]:
    # Get from cache first
    client = self.client_lookup(device.id_)
    if client:
        return client
    client = plugin.create_client(device, handler)
    if client:
        self.logger.info(f"Registering {client}")
        with self.lock:
            self.clients[client] = (device.path, device.id_)
    return client


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def create_client(
    self,
    device: "Device",
    handler: Optional["HardwareHandlerBase"],
    plugin: "HW_PluginBase",
) -> Optional["HardwareClientBase"]:
    # Get from cache first
    client = self.client_lookup(device.id_)
    if client:
        return client
    client = plugin.create_client(device, handler)
    if client:
        self.logger.info(f"Registering {client}")
        with self.lock:
            self.clients[client] = (device.path, device.id_)
    return client
# Buggy code
def client_for_keystore(
    self,
    plugin: "HW_PluginBase",
    handler,
    keystore: "Hardware_KeyStore",
    force_pair: bool,
) -> Optional["HardwareClientBase"]:
    self.logger.info("getting client for keystore")
    if handler is None:
        raise Exception(
            _("Handler not found for")
            + " "
            + plugin.name
            + "\n"
            + _("A library is probably missing.")
        )
    handler.update_status(False)
    devices = self.scan_devices()
    xpub = keystore.xpub
    derivation = keystore.get_derivation_prefix()
    assert derivation is not None
    client = self.client_by_xpub(plugin, xpub, handler, devices)
    if client is None and force_pair:
        info = self.select_device(plugin, handler, keystore, devices)
        client = self.force_pair_xpub(plugin, handler, info, xpub, derivation)
    if client:
        handler.update_status(True)
    if client:
        keystore.opportunistically_fill_in_missing_info_from_device(client)
    self.logger.info("end client for keystore")
    return client


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def client_for_keystore(
    self,
    plugin: "HW_PluginBase",
    handler: Optional["HardwareHandlerBase"],
    keystore: "Hardware_KeyStore",
    force_pair: bool,
) -> Optional["HardwareClientBase"]:
    self.logger.info("getting client for keystore")
    if handler is None:
        raise Exception(
            _("Handler not found for")
            + " "
            + plugin.name
            + "\n"
            + _("A library is probably missing.")
        )
    handler.update_status(False)
    devices = self.scan_devices()
    xpub = keystore.xpub
    derivation = keystore.get_derivation_prefix()
    assert derivation is not None
    client = self.client_by_xpub(plugin, xpub, handler, devices)
    if client is None and force_pair:
        info = self.select_device(plugin, handler, keystore, devices)
        client = self.force_pair_xpub(plugin, handler, info, xpub, derivation)
    if client:
        handler.update_status(True)
    if client:
        keystore.opportunistically_fill_in_missing_info_from_device(client)
    self.logger.info("end client for keystore")
    return client
# Buggy code
def client_by_xpub(
    self, plugin: "HW_PluginBase", xpub, handler, devices: Iterable["Device"]
) -> Optional["HardwareClientBase"]:
    _id = self.xpub_id(xpub)
    client = self.client_lookup(_id)
    if client:
        # An unpaired client might have another wallet's handler
        # from a prior scan.  Replace to fix dialog parenting.
        client.handler = handler
        return client

    for device in devices:
        if device.id_ == _id:
            return self.create_client(device, handler, plugin)


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def client_by_xpub(
    self,
    plugin: "HW_PluginBase",
    xpub,
    handler: "HardwareHandlerBase",
    devices: Iterable["Device"],
) -> Optional["HardwareClientBase"]:
    _id = self.xpub_id(xpub)
    client = self.client_lookup(_id)
    if client:
        # An unpaired client might have another wallet's handler
        # from a prior scan.  Replace to fix dialog parenting.
        client.handler = handler
        return client

    for device in devices:
        if device.id_ == _id:
            return self.create_client(device, handler, plugin)
# Buggy code
def setup_device(self, device_info, wizard, purpose):
    """Called when creating a new wallet or when using the device to decrypt
    an existing wallet. Select the device to use.  If the device is
    uninitialized, go through the initialization process.
    """
    raise NotImplementedError()


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def setup_device(self, device_info, wizard: "BaseWizard", purpose):
    """Called when creating a new wallet or when using the device to decrypt
    an existing wallet. Select the device to use.  If the device is
    uninitialized, go through the initialization process.
    """
    raise NotImplementedError()
# Buggy code
def create_client(self, device: "Device", handler) -> Optional["HardwareClientBase"]:
    raise NotImplementedError()


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def create_client(
    self, device: "Device", handler: Optional["HardwareHandlerBase"]
) -> Optional["HardwareClientBase"]:
    raise NotImplementedError()
# Buggy code
def get_xpub(self, device_id, derivation: str, xtype, wizard) -> str:
    raise NotImplementedError()


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def get_xpub(self, device_id, derivation: str, xtype, wizard: "BaseWizard") -> str:
    raise NotImplementedError()
# Buggy code
def __init__(self, win, device):
    QObject.__init__(self)
    Logger.__init__(self)
    self.clear_signal.connect(self.clear_dialog)
    self.error_signal.connect(self.error_dialog)
    self.message_signal.connect(self.message_dialog)
    self.passphrase_signal.connect(self.passphrase_dialog)
    self.word_signal.connect(self.word_dialog)
    self.query_signal.connect(self.win_query_choice)
    self.yes_no_signal.connect(self.win_yes_no_question)
    self.status_signal.connect(self._update_status)
    self.win = win
    self.device = device
    self.dialog = None
    self.done = threading.Event()


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def __init__(self, win: Union[ElectrumWindow, InstallWizard], device: str):
    QObject.__init__(self)
    Logger.__init__(self)
    self.clear_signal.connect(self.clear_dialog)
    self.error_signal.connect(self.error_dialog)
    self.message_signal.connect(self.message_dialog)
    self.passphrase_signal.connect(self.passphrase_dialog)
    self.word_signal.connect(self.word_dialog)
    self.query_signal.connect(self.win_query_choice)
    self.yes_no_signal.connect(self.win_yes_no_question)
    self.status_signal.connect(self._update_status)
    self.win = win
    self.device = device
    self.dialog = None
    self.done = threading.Event()
# Buggy code
def create_handler(self, window: ElectrumWindow) -> "QtHandlerBase":
    raise NotImplementedError()


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def create_handler(
    self, window: Union[ElectrumWindow, InstallWizard]
) -> "QtHandlerBase":
    raise NotImplementedError()
# Buggy code
def setup_device(self, device_info, wizard, purpose):
    devmgr = self.device_manager()
    device_id = device_info.device.id_
    client = devmgr.client_by_id(device_id)
    if client is None:
        raise UserFacingException(
            _("Failed to create a client for this device.")
            + "\n"
            + _("Make sure it is in the correct state.")
        )
    # fixme: we should use: client.handler = wizard
    client.handler = self.create_handler(wizard)
    if not device_info.initialized:
        self.initialize_device(device_id, wizard, client.handler)
    client.get_xpub("m", "standard")
    client.used()


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def setup_device(self, device_info, wizard, purpose):
    devmgr = self.device_manager()
    device_id = device_info.device.id_
    client = devmgr.client_by_id(device_id)
    if client is None:
        raise UserFacingException(
            _("Failed to create a client for this device.")
            + "\n"
            + _("Make sure it is in the correct state.")
        )
    client.handler = self.create_handler(wizard)
    if not device_info.initialized:
        self.initialize_device(device_id, wizard, client.handler)
    client.get_xpub("m", "standard")
    client.used()
# Buggy code
def get_xpub(self, device_id, derivation, xtype, wizard):
    if xtype not in self.SUPPORTED_XTYPES:
        raise ScriptTypeNotSupported(
            _("This type of script is not supported with {}.").format(self.device)
        )
    devmgr = self.device_manager()
    client = devmgr.client_by_id(device_id)
    client.handler = wizard
    xpub = client.get_xpub(derivation, xtype)
    client.used()
    return xpub


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def get_xpub(self, device_id, derivation, xtype, wizard):
    if xtype not in self.SUPPORTED_XTYPES:
        raise ScriptTypeNotSupported(
            _("This type of script is not supported with {}.").format(self.device)
        )
    devmgr = self.device_manager()
    client = devmgr.client_by_id(device_id)
    client.handler = self.create_handler(wizard)
    xpub = client.get_xpub(derivation, xtype)
    client.used()
    return xpub
# Buggy code
def setup_device(self, device_info, wizard, purpose):
    devmgr = self.device_manager()
    device_id = device_info.device.id_
    client = devmgr.client_by_id(device_id)
    if client is None:
        raise UserFacingException(
            _("Failed to create a client for this device.")
            + "\n"
            + _("Make sure it is in the correct state.")
        )

    if not client.is_uptodate():
        msg = _(
            "Outdated {} firmware for device labelled {}. Please "
            "download the updated firmware from {}"
        ).format(self.device, client.label(), self.firmware_URL)
        raise OutdatedHwFirmwareException(msg)

    # fixme: we should use: client.handler = wizard
    client.handler = self.create_handler(wizard)
    if not device_info.initialized:
        self.initialize_device(device_id, wizard, client.handler)
    is_creating_wallet = purpose == HWD_SETUP_NEW_WALLET
    client.get_xpub("m", "standard", creating=is_creating_wallet)
    client.used()


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def setup_device(self, device_info, wizard, purpose):
    devmgr = self.device_manager()
    device_id = device_info.device.id_
    client = devmgr.client_by_id(device_id)
    if client is None:
        raise UserFacingException(
            _("Failed to create a client for this device.")
            + "\n"
            + _("Make sure it is in the correct state.")
        )

    if not client.is_uptodate():
        msg = _(
            "Outdated {} firmware for device labelled {}. Please "
            "download the updated firmware from {}"
        ).format(self.device, client.label(), self.firmware_URL)
        raise OutdatedHwFirmwareException(msg)

    client.handler = self.create_handler(wizard)
    if not device_info.initialized:
        self.initialize_device(device_id, wizard, client.handler)
    is_creating_wallet = purpose == HWD_SETUP_NEW_WALLET
    client.get_xpub("m", "standard", creating=is_creating_wallet)
    client.used()
# Buggy code
def on_hw_derivation(self, name, device_info, derivation, xtype):
    from .keystore import hardware_keystore

    devmgr = self.plugins.device_manager
    try:
        xpub = self.plugin.get_xpub(device_info.device.id_, derivation, xtype, self)
        client = devmgr.client_by_id(device_info.device.id_)
        if not client:
            raise Exception("failed to find client for device id")
        root_fingerprint = client.request_root_fingerprint_from_device()
    except ScriptTypeNotSupported:
        raise  # this is handled in derivation_dialog
    except BaseException as e:
        self.logger.exception("")
        self.show_error(e)
        return
    d = {
        "type": "hardware",
        "hw_type": name,
        "derivation": derivation,
        "root_fingerprint": root_fingerprint,
        "xpub": xpub,
        "label": device_info.label,
    }
    k = hardware_keystore(d)
    self.on_keystore(k)


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def on_hw_derivation(self, name, device_info: "DeviceInfo", derivation, xtype):
    from .keystore import hardware_keystore

    devmgr = self.plugins.device_manager
    try:
        xpub = self.plugin.get_xpub(device_info.device.id_, derivation, xtype, self)
        client = devmgr.client_by_id(device_info.device.id_)
        if not client:
            raise Exception("failed to find client for device id")
        root_fingerprint = client.request_root_fingerprint_from_device()
        label = client.label()  # use this as device_info.label might be outdated!
    except ScriptTypeNotSupported:
        raise  # this is handled in derivation_dialog
    except BaseException as e:
        self.logger.exception("")
        self.show_error(e)
        return
    d = {
        "type": "hardware",
        "hw_type": name,
        "derivation": derivation,
        "root_fingerprint": root_fingerprint,
        "xpub": xpub,
        "label": label,
    }
    k = hardware_keystore(d)
    self.on_keystore(k)
# Buggy code
def setup_device(self, device_info, wizard: "BaseWizard", purpose):
    """Called when creating a new wallet or when using the device to decrypt
    an existing wallet. Select the device to use.  If the device is
    uninitialized, go through the initialization process.
    """
    raise NotImplementedError()


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def setup_device(self, device_info: DeviceInfo, wizard: "BaseWizard", purpose):
    """Called when creating a new wallet or when using the device to decrypt
    an existing wallet. Select the device to use.  If the device is
    uninitialized, go through the initialization process.
    """
    raise NotImplementedError()
# Buggy code
def dbb_generate_wallet(self):
    key = self.stretch_key(self.password)
    filename = "Electrum-" + time.strftime("%Y-%m-%d-%H-%M-%S") + ".pdf"
    msg = (
        '{"seed":{"source": "create", "key": "%s", "filename": "%s", "entropy": "%s"}}'
        % (key, filename, "Digital Bitbox Electrum Plugin")
    ).encode("utf8")
    reply = self.hid_send_encrypt(msg)
    if "error" in reply:
        raise UserFacingException(reply["error"]["message"])


# Traceback (electrum.util.UserFacingException)
Traceback (most recent call last):
File "...\electrum\electrum\base_wizard.py", line 296, in on_device
self.plugin.setup_device(device_info, self, purpose)
File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 728, in setup_device
client.get_xpub("m/44'/0'", 'standard')
File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 110, in get_xpub
reply = self._get_xpub(bip32_path)
File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 104, in _get_xpub
if self.check_device_dialog():
File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 215, in check_device_dialog
self.seed_device_dialog() # Seed if not initialized
File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 254, in seed_device_dialog
self.dbb_generate_wallet()
File "...\electrum\electrum\plugins\digitalbitbox\digitalbitbox.py", line 311, in dbb_generate_wallet
raise UserFacingException(reply['error']['message'])
electrum.util.UserFacingException: Invalid command.

# Fixed code
def dbb_generate_wallet(self):
    key = self.stretch_key(self.password)
    filename = "Electrum-" + time.strftime("%Y-%m-%d-%H-%M-%S") + ".pdf"
    msg = (
        '{"seed":{"source": "create", "key": "%s", "filename": "%s", "entropy": "%s"}}'
        % (key, filename, to_hexstr(os.urandom(32)))
    ).encode("utf8")
    reply = self.hid_send_encrypt(msg)
    if "error" in reply:
        raise UserFacingException(reply["error"]["message"])
# Buggy code
def format_fee_rate(self, fee_rate):
    return format_fee_satoshis(fee_rate / 1000, self.num_zeros) + " sat/byte"


# Traceback (ValueError)
Traceback (most recent call last):
File "electrum/electrum/gui/qt/__init__.py", line 242, in start_new_window
w = self.create_window_for_wallet(wallet)
File "electrum/electrum/gui/qt/__init__.py", line 191, in create_window_for_wallet
w = ElectrumWindow(self, wallet)
File "electrum/electrum/gui/qt/main_window.py", line 146, in __init__
self.send_tab = self.create_send_tab()
File "electrum/electrum/gui/qt/main_window.py", line 1153, in create_send_tab
self.fee_slider = FeeSlider(self, self.config, fee_cb)
File "electrum/electrum/gui/qt/fee_slider.py", line 19, in __init__
self.update()
File "electrum/electrum/gui/qt/fee_slider.py", line 49, in update
tooltip = self.get_tooltip(pos, fee_rate)
File "electrum/electrum/gui/qt/fee_slider.py", line 36, in get_tooltip
target, estimate = self.config.get_fee_text(pos, self.dyn, mempool, fee_rate)
File "electrum/electrum/simple_config.py", line 404, in get_fee_text
rate_str = format_fee_satoshis(fee_rate/1000) + ' sat/byte'
File "electrum/electrum/util.py", line 544, in format_fee_satoshis
return format_satoshis(fee, num_zeros, 0, precision=FEERATE_PRECISION)
File "electrum/electrum/util.py", line 524, in format_satoshis
result = ("{:" + decimal_format + "f}").format(x / scale_factor)
File "/usr/lib/python3.7/_pydecimal.py", line 3762, in __format__
spec = _parse_format_specifier(specifier, _localeconv=_localeconv)
File "/usr/lib/python3.7/_pydecimal.py", line 6192, in _parse_format_specifier
raise ValueError("Invalid format specifier: " + format_spec)

# Fixed code
def format_fee_rate(self, fee_rate):
    return format_fee_satoshis(fee_rate / 1000, num_zeros=self.num_zeros) + " sat/byte"
# Buggy code
def format_fee_satoshis(fee, num_zeros=0):
    return format_satoshis(fee, num_zeros, 0, precision=FEERATE_PRECISION)


# Traceback (ValueError)
Traceback (most recent call last):
File "electrum/electrum/gui/qt/__init__.py", line 242, in start_new_window
w = self.create_window_for_wallet(wallet)
File "electrum/electrum/gui/qt/__init__.py", line 191, in create_window_for_wallet
w = ElectrumWindow(self, wallet)
File "electrum/electrum/gui/qt/main_window.py", line 146, in __init__
self.send_tab = self.create_send_tab()
File "electrum/electrum/gui/qt/main_window.py", line 1153, in create_send_tab
self.fee_slider = FeeSlider(self, self.config, fee_cb)
File "electrum/electrum/gui/qt/fee_slider.py", line 19, in __init__
self.update()
File "electrum/electrum/gui/qt/fee_slider.py", line 49, in update
tooltip = self.get_tooltip(pos, fee_rate)
File "electrum/electrum/gui/qt/fee_slider.py", line 36, in get_tooltip
target, estimate = self.config.get_fee_text(pos, self.dyn, mempool, fee_rate)
File "electrum/electrum/simple_config.py", line 404, in get_fee_text
rate_str = format_fee_satoshis(fee_rate/1000) + ' sat/byte'
File "electrum/electrum/util.py", line 544, in format_fee_satoshis
return format_satoshis(fee, num_zeros, 0, precision=FEERATE_PRECISION)
File "electrum/electrum/util.py", line 524, in format_satoshis
result = ("{:" + decimal_format + "f}").format(x / scale_factor)
File "/usr/lib/python3.7/_pydecimal.py", line 3762, in __format__
spec = _parse_format_specifier(specifier, _localeconv=_localeconv)
File "/usr/lib/python3.7/_pydecimal.py", line 6192, in _parse_format_specifier
raise ValueError("Invalid format specifier: " + format_spec)

# Fixed code
def format_fee_satoshis(fee, *, num_zeros=0, precision=None):
    if precision is None:
        precision = FEERATE_PRECISION
    num_zeros = min(num_zeros, FEERATE_PRECISION)  # no more zeroes than available prec
    return format_satoshis(
        fee, num_zeros=num_zeros, decimal_point=0, precision=precision
    )
# Buggy code
def listunspent(self):
    """List unspent outputs. Returns the list of unspent transaction
    outputs in your wallet."""
    l = copy.deepcopy(self.wallet.get_utxos(exclude_frozen=False))
    for i in l:
        v = i["value"]
        i["value"] = str(Decimal(v) / COIN) if v is not None else None
    return l


# Traceback (jsonrpclib.jsonrpc.ProtocolError)
[ecc] info: libsecp256k1 library not available, falling back to python-ecdsa. This means signing operations will be slower.
Invalid call parameters: <Fault -32602: Invalid parameters: get_utxos() got an unexpected keyword argument 'exclude_frozen'>
Traceback (most recent call last):
File "./run_electrum", line 457, in <module>
result = server.run_cmdline(config_options)
File "/usr/local/lib/python3.5/dist-packages/jsonrpclib/jsonrpc.py", line 650, in __call__
return self.__send(self.__name, args)
File "/usr/local/lib/python3.5/dist-packages/jsonrpclib/jsonrpc.py", line 532, in _request
check_for_errors(response)
File "/usr/local/lib/python3.5/dist-packages/jsonrpclib/jsonrpc.py", line 1220, in check_for_errors
raise ProtocolError((code, message))
jsonrpclib.jsonrpc.ProtocolError: (-32602, "Invalid parameters: get_utxos() got an unexpected keyword argument 'exclude_frozen'")

# Fixed code
def listunspent(self):
    """List unspent outputs. Returns the list of unspent transaction
    outputs in your wallet."""
    l = copy.deepcopy(self.wallet.get_utxos())
    for i in l:
        v = i["value"]
        i["value"] = str(Decimal(v) / COIN) if v is not None else None
    return l