def onSave(self): # Get new config data protocol = "http" if self.ui.protocol_select.currentIndex( ) == 0 else "https" host = self.ui.host_edt.text() user = self.ui.user_edt.text() passwd = self.ui.passwd_edt.text() # Check malformed URL url_string = "%s://%s:%s@%s" % (protocol, user, passwd, host) if checkRPCstring(url_string): if self.changing_index is None: # Save new entry in DB. self.main_wnd.db.addRPCServer(protocol, host, user, passwd) else: # Edit existing entry to DB. id = self.main_wnd.mainWindow.rpcServersList[ self.changing_index].get('id') self.main_wnd.db.editRPCServer(protocol, host, user, passwd, id) # If this was previously selected in mainWindow, update status clients = self.main_wnd.mainWindow.header.rpcClientsBox data = clients.itemData(clients.currentIndex()) if data.get('id') == id and data.get('isCustom'): ThreadFuns.runInThread( self.main_wnd.mainWindow.updateRPCstatus, (True, ), ) # call onCancel self.onCancel()
def onSearchPK(self): fromAddress = self.ui.fromAddressRadioBtn.isChecked() self.hwAcc = self.ui.hwAccountSpingBox.value() self.currIsTestnet = self.ui.testnetCheckBox.isChecked() if fromAddress: addy = self.ui.addressLineEdit.text().strip() if len(addy) == 0: mess = "No address. Insert PIVX address first." myPopUp_sb(self.main_wnd, QMessageBox.Warning, 'SPMT - no address', mess) return if not checkPivxAddr(addy, self.currIsTestnet): net = "testnet" if self.currIsTestnet else "mainnet" mess = "PIVX address not valid. Insert valid PIVX %s address" % net myPopUp_sb(self.main_wnd, QMessageBox.Warning, 'SPMT - invalid address', mess) return # check hw connection while self.main_wnd.hwStatus != 2: mess = "HW device not connected. Try to connect?" ans = myPopUp(self.main_wnd, QMessageBox.Question, 'SPMT - hw check', mess) if ans == QMessageBox.No: return # re connect self.main_wnd.onCheckHw() # Go! if fromAddress: self.spath_found = False ThreadFuns.runInThread(self.findSpath, (0, 10), self.findSpath_done) else: self.spath_found = True self.spath = self.ui.spathSpinBox.value() self.findPubKey()
def __init__(self, main_tab): QDialog.__init__(self, parent=main_tab.ui) self.main_tab = main_tab self.setWindowTitle('Sweep All Rewards') self.setupUI() self.connectButtons() ThreadFuns.runInThread(self.load_utxos_thread, (), self.display_utxos)
def prepare_transfer_tx_bulk(self, caller, rewardsArray, dest_address, tx_fee, isTestnet=False): with self.lock: # For each UTXO create a Ledger 'trusted input' self.trusted_inputs = [] # https://klmoney.wordpress.com/bitcoin-dissecting-transactions-part-2-building-a-transaction-by-hand) self.arg_inputs = [] self.amount = 0 num_of_sigs = sum([len(mnode['utxos']) for mnode in rewardsArray]) curr_utxo_checked = 0 for mnode in rewardsArray: # Add proper HW path (for current device) on each utxo if isTestnet: mnode['path'] = MPATH_TESTNET + mnode['path'] else: mnode['path'] = MPATH + mnode['path'] # Create a TX input with each utxo for utxo in mnode['utxos']: self.append_inputs_to_TX(utxo, mnode['path']) # completion percent emitted curr_utxo_checked += 1 completion = int(95 * curr_utxo_checked / num_of_sigs) self.tx_progress.emit(completion) self.amount -= int(tx_fee) self.amount = int(self.amount) arg_outputs = [{'address': dest_address, 'valueSat': self.amount}] # there will be multiple outputs soon self.new_transaction = bitcoinTransaction() # new transaction object to be used for serialization at the last stage self.new_transaction.version = bytearray([0x01, 0x00, 0x00, 0x00]) self.tx_progress.emit(99) for o in arg_outputs: output = bitcoinOutput() output.script = compose_tx_locking_script(o['address'], isTestnet) output.amount = int.to_bytes(o['valueSat'], 8, byteorder='little') self.new_transaction.outputs.append(output) self.tx_progress.emit(100) # join all outputs - will be used by Ledger for signing transaction self.all_outputs_raw = self.new_transaction.serializeOutputs() self.mBox2 = QMessageBox(caller) self.messageText = "<p>Confirm transaction on your device, with the following details:</p>" # messageText += "From bip32_path: <b>%s</b><br><br>" % str(bip32_path) self.messageText += "<p>Payment to:<br><b>%s</b></p>" % dest_address self.messageText += "<p>Net amount:<br><b>%s</b> PIV</p>" % str(round(self.amount / 1e8, 8)) self.messageText += "<p>Fees:<br><b>%s</b> PIV<p>" % str(round(int(tx_fee) / 1e8, 8)) messageText = self.messageText + "Signature Progress: 0 %" self.mBox2.setText(messageText) self.mBox2.setIconPixmap(caller.tabMain.ledgerImg.scaledToHeight(200, Qt.SmoothTransformation)) self.mBox2.setWindowTitle("CHECK YOUR LEDGER") self.mBox2.setStandardButtons(QMessageBox.NoButton) self.mBox2.setMaximumWidth(500) self.mBox2.show() ThreadFuns.runInThread(self.signTxSign, (), self.signTxFinish)
def prepare_transfer_tx_bulk(self, caller, rewardsArray, dest_address, tx_fee, isTestnet=False): inputs = [] outputs = [] c_name = "PIVX" if isTestnet: c_name += " Testnet" coin = coins.by_name[c_name] with self.lock: self.amount = 0 for mnode in rewardsArray: # Add proper HW path (for current device) on each utxo if isTestnet: mnode['path'] = MPATH_TESTNET + mnode['path'] else: mnode['path'] = MPATH + mnode['path'] # Create a TX input with each utxo for utxo in mnode['utxos']: self.append_inputs_to_TX(utxo, mnode['path'], inputs) self.amount = int(self.amount) self.amount -= int(tx_fee) if self.amount < 0: raise Exception('Invalid TX: inputs + fee != outputs') outputs.append( trezor_proto.TxOutputType( address=dest_address, address_n=None, amount=self.amount, script_type=trezor_proto.OutputScriptType.PAYTOSCRIPTHASH)) txes = self.load_prev_txes(rewardsArray) self.mBox2 = QMessageBox(caller) self.messageText = "<p>Signing transaction...</p>" # messageText += "From bip32_path: <b>%s</b><br><br>" % str(bip32_path) self.messageText += "<p>Payment to:<br><b>%s</b></p>" % dest_address self.messageText += "<p>Net amount:<br><b>%s</b> PIV</p>" % str( round(self.amount / 1e8, 8)) self.messageText += "<p>Fees:<br><b>%s</b> PIV<p>" % str( round(int(tx_fee) / 1e8, 8)) messageText = self.messageText + "Signature Progress: 0 %" self.mBox2.setText(messageText) self.setBoxIcon(self.mBox2, caller) self.mBox2.setWindowTitle("CHECK YOUR TREZOR") self.mBox2.setStandardButtons(QMessageBox.NoButton) self.mBox2.setMaximumWidth(500) self.mBox2.show() ThreadFuns.runInThread(self.signTxSign, (inputs, outputs, txes, isTestnet), self.signTxFinish)
def onRefreshTorrents(self): self.ui.refreshingLabel.show() self.ui.torrentBox.setRowCount(0) self.torrents = [] self.selectedTorrents = [] self.ui.torrentBox.setSortingEnabled(False) ThreadFuns.runInThread(self.loadTorrents_thread, (), on_thread_finish=self.displayTorrents)
def __init__(self, main_wnd): QDialog.__init__(self, parent=main_wnd.ui) self.main_wnd = main_wnd self.setWindowTitle('Budget Projection') self.initUI() self.ui.ok_btn.clicked.connect(lambda: self.accept()) self.next_superBlock = 0 ThreadFuns.runInThread(self.loadBudgetProjection_thread, (), self.displayBudgetProjection)
def onRefreshProposals(self): self.ui.refreshingLabel.show() self.ui.proposalBox.setRowCount(0) self.proposals = [] self.selectedProposals = [] self.ui.proposalBox.setSortingEnabled(False) ThreadFuns.runInThread(self.loadProposals_thread, (), self.displayProposals)
def load_data(self): # clear table self.ui.tableW.setRowCount(0) # load last used destination from cache self.ui.edt_destination.setText(self.main_tab.caller.parent.cache.get("lastAddress")) # load useSwiftX check from cache if self.main_tab.caller.parent.cache.get("useSwiftX"): self.ui.swiftxCheck.setChecked(True) # Reload UTXOs ThreadFuns.runInThread(self.main_tab.caller.t_rewards.load_utxos_thread, ())
def loadSelection(self): # Check dongle printDbg("Checking HW device") if self.caller.hwStatus != 2: self.caller.myPopUp2(QMessageBox.Critical, 'PET4L - hw device check', "Connect to HW device first") printDbg("Unable to connect - hw status: %d" % self.caller.hwStatus) return None self.ui.addySelect.clear() ThreadFuns.runInThread(self.loadSelection_thread, ())
def vote_thread_end(self): message = '<p>Votes sent</p>' if self.successVotes > 0: message += '<p>Successful Votes: <b>%d</b></p>' % self.successVotes if self.failedVotes > 0: message += '<p>Failed Votes: <b>%d</b>' % self.failedVotes myPopUp_sb(self.caller, "info", 'Vote Finished', message) # refresh my votes on proposals self.ui.selectedPropLabel.setText("<em><b>0</b> proposals selected") self.ui.resetStatusLabel() ThreadFuns.runInThread(self.updateMyVotes_thread, (), self.displayProposals)
def onCheckAllMN(self): if not self.caller.rpcConnected: self.caller.myPopUp2(QMessageBox.Critical, 'SPMT - hw device check', "RPC server must be connected to perform this action.") printDbg("Unable to connect: %s" % self.caller.rpcStatusMess) return try: printOK("Check-All pressed") ThreadFuns.runInThread(self.updateAllMasternodes_thread, (), self.displayMNlistUpdated) except Exception as e: err_msg = "error in checkAllMN" printException(getCallerName(), getFunctionName(), err_msg, e)
def load_data(self): # clear table self.ui.tableW.setRowCount(0) # load last used destination from cache self.ui.edt_destination.setText( self.main_tab.caller.parent.cache.get("lastAddress")) if self.loading_txes: self.display_utxos() else: # Reload UTXOs ThreadFuns.runInThread( self.main_tab.caller.t_rewards.load_utxos_thread, ())
def vote_thread_end(self): message = '<p>Votes sent</p>' if self.successVotes > 0: message += '<p>Successful Votes: <b>%d</b></p>' % self.successVotes if self.failedVotes > 0: message += '<p>Failed Votes: <b>%d</b>' % self.failedVotes self.caller.myPopUp2(QMessageBox.Information, 'Vote Finished', message) # refresh proposals self.ui.proposalBox.setRowCount(0) self.ui.proposalBox.setSortingEnabled(False) self.ui.refreshingLabel.show() self.ui.selectedPropLabel.setText("<em><b>0</b> proposals selected") ThreadFuns.runInThread(self.countMyVotes_thread, (), self.displayProposals)
def onVote(self, vote_code): if len(self.selectedProposals) == 0: message = "NO PROPOSAL SELECTED. Select proposals from the list." myPopUp_sb(self.caller, "crit", 'Vote on proposals', message) return if len(self.votingMasternodes) == 0: message = "NO MASTERNODE SELECTED FOR VOTING. Click on 'Select Masternodes...'" myPopUp_sb(self.caller, "crit", 'Vote on proposals', message) return reply = self.summaryDlg(vote_code) if reply == 1: ThreadFuns.runInThread(self.vote_thread, ([vote_code]), self.vote_thread_end)
def onCheckAllMN(self): if not self.caller.rpcConnected: myPopUp_sb(self.caller, "crit", 'SPMT - hw device check', "RPC server must be connected to perform this action.") printDbg("Unable to connect: %s" % self.caller.rpcStatusMess) return if self.caller.masternode_list is None or self.caller.masternode_list == []: myPopUp_sb(self.caller, "crit", 'SPMT - Check-All masternodes', "No masternode in list. Add masternodes first.") return try: printDbg("Check-All pressed") ThreadFuns.runInThread(self.updateAllMasternodes_thread, (), self.displayMNlistUpdated) except Exception as e: err_msg = "error in checkAllMN" printException(getCallerName(), getFunctionName(), err_msg, e)
def onVote(self, vote_code): if len(self.selectedProposals) == 0: printDbg("NO PROPOSAL SELECTED. Select proposals from the list.") return if len(self.votingMasternodes) == 0: printDbg( "NO MASTERNODE SELECTED FOR VOTING. Click on 'Select Masternodes...'" ) return reply = self.summaryDlg(vote_code) if reply == 1: ThreadFuns.runInThread(self.vote_thread, ([vote_code]), self.vote_thread_end)
def signMess(self, caller, hwpath, message, isTestnet=False): if isTestnet: path = MPATH_TESTNET + hwpath else: path = MPATH + hwpath # Ledger doesn't accept characters other that ascii printable: # https://ledgerhq.github.io/btchip-doc/bitcoin-technical.html#_sign_message message = message.encode('ascii', 'ignore') message_sha = splitString(single_sha256(message).hex(), 32) # Connection pop-up mBox = QMessageBox(caller) warningText = "Another application (such as Ledger Wallet app) has probably taken over " warningText += "the communication with the Ledger device.<br><br>To continue, close that application and " warningText += "click the <b>Retry</b> button.\nTo cancel, click the <b>Abort</b> button" mBox.setText(warningText) mBox.setWindowTitle("WARNING") mBox.setStandardButtons(QMessageBox.Retry | QMessageBox.Abort) # Ask confirmation with self.lock: info = self.chip.signMessagePrepare(path, message) while info['confirmationNeeded'] and info['confirmationType'] == 34: ans = mBox.exec_() if ans == QMessageBox.Abort: raise Exception("Reconnect HW device") # we need to reconnect the device self.initDevice() info = self.chip.signMessagePrepare(path, message) printOK('Signing Message') self.mBox = QMessageBox(caller) messageText = "Check display of your hardware device\n\n- message hash:\n\n%s\n\n-path:\t%s\n" % ( message_sha, path) self.mBox.setText(messageText) self.mBox.setIconPixmap( caller.tabMain.ledgerImg.scaledToHeight( 200, Qt.SmoothTransformation)) self.mBox.setWindowTitle("CHECK YOUR LEDGER") self.mBox.setStandardButtons(QMessageBox.NoButton) self.mBox.show() # Sign message ThreadFuns.runInThread(self.signMessageSign, (), self.signMessageFinish)
def onButtonSave(self, main_dlg): try: main_dlg.rpc_ip = ip_address( self.edt_rpcIp.text().strip()).compressed main_dlg.rpc_port = int(self.edt_rpcPort.value()) main_dlg.rpc_user = self.edt_rpcUser.text() main_dlg.rpc_password = self.edt_rpcPassword.text() conf = {} conf["rpc_ip"] = main_dlg.rpc_ip conf["rpc_port"] = main_dlg.rpc_port conf["rpc_user"] = main_dlg.rpc_user conf["rpc_password"] = main_dlg.rpc_password # Update File writeRPCfile(conf) # Update current RPC Server main_dlg.main_wnd.mainWindow.rpcClient = None main_dlg.main_wnd.mainWindow.rpcConnected = False printDbg("Trying to connect to RPC server [%s]:%s" % (conf["rpc_ip"], str(conf["rpc_port"]))) self.runInThread = ThreadFuns.runInThread( main_dlg.main_wnd.mainWindow.updateRPCstatus, (), main_dlg.main_wnd.mainWindow.updateRPCled) main_dlg.close() except Exception as e: print(e)
def __init__(self, caller): self.caller = caller self.ui = TabAddTorrent_gui(caller) self.caller.tabAddTorrent = self.ui self.ui.submitBtn.clicked.connect(lambda: self.submitTorrent()) rpc_ip, rpc_port, rpc_user, rpc_passwd = readRPCfile() self.server_uri = 'http://{}:{}'.format(rpc_ip, rpc_port) self.auth_pair = rpc_user, rpc_passwd self.current_block = None self.next_super = None self.update = False ThreadFuns.runInThread(self.updater, ())
def findSpath_done(self): if self.spath_found: self.findPubKey() else: addy = self.ui.addressLineEdit.text().strip() starting_spath = self.curr_starting_spath spath_count = self.curr_spath_count mess = "Scanned addresses <b>%d</b> to <b>%d</b> of HW account <b>%d</b>.<br>" % ( starting_spath, starting_spath + spath_count - 1, self.hwAcc) mess += "Unable to find the address <i>%s</i>.<br>Maybe it's on a different account.<br><br>" % addy mess += "Do you want to scan %d more addresses of account n.<b>%d</b> ?" % (spath_count, self.hwAcc) ans = myPopUp(self.main_wnd, QMessageBox.Question, 'SPMT - spath search', mess) if ans == QMessageBox.Yes: # Look for 10 more addresses starting_spath += spath_count ThreadFuns.runInThread(self.findSpath, (starting_spath, spath_count), self.findSpath_done)
def onButtonSave(self, main_dlg): main_dlg.rpc_ip = ip_address(self.edt_rpcIp.text().strip()).compressed main_dlg.rpc_port = int(self.edt_rpcPort.value()) main_dlg.rpc_user = self.edt_rpcUser.text() main_dlg.rpc_password = self.edt_rpcPassword.text() conf = {} conf["rpc_ip"] = main_dlg.rpc_ip conf["rpc_port"] = main_dlg.rpc_port conf["rpc_user"] = main_dlg.rpc_user conf["rpc_password"] = main_dlg.rpc_password urlstring = "http://%s:%s@%s:%d" % (conf["rpc_user"], conf["rpc_password"], conf["rpc_ip"], conf["rpc_port"]) if checkRPCstring(urlstring, action_msg="Restoring previous configuration"): # Update datafile writeToFile(conf, rpc_File) # Update current RPC Server main_dlg.main_wnd.mainWindow.rpcClient = None main_dlg.main_wnd.mainWindow.rpcConnected = False printDbg("Trying to connect to RPC server [%s]:%s" % (conf["rpc_ip"], str(conf["rpc_port"]))) self.runInThread = ThreadFuns.runInThread( main_dlg.main_wnd.mainWindow.updateRPCstatus, (), main_dlg.main_wnd.mainWindow.updateRPCled) else: printDbg("Restored RPC credentials. ") main_dlg.close()
def signMess(self, caller, hwpath, message, isTestnet=False): if isTestnet: path = MPATH_TESTNET + hwpath else: path = MPATH + hwpath # Connection pop-up self.mBox = QMessageBox(caller) messageText = "Check display of your hardware device\n\n- message:\n\n%s\n\n-path:\t%s\n" % ( splitString(message, 32), path) self.mBox.setText(messageText) self.setBoxIcon(self.mBox, caller) self.mBox.setWindowTitle("CHECK YOUR TREZOR") self.mBox.setStandardButtons(QMessageBox.NoButton) self.mBox.show() # Sign message ThreadFuns.runInThread(self.signMessageSign, (path, message, isTestnet), self.signMessageFinish)
def onChangeSelected(self): if self.ui.addySelect.currentIndex() >= 0: self.curr_path = self.ui.addySelect.itemData(self.ui.addySelect.currentIndex())[0] self.curr_addr = self.ui.addySelect.itemData(self.ui.addySelect.currentIndex())[1] self.curr_balance = self.ui.addySelect.itemData(self.ui.addySelect.currentIndex())[2] if self.curr_balance is not None: self.runInThread = ThreadFuns.runInThread(self.load_utxos_thread, (), self.display_utxos)
def submitTorrent(self): name = self.ui.fileNameTextBox.text() if not name: highlight_textbox(self.ui.fileNameTextBox, self.ui.fileNameLabel) payee = self.ui.paymentTextBox.text() if not payee: highlight_textbox(self.ui.paymentTextBox, self.ui.paymentLabel) uri = self.ui.magnetUriTextBox.text() if not uri: highlight_textbox(self.ui.magnetUriTextBox, self.ui.magnetUriLabel) cat = self.ui.categorySelect.currentText() if not all((name, uri, payee)): return ThreadFuns.runInThread(self.submit_torrent_thread, (name, uri, payee, cat))
def submitTorrent(self): name = self.ui.fileNameTextBox.text() if not name: highlight_textbox(self.ui.fileNameTextBox, self.ui.fileNameLabel) payee = self.ui.paymentTextBox.text() if not payee: highlight_textbox(self.ui.paymentTextBox, self.ui.paymentLabel) uri = self.ui.magnetUriTextBox.text() if not uri: highlight_textbox(self.ui.magnetUriTextBox, self.ui.magnetUriLabel) cat = self.ui.categorySelect.currentText() if not all((name, uri, payee)): return ThreadFuns.runInThread(self.submit_torrent_thread, (name, uri, payee, cat), on_thread_exception=self.display_error, on_thread_finish=self.notify_success, skip_raise_exception=False)
def onChangeSelectedMN(self): if self.ui.mnSelect.currentIndex() >= 0: self.curr_addr = self.ui.mnSelect.itemData(self.ui.mnSelect.currentIndex())[0] self.curr_txid = self.ui.mnSelect.itemData(self.ui.mnSelect.currentIndex())[1] self.curr_path = self.ui.mnSelect.itemData(self.ui.mnSelect.currentIndex())[2] if self.curr_addr is not None: result = self.caller.apiClient.getBalance(self.curr_addr) self.ui.addrAvailLine.setText("<i>%s PIVs</i>" % result) self.ui.selectedRewardsLine.setText("0.0") self.ui.rewardsList.box.clearSelection() self.ui.rewardsList.box.collateralRow = None self.ui.collateralHidden = True self.ui.btn_toggleCollateral.setText("Show Collateral") if result is not None: self.runInThread = ThreadFuns.runInThread(self.load_utxos_thread, (), self.display_utxos)
def create_sl_button(row, hash): result = QPushButton() result.setIcon(self.ui.question_icon) result.setToolTip('Get seeders and leechers') def sl_button_clicked(ctrl): saved_log = torrent_scraper.logger.log null_func = lambda _, __, ___: None torrent_scraper.logger.log = null_func saved_stdout = sys.stdout sys.stdout = io.StringIO() uri_extractor = r'urn\:btih\:([^&]+)' magnet_uri = re.findall(uri_extractor, hash) if not magnet_uri: return magnet_uri = magnet_uri[0] try: _, s, l, __ = torrent_scraper.scrape( magnet_uri, 'tracker.coppersurfer.tk', 6969) except ValueError: torrent_scraper.logger.log = saved_log return self.ui.torrentBox.removeCellWidget( row, self.ui.torrentBox.column_sl) self.ui.torrentBox.setItem(row, self.ui.torrentBox.column_sl, QTableWidgetItem(f'{s} / {l}')) torrent_scraper.logger.log = saved_log sys.stdout = saved_stdout result.clicked.connect( lambda: ThreadFuns.runInThread(sl_button_clicked, ())) return result
def onRefreshProposals(self): self.ui.resetStatusLabel() ThreadFuns.runInThread(self.loadProposals_thread, (),)
def load_data(self, pivx_addr): self.pivx_addr = pivx_addr ##--- PIVX Address self.edtAddress.setText(self.pivx_addr) ##--- Load utxos ThreadFuns.runInThread(self.load_utxos_thread, (), self.display_utxos)