def main(): """ Start the TinyWallet application. """ os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" sys.excepthook = exception_hook QtWidgets.QApplication.setDesktopSettingsAware(False) roboFont = QtGui.QFont("Roboto") roboFont.setPixelSize(16) QtWidgets.QApplication.setFont(roboFont) QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) qApp = QtWidgets.QApplication(sys.argv) qApp.setStyleSheet(Q.QUTILITY_STYLE) qApp.setPalette(Q.lightThemePalette) qApp.setWindowIcon(QtGui.QIcon(DCR.LOGO)) qApp.setApplicationName("Tiny Decred") loadFonts() decred = TinyWallet(qApp) try: qApp.exec_() except Exception as e: print(formatTraceback(e)) decred.sysTray.hide() qApp.deleteLater() return
def getCK(pw): try: cryptoKey = self.wallet.cryptoKey(pw) return f(cryptoKey) except Exception as e: self.log.error( f"error decoding encryption key with provided password: {e}" ) self.log.debug(formatTraceback(e)) self.appWindow.showError("password error")
def run(self): """ QThread method. Runs the func. """ try: self.returns = self.func(*self.args, **self.kwargs) except Exception as e: log.error("exception encountered in QThread: %s" % helpers.formatTraceback(e)) self.returns = False
def updateTip(self): """ Update the tip block. If the wallet is subscribed to block updates, this can be used sparingly. """ try: self.tipHeight = self.bestBlock()["height"] except Exception as e: log.error("failed to retrieve tip from blockchain: %s" % formatTraceback(e)) raise DecredError("no tip data retrieved")
def handleRequest(self, req): route = req["route"] handler = self.requestHandlers.get(route, None) if not handler: return { "error": f"unknown request route {route}", } try: return handler(req.get("payload", {})) except Exception as e: log.error(f"exception encountered with request {req}: {e}") print(helpers.formatTraceback(e)) return { "error": "internal server error", }
def blockHeader(self, hexHash): """ blockHeader will produce a blockHeader implements the BlockHeader API. Args: bHash (str): The block hash of the block header. Returns: BlockHeader: An object which implements the BlockHeader API. """ try: return self.headerDB[hashFromHex(hexHash).bytes()] except database.NoValueError: try: block = self.dcrdata.block.hash.header.raw(hexHash) blockHeader = msgblock.BlockHeader.deserialize(block["hex"]) self.saveBlockHeader(blockHeader) return blockHeader except Exception as e: log.warning("unable to retrieve block header: %s" % formatTraceback(e)) raise DecredError("failed to get block header for block %s" % hexHash)
def pubsubSignal(self, sig): """ Process a notification from the block explorer. Arg: sig (dict or string): The block explorer's notification, decoded. """ if sig == WS_DONE: return sigType = sig["event"] try: if sigType == "address": msg = sig["message"] addr = msg["address"] log.debug("signal received for %s" % msg["address"]) receiver = self.addrSubscribers.get(addr) if not receiver: log.error("no receiver registered for address %s", addr) return receiver(addr, msg["transaction"]) elif sigType == "newblock": self.tipHeight = sig["message"]["block"]["height"] for receiver in self.blockSubscribers: receiver(sig) elif sigType == "subscribeResp": # should check for error. pass elif sigType == "ping": # nothing to do here right now. May want to implement a # auto-reconnect using this signal. pass else: raise DecredError("unknown signal %s" % repr(sigType)) except Exception as e: log.error("failed to process pubsub message: %s" % formatTraceback(e))
def test_formatTraceback(): # Cannot actually raise an error because pytest intercepts it. assert (helpers.formatTraceback( DecredError("errmsg")) == "decred.DecredError: errmsg\n")