def load_wallet(self, wallet, window): for keystore in wallet.get_keystores(): if not isinstance(keystore, self.keystore_class): continue if not self.libraries_available: if hasattr(self, 'libraries_available_message'): message = self.libraries_available_message + '\n' else: message = _("Cannot find python library for") + " '%s'.\n" % self.name message += _("Make sure you install it with python3") window.show_error(message) return tooltip = self.device + '\n' + (keystore.label or 'unnamed') cb = partial(self.show_settings_dialog, window, keystore) button = StatusBarButton(QIcon(self.icon_unpaired), tooltip, cb) button.icon_paired = self.icon_paired button.icon_unpaired = self.icon_unpaired window.statusBar().addPermanentWidget(button) handler = self.create_handler(window) handler.button = button keystore.handler = handler keystore.thread = TaskThread(window, window.on_error) self.add_show_address_on_hw_device_button_for_receive_addr(wallet, keystore, window) # Trigger a pairing keystore.thread.add(partial(self.get_client, keystore))
def load_wallet(self, wallet, window): for keystore in wallet.get_keystores(): if not isinstance(keystore, self.keystore_class): continue if not self.libraries_available: if hasattr(self, 'libraries_available_message'): message = self.libraries_available_message + '\n' else: message = _("Cannot find python library for" ) + " '%s'.\n" % self.name message += _("Make sure you install it with python3") window.show_error(message) return tooltip = self.device + '\n' + (keystore.label or 'unnamed') cb = partial(self.show_settings_dialog, window, keystore) button = StatusBarButton(QIcon(self.icon_unpaired), tooltip, cb) button.icon_paired = self.icon_paired button.icon_unpaired = self.icon_unpaired window.statusBar().addPermanentWidget(button) handler = self.create_handler(window) handler.button = button keystore.handler = handler keystore.thread = TaskThread(window, window.on_error) # Trigger a pairing keystore.thread.add(partial(self.get_client, keystore))
def create_status_bar(self, sb): if self.autoexport_interval_seconds and (self.auto_export_enabled()): auto_export = _("AutoExport: {}sec.".format( self.autoexport_interval_seconds)) self.status_button = StatusBarButton( QIcon(":icons/status_connected.png"), auto_export, lambda: self.settings_dialog(self, self.window)) else: self.status_button = StatusBarButton( QIcon(":icons/status_disconnected.png"), _("AutoExport"), lambda: self.settings_dialog(self, self.window)) sb.addPermanentWidget(self.status_button) return sb
def load_wallet(self, wallet, window): for keystore in wallet.get_keystores(): if type(keystore) != self.keystore_class: continue tooltip = self.device + '\n' + (keystore.label or 'unnamed') cb = partial(self.show_settings_dialog, window, keystore) button = StatusBarButton(QIcon(self.icon_unpaired), tooltip, cb) button.icon_paired = self.icon_paired button.icon_unpaired = self.icon_unpaired window.statusBar().addPermanentWidget(button) handler = self.create_handler(window) handler.button = button keystore.handler = handler keystore.thread = TaskThread(window, window.on_error) # Trigger a pairing keystore.thread.add(partial(self.get_client, keystore))
def load_wallet(self, wallet, window): self.print_error("load_wallet") self.wallet = wallet self.window = window self.wallet.plugin = self self.keepkey_button = StatusBarButton(QIcon(":icons/keepkey.png"), _("KeepKey"), self.settings_dialog) if type(window) is ElectrumWindow: self.window.statusBar().addPermanentWidget(self.keepkey_button) if self.handler is None: self.handler = KeepKeyQtHandler(self.window) try: self.get_client().ping('t') except BaseException as e: QMessageBox.information( self.window, _('Error'), _("KeepKey device not detected.\nContinuing in watching-only mode." + '\n\nReason:\n' + str(e)), _('OK')) self.wallet.force_watching_only = True return if self.wallet.addresses() and not self.wallet.check_proper_device(): QMessageBox.information( self.window, _('Error'), _("This wallet does not match your KeepKey device"), _('OK')) self.wallet.force_watching_only = True
def load_wallet(self, wallet, window): for keystore in wallet.get_keystores(): if not isinstance(keystore, self.keystore_class): continue tooltip = self.device + '\n' + (keystore.label or 'unnamed') cb = partial(self.show_settings_dialog, window, keystore) button = StatusBarButton(QIcon(self.icon_unpaired), tooltip, cb) button.icon_paired = self.icon_paired button.icon_unpaired = self.icon_unpaired window.statusBar().addPermanentWidget(button) handler = self.create_handler(window) handler.button = button keystore.handler = handler keystore.thread = TaskThread(window, window.on_error) # Trigger a pairing keystore.thread.add(partial(self.get_client, keystore))
def load_wallet(self, wallet): self.trustedcoin_button = StatusBarButton( QIcon(":icons/trustedcoin.png"), _("Network"), self.settings_dialog) self.window.statusBar().addPermanentWidget(self.trustedcoin_button) self.xpub = self.wallet.master_public_keys.get('x1/') self.user_id = self.get_user_id()[1] t = threading.Thread(target=self.request_billing_info) t.setDaemon(True) t.start()
def load_wallet(self, wallet, window): if type(wallet) != self.wallet_class: return window.tzb = StatusBarButton(QIcon(self.icon_file), self.device, partial(self.settings_dialog, window)) window.statusBar().addPermanentWidget(window.tzb) wallet.handler = self.create_handler(window) # Trigger a pairing wallet.thread.add(partial(self.get_client, wallet))
def on_new_window(self, window): wallet = window.wallet if wallet.storage.get('wallet_type') == '2fa': button = StatusBarButton(QIcon(":icons/trustedcoin.png"), _("TrustedCoin"), partial(self.settings_dialog, window)) window.statusBar().addPermanentWidget(button) t = Thread(target=self.request_billing_info, args=(wallet, )) t.setDaemon(True) t.start()
def load_wallet(self, wallet, window): keystore = wallet.get_keystore() if type(keystore) != self.keystore_class: return window.tzb = StatusBarButton(QIcon(self.icon_file), self.device, partial(self.settings_dialog, window)) window.statusBar().addPermanentWidget(window.tzb) keystore.handler = self.create_handler(window) keystore.thread = TaskThread(window, window.on_error) # Trigger a pairing keystore.thread.add(partial(self.get_client, keystore))
def on_new_window(self, window): wallet = window.wallet if not isinstance(wallet, self.wallet_class): return if wallet.can_sign_without_server(): msg = ' '.join([ _('This wallet was restored from seed, and it contains two master private keys.'), _('Therefore, two-factor authentication is disabled.') ]) action = lambda: window.show_message(msg) else: action = partial(self.settings_dialog, window) button = StatusBarButton(QIcon(":icons/trustedcoin-status.png"), _("TrustedCoin"), action) window.statusBar().addPermanentWidget(button) self.start_request_thread(window.wallet)
class Plugin(BasePlugin): wallet = None timer = None def fullname(self): return 'AutoExport' def description(self): return _("Auto Export Plugin") def is_available(self): return True def __init__(self, parent, config, name): BasePlugin.__init__(self, parent, config, name) self.update_settings(initial=True) @staticmethod def call_repeatedly(interval, func, *args): stopped = threading.Event() def loop(): while not stopped.wait( interval): # the first call is in `interval` secs func(*args) threading.Thread(target=loop).start() return stopped.set def auto_export_enabled(self): return self.autoexport_need_export_to_local or self.autoexport_need_export_to_ftp def export_csv(self): if self.autoexport_need_export_to_local: self.export_csv_local() if self.autoexport_need_export_to_ftp: self.export_csv_ftp() def get_exported_data(self): history = self.wallet.get_history() lines = [[ "transaction_hash", "label", "confirmations", "value", "timestamp" ]] for item in history: tx_hash, height, confirmations, timestamp, value, balance = item if height > 0: if timestamp is not None: time_string = format_time(timestamp) else: time_string = _("unverified") else: time_string = _("unconfirmed") if value is not None: value_string = format_satoshis(value, True) else: value_string = '--' if tx_hash: label = self.wallet.get_label(tx_hash) else: label = "" lines.append( [tx_hash, label, confirmations, value_string, time_string]) return lines def export_csv_local(self): try: if not self.autoexport_local_path: return filename = time.strftime("%Y_%m_%d__%H_%M_%S") + '.csv' filepath = os.path.join(self.autoexport_local_path, filename) lines = self.get_exported_data() with open(filepath, "w+") as f: transaction = csv.writer(f, lineterminator='\n') for line in lines: transaction.writerow(line) except Exception as e: print_error(str(e)) @hook def create_status_bar(self, sb): if self.autoexport_interval_seconds and (self.auto_export_enabled()): auto_export = _("AutoExport: {}sec.".format( self.autoexport_interval_seconds)) self.status_button = StatusBarButton( QIcon(":icons/status_connected.png"), auto_export, lambda: self.settings_dialog(self, self.window)) else: self.status_button = StatusBarButton( QIcon(":icons/status_disconnected.png"), _("AutoExport"), lambda: self.settings_dialog(self, self.window)) sb.addPermanentWidget(self.status_button) return sb def export_csv_ftp(self): try: if not self.autoexport_ftp_host or not self.autoexport_ftp_port: return if not self.autoexport_ftp_user or not self.autoexport_ftp_password: return filename = time.strftime("%Y_%m_%d__%H_%M_%S") + '.csv' lines = self.get_exported_data() ftp = FTP() ftp.connect(self.autoexport_ftp_host, int(self.autoexport_ftp_port)) ftp.login(self.autoexport_ftp_user, self.autoexport_ftp_password) if self.autoexport_ftp_dir: ftp.cwd(self.autoexport_ftp_dir) str_f = StringIO() transaction = csv.writer(str_f, lineterminator='\n') for line in lines: transaction.writerow(line) f = BytesIO(str_f.getvalue().encode('utf-8')) ftp.storlines("STOR " + filename, f) str_f.close() f.close() ftp.close() except Exception as e: print_error(str(e)) @hook def load_wallet(self, wallet, window): self.window = window self.wallet = wallet if not self.wallet or not self.autoexport_interval_seconds: return self.timer = self.call_repeatedly(self.autoexport_interval_seconds, self.export_csv) @hook def close_wallet(self, wallet): self.wallet = None if self.timer: self.timer() def requires_settings(self): return True def settings_widget(self, window): return EnterButton(_('Settings'), partial(self.settings_dialog, window)) def update_settings(self, initial=False): self.autoexport_interval_seconds = self.config.get( 'autoexport_interval_seconds', 0) self.autoexport_need_export_to_local = self.config.get( 'autoexport_need_export_to_local', False) self.autoexport_need_export_to_ftp = self.config.get( 'autoexport_need_export_to_ftp', False) self.autoexport_local_path = self.config.get('autoexport_local_path', '') self.autoexport_ftp_host = self.config.get('autoexport_ftp_host', '') self.autoexport_ftp_port = self.config.get('autoexport_ftp_port', 21) self.autoexport_ftp_user = self.config.get('autoexport_ftp_user', '') self.autoexport_ftp_password = self.config.get( 'autoexport_ftp_password', '') self.autoexport_ftp_dir = self.config.get('autoexport_ftp_dir', '') if self.timer: self.timer() self.timer = None if initial or not self.wallet or not self.autoexport_interval_seconds: return self.timer = self.call_repeatedly(self.autoexport_interval_seconds, self.export_csv) if self.autoexport_interval_seconds and (self.auto_export_enabled()): auto_export = _("AutoExport: {}sec.".format( self.autoexport_interval_seconds)) self.status_button.setToolTip(auto_export) self.status_button.setIcon(QIcon(":icons/status_connected.png")) else: self.status_button.setToolTip(_("AutoExport")) self.status_button.setIcon(QIcon(":icons/status_disconnected.png")) def settings_dialog(self, window): d = WindowModalDialog(window, _("AutoExport settings")) d.setMinimumSize(500, 200) layout = QVBoxLayout(d) # Initialize tab screen tabs = QTabWidget() tab0 = QWidget() tab1 = QWidget() tab2 = QWidget() tabs.resize(500, 200) # Add tabs tabs.addTab(tab0, _('Interval')) tabs.addTab(tab1, _('Local')) tabs.addTab(tab2, _('FTP')) # Create Interval tab grid = QGridLayout() tab0.layout = grid grid.addWidget(QLabel('Interval to auto export in seconds'), 0, 0) export_interval_seconds = QLineEdit() export_interval_seconds.setValidator(QIntValidator()) try: default_value = str(int(self.autoexport_interval_seconds)) except: default_value = '0' export_interval_seconds.setText(default_value) grid.addWidget(export_interval_seconds, 0, 1) tab0.setLayout(tab0.layout) # Create LocalExport tab grid = QGridLayout() tab1.layout = grid grid.addWidget(QLabel('Need export to local path'), 0, 0) export_need_export_to_local = QCheckBox() try: default_value = bool(self.autoexport_need_export_to_local) except: default_value = False export_need_export_to_local.setChecked(default_value) grid.addWidget(export_need_export_to_local, 0, 1) grid.addWidget(QLabel('Local path'), 1, 0) export_local_path = QLineEdit() try: default_value = str(self.autoexport_local_path) except: default_value = '' export_local_path.setText(default_value) grid.addWidget(export_local_path, 1, 1) tab1.setLayout(tab1.layout) # Create FTPExport tab grid = QGridLayout() tab2.layout = grid grid.addWidget(QLabel('Need export to ftp'), 0, 0) export_need_export_to_ftp = QCheckBox() try: default_value = bool(self.autoexport_need_export_to_ftp) except: default_value = False export_need_export_to_ftp.setChecked(default_value) grid.addWidget(export_need_export_to_ftp, 0, 1) grid.addWidget(QLabel('FTP Host'), 1, 0) export_ftp_host = QLineEdit() try: default_value = str(self.autoexport_ftp_host) except: default_value = '' export_ftp_host.setText(default_value) grid.addWidget(export_ftp_host, 1, 1) grid.addWidget(QLabel('FTP port'), 1, 2) export_ftp_port = QLineEdit() export_ftp_port.setValidator(QIntValidator()) try: default_value = str(int(self.autoexport_ftp_port)) except: default_value = '21' export_ftp_port.setText(default_value) grid.addWidget(export_ftp_port, 1, 3) grid.addWidget(QLabel('FTP user'), 2, 0) export_ftp_user = QLineEdit() try: default_value = str(self.autoexport_ftp_user) except: default_value = '' export_ftp_user.setText(default_value) grid.addWidget(export_ftp_user, 2, 1) grid.addWidget(QLabel('FTP password'), 2, 2) export_ftp_password = QLineEdit() try: default_value = str(self.autoexport_ftp_password) except: default_value = '' export_ftp_password.setEchoMode(QLineEdit.Password) export_ftp_password.setText(default_value) grid.addWidget(export_ftp_password, 2, 3) grid.addWidget(QLabel('FTP path'), 3, 0) export_ftp_dir = QLineEdit() try: default_value = str(self.autoexport_ftp_dir) except: default_value = '' export_ftp_dir.setText(default_value) grid.addWidget(export_ftp_dir, 3, 1) tab2.setLayout(tab2.layout) # Add tabs to widget layout.addWidget(tabs) layout.addStretch() layout.addLayout(Buttons(CloseButton(d), OkButton(d))) if not d.exec_(): return try: int_export_interval_seconds = int(export_interval_seconds.text()) except: int_export_interval_seconds = 0 self.config.set_key('autoexport_interval_seconds', int_export_interval_seconds) self.config.set_key('autoexport_need_export_to_ftp', export_need_export_to_ftp.isChecked()) self.config.set_key('autoexport_need_export_to_local', export_need_export_to_local.isChecked()) self.config.set_key('autoexport_local_path', export_local_path.text()) self.config.set_key('autoexport_ftp_host', export_ftp_host.text()) self.config.set_key('autoexport_ftp_port', export_ftp_port.text()) self.config.set_key('autoexport_ftp_user', export_ftp_user.text()) self.config.set_key('autoexport_ftp_password', export_ftp_password.text()) self.config.set_key('autoexport_ftp_dir', export_ftp_dir.text()) self.update_settings()