Beispiel #1
0
 async def do_get(self, url="/labels"):
     url = 'https://' + self.target_host + url
     network = Network.get_instance()
     proxy = network.proxy if network else None
     async with make_aiohttp_session(proxy) as session:
         async with session.get(url) as result:
             return await result.json()
Beispiel #2
0
    def __init__(self, config: 'SimpleConfig', exctype, value, tb):
        BaseCrashReporter.__init__(self, exctype, value, tb)
        self.network = Network.get_instance()
        self.config = config

        QWidget.__init__(self)
        self.setWindowTitle('Firo Electrum - ' + _('An Error Occurred'))
        self.setMinimumSize(600, 300)

        Logger.__init__(self)

        main_box = QVBoxLayout()

        heading = QLabel('<h2>' + BaseCrashReporter.CRASH_TITLE + '</h2>')
        main_box.addWidget(heading)
        main_box.addWidget(QLabel(BaseCrashReporter.CRASH_MESSAGE))

        main_box.addWidget(QLabel(BaseCrashReporter.REQUEST_HELP_MESSAGE))

        collapse_info = QPushButton(_("Show report contents"))
        collapse_info.clicked.connect(
            lambda: self.msg_box(QMessageBox.NoIcon,
                                 self,
                                 _("Report contents"),
                                 self.get_report_string(),
                                 rich_text=True))

        main_box.addWidget(collapse_info)

        main_box.addWidget(QLabel(BaseCrashReporter.DESCRIBE_ERROR_MESSAGE))

        self.description_textfield = QTextEdit()
        self.description_textfield.setFixedHeight(50)
        self.description_textfield.setPlaceholderText(
            _("Do not enter sensitive/private information here. "
              "The report will be visible on the public issue tracker."))
        main_box.addWidget(self.description_textfield)

        main_box.addWidget(QLabel(BaseCrashReporter.ASK_CONFIRM_SEND))

        buttons = QHBoxLayout()

        report_button = QPushButton(_('Send Bug Report'))
        report_button.clicked.connect(self.send_report)
        report_button.setIcon(read_QIcon("tab_send.png"))
        buttons.addWidget(report_button)

        never_button = QPushButton(_('Never'))
        never_button.clicked.connect(self.show_never)
        buttons.addWidget(never_button)

        close_button = QPushButton(_('Not Now'))
        close_button.clicked.connect(self.close)
        buttons.addWidget(close_button)

        main_box.addLayout(buttons)

        self.setLayout(main_box)
        self.show()
Beispiel #3
0
 async def do_scan(self, wallet, cnt):
     w = wallet
     try:
         async with self.wallet_scans_lock:
             ws = self.wallet_scans.get(w)
             if not ws or ws.running:
                 return
             ws.running = True
             scans = list(ws.scans.values())
         n = Network.get_instance()
         loop = n.asyncio_loop
         done_cnt = 0
         to_scan_cnt = 0
         for s in scans:
             if not s.active:
                 continue
             to_scan_cnt += len(s.uncompleted)
         if to_scan_cnt:
             self.logger.info(f'total count to rescan: {to_scan_cnt}')
         else:
             for s in scans:
                 if not s.active:
                     continue
                 async with self.wallet_scans_lock:
                     await loop.run_in_executor(None, s.derive_addrs, cnt)
                 to_scan_cnt += cnt
             self.logger.info(f'total count to scan: {to_scan_cnt}')
         if not to_scan_cnt:
             return
         async with TaskGroup() as group:
             for s in scans:
                 for i, addr in s.addrs.items():
                     if i in s.balances:
                         continue
                     script = bitcoin.address_to_script(addr)
                     scripthash = bitcoin.script_to_scripthash(script)
                     coro = n.get_balance_for_scripthash(scripthash)
                     s.tasks[i] = await group.spawn(coro)
             while True:
                 task = await group.next_done()
                 if task is None:
                     break
                 done_cnt += 1
                 await self.on_progress(w, 100 * done_cnt / to_scan_cnt)
         for s in scans:
             for i, task in s.tasks.items():
                 try:
                     balance = task.result()
                     s.balances[i] = balance_total(**balance)
                     if i in s.errors:
                         s.errors.pop(i)
                 except BaseException as e:
                     self.logger.info(f'Exception on get_balance {repr(e)}')
                     s.errors[i] = e
             s.tasks.clear()
         await self.on_completed(w)
     except Exception as e:
         self.logger.info(f'Exception during wallet_scan: {repr(e)}')
         await self.on_error(w, e)
Beispiel #4
0
 async def do_post(self, url="/labels", data=None):
     url = 'https://' + self.target_host + url
     network = Network.get_instance()
     proxy = network.proxy if network else None
     async with make_aiohttp_session(proxy) as session:
         async with session.post(url, json=data) as result:
             try:
                 return await result.json()
             except Exception as e:
                 raise Exception('Could not decode: ' +
                                 await result.text()) from e
Beispiel #5
0
 async def add_found(self, wallet):
     w = wallet
     try:
         n = Network.get_instance()
         loop = n.asyncio_loop
         async with self.wallet_scans_lock:
             ws = self.wallet_scans.get(w)
             if not ws or ws.running:
                 return
             ws.running = True
             scans = list(ws.scans.values())
             for s in scans:
                 await loop.run_in_executor(None, s.create_new_addrs, w)
         await self.on_completed(w)
     except Exception as e:
         self.logger.info(f'Exception during add_found: {repr(e)}')
         await self.on_error(w, e)
Beispiel #6
0
    def __init__(self, app, plugin):
        super(ScanOverGapPopup, self).__init__()
        self.app = app
        self.wallet = w = app.wallet
        self.plugin = p = plugin
        self.title = plugin.MSG_TITLE
        self.network = Network.get_instance()
        coro = plugin.init_scans(w)
        fut = asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop)
        fut.result()
        box = self.box
        box.add_widget(Factory.WWLabel(text=p.MSG_SCAN_TITLE),
                       len(box.children))
        self.scan_list = ScanList(self)
        self.scan_list.update()
        box.add_widget(self.scan_list, len(box.children) - 1)
        self.set_do_scan_btn_txt(p.DEF_SCAN_CNT)
        self.reset_scans_btn.text = p.MSG_RESET
        self.add_found_btn.text = p.MSG_ADD_FOUND
        self.scan_count_msg = p.MSG_SCAN_COUNT
        self.scan_cnt_sb.min = p.MIN_SCAN_CNT
        self.scan_cnt_sb.max = p.MAX_SCAN_CNT
        self.scan_cnt_sb.step = p.DEF_SCAN_CNT
        self.scan_cnt_sb.val = p.DEF_SCAN_CNT
        self.scan_progress_msg = p.MSG_PROGRESS

        ws = self.plugin.wallet_scans.get(w)
        self.scan_progress_pb.value = ws.progress
        if ws.running:
            self.scan_cnt_sb.disabled = True
            self.do_scan_btn.disabled = True
            self.reset_scans_btn.disabled = True
        self.set_add_found_bnt_state()
        ScanOverGapEvents.bind(on_completed=self.on_completed_kivy)
        ScanOverGapEvents.bind(on_progress=self.on_progress_kivy)
        ScanOverGapEvents.bind(on_error=self.on_error_kivy)
Beispiel #7
0
 def is_available(self):
     if Network.get_instance():
         return True
     self.logger.warning(f'Plugin {self.name} unavailable in offline mode')
     return False
Beispiel #8
0
 def __init__(self):
     QThread.__init__(self)
     Logger.__init__(self)
     self.network = Network.get_instance()
Beispiel #9
0
 def recovery(self):
     network = Network.get_instance()
     coroutine = account_discovery(network, self.get_account_xpub)
     return network.run_from_another_thread(coroutine)
Beispiel #10
0
    def __init__(self, window, plugin):
        WindowModalDialog.__init__(self, window, plugin.MSG_TITLE)
        self.setMinimumSize(800, 400)

        self.wallet = w = window.parent().wallet
        self.plugin = plugin
        self.config = plugin.config
        self.network = Network.get_instance()
        coro = plugin.init_scans(w)
        fut = asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop)
        fut.result()

        g = QGridLayout(self)

        g.addWidget(WWLabel(plugin.MSG_SCAN_TITLE), 0, 0, 1, -1)

        self.scan_list = ScanListWidget(self)
        self.scan_list.update()
        self.scan_list.itemChanged.connect(self.scan_list_item_changed)
        g.addWidget(self.scan_list, 1, 0, 1, -1)

        g.addWidget(QLabel(plugin.MSG_SCAN_COUNT), 2, 0)
        self.scan_cnt_sb = QSpinBox()
        self.scan_cnt_sb.setRange(plugin.MIN_SCAN_CNT, plugin.MAX_SCAN_CNT)
        self.scan_cnt_sb.setValue(plugin.DEF_SCAN_CNT)
        self.scan_cnt_sb.setSingleStep(plugin.DEF_SCAN_CNT)
        self.scan_cnt_sb.valueChanged.connect(self.on_scan_cnt_value_changed)
        g.addWidget(self.scan_cnt_sb, 2, 1)

        self.do_scan_btn = QPushButton()
        self.set_do_scan_btn_txt(plugin.DEF_SCAN_CNT)
        self.do_scan_btn.clicked.connect(partial(self.do_scan, w))
        g.addWidget(self.do_scan_btn, 2, 3)

        g.addWidget(QLabel(plugin.MSG_PROGRESS), 2, 4)
        self.scan_progress_pb = QProgressBar()
        self.scan_progress_pb.setValue(0)
        g.addWidget(self.scan_progress_pb , 2, 5)

        g.setRowStretch(10, 1)

        hbox = QHBoxLayout()
        self.reset_scans_btn = QPushButton(plugin.MSG_RESET)
        self.reset_scans_btn.clicked.connect(partial(self.reset_scans, w))
        hbox.addWidget(self.reset_scans_btn)
        hbox.addStretch(1)
        self.add_found_btn = QPushButton(plugin.MSG_ADD_FOUND)
        self.add_found_btn.clicked.connect(partial(self.add_found_coins, w))
        hbox.addWidget(self.add_found_btn)
        hbox.addWidget(CloseButton(self))
        g.addLayout(hbox, 11, 0, 1, -1)

        self.plugin.progress_sig.s.connect(self.on_progress_qt)
        self.plugin.completed_sig.s.connect(self.on_completed_qt)
        self.plugin.error_sig.s.connect(self.on_error_qt)
        self.cleaned_up = False

        ws = self.plugin.wallet_scans.get(w)
        self.scan_progress_pb.setValue(ws.progress)
        if ws.running:
            self.scan_cnt_sb.setEnabled(False)
            self.do_scan_btn.setEnabled(False)
            self.reset_scans_btn.setEnabled(False)
        self.set_add_found_bnt_state()