def onSendRewards(self): self.dest_addr = self.ui.destinationLine.text().strip() self.currFee = self.ui.feeLine.value() * 1e8 # Check spending collateral if (not self.ui.collateralHidden and self.ui.rewardsList.box.collateralRow is not None and self.ui.rewardsList.box.item(self.ui.rewardsList.box.collateralRow, 0).isSelected() ): warning1 = "Are you sure you want to transfer the collateral?" warning2 = "Really?" warning3 = "Take a deep breath. Do you REALLY want to transfer your collateral?" ans = myPopUp(self.caller, "warn", 'SPMT - warning', warning1) if ans == QMessageBox.No: return None else: ans2 = myPopUp(self.caller, "warn", 'SPMT - warning', warning2) if ans2 == QMessageBox.No: return None else: ans2 = myPopUp(self.caller, "crit", 'SPMT - warning', warning3) if ans2 == QMessageBox.No: return None # Check HW device while self.caller.hwStatus != 2: mess = "HW device not connected. Try to connect?" ans = myPopUp(self.caller, QMessageBox.Question, 'SPMT - hw check', mess) if ans == QMessageBox.No: return # re connect self.caller.onCheckHw() # SEND self.SendRewards(self.useSwiftX())
def onStartAllMN(self): printOK("Start-All pressed") # Check RPC & HW device if not self.caller.rpcConnected or self.caller.hwStatus != 2: myPopUp_sb(self.caller, "crit", 'SPMT - hw/rpc device check', "Connect to RPC server and HW device first") printDbg("Hardware device or RPC server not connected") return None try: reply = myPopUp(self.caller, "quest", 'Confirm START', "Are you sure you want to start ALL masternodes?", QMessageBox.Yes) if reply == QMessageBox.Yes: mnList = [ x for x in self.caller.masternode_list if x['isHardware'] ] for mn_conf in mnList: self.masternodeToStart = Masternode( self, mn_conf['name'], mn_conf['ip'], mn_conf['port'], mn_conf['mnPrivKey'], mn_conf['hwAcc'], mn_conf['collateral'], mn_conf['isTestnet']) # connect signal self.masternodeToStart.sigdone.connect(self.sendBroadcast) self.mnToStartList.append(self.masternodeToStart) self.startMN() except Exception as e: err_msg = "error before starting node" printException(getCallerName(), getFunctionName(), err_msg, e)
def onStartMN(self, data=None): # Check RPC & HW device if not self.caller.rpcConnected or self.caller.hwStatus != 2: myPopUp_sb(self.caller, "crit", 'SPMT - hw/rpc device check', "Connect to RPC server and HW device first") printDbg("Hardware device or RPC server not connected") return None try: if not data: target = self.ui.sender() masternode_alias = target.alias printOK("Start-masternode %s pressed" % masternode_alias) for mn_conf in self.caller.masternode_list: if mn_conf['name'] == masternode_alias: reply = myPopUp( self.caller, QMessageBox.Question, 'Confirm START', "Are you sure you want to start masternoode:\n'%s'?" % mn_conf['name'], QMessageBox.Yes) if reply == QMessageBox.Yes: self.masternodeToStart = Masternode( self, mn_conf['name'], mn_conf['ip'], mn_conf['port'], mn_conf['mnPrivKey'], mn_conf['hwAcc'], mn_conf['collateral'], mn_conf['isTestnet']) # connect signal self.masternodeToStart.sigdone.connect( self.sendBroadcast) self.mnToStartList.append(self.masternodeToStart) self.startMN() break except Exception as e: err_msg = "error before starting node" printException(getCallerName(), getFunctionName(), err_msg, e)
def findSpath_done(self): currAddr = self.ui.edt_address.text().strip() currHwAcc = self.ui.edt_hwAccount.value() spath = self.spath starting_spath = self.curr_starting_spath spath_count = self.curr_spath_count if self.spath_found: printOK("spath is %d" % spath) mess = "Found address %s in HW account %s with spath_id %s" % ( currAddr, currHwAcc, spath) myPopUp_sb(self.caller, "info", 'SPMT - spath search', mess) self.ui.edt_spath.setValue(spath) self.findPubKey() else: mess = "Scanned addresses <b>%d</b> to <b>%d</b> of HW account <b>%d</b>.<br>" % ( starting_spath, starting_spath + spath_count - 1, currHwAcc) mess += "Unable to find the address <i>%s</i>.<br>Maybe it's on a different account.<br><br>" % currAddr mess += "Do you want to scan %d more addresses of account n.<b>%d</b> ?" % ( spath_count, currHwAcc) ans = myPopUp(self.caller, "crit", 'SPMT - spath search', mess) if ans == QMessageBox.Yes: starting_spath += spath_count self.runInThread(self.findSpath, (starting_spath, spath_count), self.findSpath_done)
def onSign(self): # check message if self.ui.messageTextEdt.document().isEmpty(): mess = "Nothing to sign. Insert message." myPopUp_sb(self.main_wnd, QMessageBox.Warning, 'PET4L - no message', 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, 'PET4L - hw check', mess) if ans == QMessageBox.No: return # re connect self.main_wnd.onCheckHw() # sign message on HW device serializedData = str(self.ui.messageTextEdt.toPlainText()) device = self.main_wnd.hwdevice try: device.sig1done.disconnect() except: pass device.sig1done.connect(self.displaySignature) try: device.signMess(self.main_wnd, self.currHwPath, serializedData, self.currIsTestnet) # wait for signal when device.sig1 is ready then --> displaySignature except Exception as e: err_msg = "error during signature" printException(getCallerName(), getFunctionName(), err_msg, e.args) except KeyboardInterrupt: err_msg = "Keyboard Interrupt" printException(getCallerName(), getFunctionName(), err_msg, '')
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 sendBroadcast(self, text): if text == "None": self.sendBroadcastCheck() return printOK("Start Message: %s" % text) ret = self.caller.rpcClient.decodemasternodebroadcast(text) if ret is None: myPopUp_sb(self.caller, "crit", 'message decoding failed', 'message decoding failed') self.sendBroadcastCheck() return msg = "Broadcast START message?\n" + json.dumps(ret, indent=4, sort_keys=True) reply = myPopUp(self.caller, "quest", 'message decoded', msg, QMessageBox.Yes) if reply == QMessageBox.No: self.sendBroadcastCheck() return ret2 = self.caller.rpcClient.relaymasternodebroadcast(text) if json.dumps(ret2)[1:26] == "Masternode broadcast sent": message = "Start-message was successfully sent to the network.<br>" message += "If your remote server is correctly configured and connected to the network, " message += "the output of the <b>./pivx-cli masternode status</b> command on the VPS should show:<br>" message += "<br><em>\"message\": \"Masternode successfully started\"</em>" myPopUp_sb(self.caller, "info", 'message relayed', message) else: print(json.dumps(ret2)[1:26]) print("\n") self.sendBroadcastCheck()
def onRemoveServer(self, index): mess = "Are you sure you want to remove server with index %d (%s) from list?" % ( index, self.main_wnd.mainWindow.rpcServersList[index].get('host')) ans = myPopUp(self, QMessageBox.Question, 'SPMT - remove server', mess) if ans == QMessageBox.Yes: # Remove entry from database id = self.main_wnd.mainWindow.rpcServersList[index].get('id') self.main_wnd.db.removeRPCServer(id)
def onGenerateMNkey(self): printDbg("Generate MNkey pressed") reply = QMessageBox.Yes if self.ui.edt_mnPrivKey.text() != "": reply = myPopUp(self.caller, "warn", "GENERATE PRIV KEY", "Are you sure?\nThis will overwrite current private key", QMessageBox.No) if reply == QMessageBox.No: return newkey = generate_privkey(self.isTestnet()) self.ui.edt_mnPrivKey.setText(newkey)
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 onRemoveMN(self, data=None): if not data: target = self.ui.sender() masternode_alias = target.alias reply = myPopUp(self.caller, "warn", 'Confirm REMOVE', "Are you sure you want to remove\nmasternoode:'%s'" % masternode_alias, QMessageBox.No) if reply == QMessageBox.No: return for masternode in self.caller.masternode_list: if masternode['name'] == masternode_alias: # remove from cache, QListWidget and DB removeMNfromList(self.caller, masternode) break
def onButtonSend(self): t_rewards = self.main_tab.caller.t_rewards t_rewards.dest_addr = self.ui.edt_destination.text().strip() t_rewards.currFee = self.ui.feeLine.value() * 1e8 # Check HW device while self.main_tab.caller.hwStatus != 2: mess = "HW device not connected. Try to connect?" ans = myPopUp(self.main_tab.caller, QMessageBox.Question, 'SPMT - hw check', mess) if ans == QMessageBox.No: return # re connect self.main_tab.caller.onCheckHw() # disable buttons (re-enabled in AbortSend) self.ui.buttonSend.setEnabled(False) self.ui.buttonCancel.setEnabled(False) # SEND t_rewards.SendRewards(self.useSwiftX(), self.rewardsArray, self)
def onSendRewards(self): self.dest_addr = self.ui.destinationLine.text().strip() self.currFee = self.ui.feeLine.value() * 1e8 # Check HW device while self.caller.hwStatus != 2: mess = "HW device not connected. Try to connect?" ans = myPopUp(self.caller, QMessageBox.Question, 'PET4L - hw check', mess) if ans == QMessageBox.No: return # re connect self.caller.onCheckHw() if self.caller.hwStatus != 2: myPopUp_sb(self.caller, "crit", 'PET4L - hw device check', "Connect to HW device first") printDbg("Unable to connect to hardware device. The device status is: %d" % self.caller.hwStatus) return None # SEND self.SendRewards()
def onSendRewards(self): self.dest_addr = self.ui.destinationLine.text().strip() # Check HW device if self.caller.hwStatus != 2: myPopUp_sb(self.caller, "crit", 'SPMT - hw device check', "Connect to HW device first") printDbg("Unable to connect to hardware device. The device status is: %d" % self.caller.hwStatus) return None # Check destination Address if not checkPivxAddr(self.dest_addr, self.caller.isTestnetRPC): myPopUp_sb(self.caller, "crit", 'SPMT - PIVX address check', "The destination address is missing, or invalid.") return None # Check spending collateral if (not self.ui.collateralHidden and self.ui.rewardsList.box.collateralRow is not None and self.ui.rewardsList.box.item(self.ui.rewardsList.box.collateralRow, 0).isSelected() ): warning1 = "Are you sure you want to transfer the collateral?" warning2 = "Really?" warning3 = "Take a deep breath. Do you REALLY want to transfer your collateral?" ans = myPopUp(self.caller, "warn", 'SPMT - warning', warning1) if ans == QMessageBox.No: return None else: ans2 = myPopUp(self.caller, "warn", 'SPMT - warning', warning2) if ans2 == QMessageBox.No: return None else: ans2 = myPopUp(self.caller, "crit", 'SPMT - warning', warning3) if ans2 == QMessageBox.No: return None # LET'S GO if self.selectedRewards: printDbg("Sending from PIVX address %s to PIVX address %s " % (self.curr_addr, self.dest_addr)) printDbg("Preparing transaction. Please wait...") self.ui.loadingLine.show() self.ui.loadingLinePercent.show() QApplication.processEvents() # save last destination address and swiftxCheck to cache and persist to settings self.caller.parent.cache["lastAddress"] = persistCacheSetting('cache_lastAddress', self.dest_addr) self.caller.parent.cache["useSwiftX"] = persistCacheSetting('cache_useSwiftX', self.useSwiftX()) self.currFee = self.ui.feeLine.value() * 1e8 # re-connect signals try: self.caller.hwdevice.api.sigTxdone.disconnect() except: pass try: self.caller.hwdevice.api.sigTxabort.disconnect() except: pass try: self.caller.hwdevice.api.tx_progress.disconnect() except: pass self.caller.hwdevice.api.sigTxdone.connect(self.FinishSend) self.caller.hwdevice.api.sigTxabort.connect(self.AbortSend) self.caller.hwdevice.api.tx_progress.connect(self.updateProgressPercent) try: self.txFinished = False self.caller.hwdevice.prepare_transfer_tx(self.caller, self.curr_hwpath, self.selectedRewards, self.dest_addr, self.currFee, self.useSwiftX(), self.caller.isTestnetRPC) except DisconnectedException as e: self.caller.hwStatus = 0 self.caller.updateHWleds() except Exception as e: err_msg = "Error while preparing transaction. <br>" err_msg += "Probably Blockchain wasn't synced when trying to fetch raw TXs.<br>" err_msg += "<b>Wait for full synchronization</b> then hit 'Clear/Reload'" printException(getCallerName(), getFunctionName(), err_msg, e.args) else: myPopUp_sb(self.caller, "warn", 'Transaction NOT sent', "No UTXO to send")