def loadSelection_thread(self, ctrl): hwAcc = self.ui.edt_hwAccount.value() spathFrom = self.ui.edt_spathFrom.value() spathTo = self.ui.edt_spathTo.value() intExt = self.ui.edt_internalExternal.value() isTestnet = self.caller.isTestnetRPC # Save settings self.caller.parent.cache["hwAcc"] = persistCacheSetting( 'cache_hwAcc', hwAcc) self.caller.parent.cache["spathFrom"] = persistCacheSetting( 'cache_spathFrom', spathFrom) self.caller.parent.cache["spathTo"] = persistCacheSetting( 'cache_spathTo', spathTo) self.caller.parent.cache["intExt"] = persistCacheSetting( 'cache_intExt', intExt) for i in range(spathFrom, spathTo + 1): path = "%d'/%d/%d" % (hwAcc, intExt, i) address = self.caller.hwdevice.scanForAddress( hwAcc, i, intExt, isTestnet) try: balance = self.caller.apiClient.getBalance(address) except Exception as e: print(e) balance = 0 itemLine = "%s -- %s" % (path, address) if (balance): itemLine += " [%s PIV]" % str(balance) self.ui.addySelect.addItem(itemLine, [path, address, balance])
def onButtonSend(self): try: self.dest_addr = self.ui.edt_destination.text().strip() self.currFee = self.ui.feeLine.value() * 1e8 # Check RPC & dongle if not self.main_tab.caller.rpcConnected or self.main_tab.caller.hwStatus != 2: myPopUp_sb(self.main_tab.caller, "crit", 'SPMT - hw/rpc device check', "Connect to RPC server and HW device first") return None # Check destination Address if not checkPivxAddr(self.dest_addr): myPopUp_sb(self.main_tab.caller, "crit", 'SPMT - PIVX address check', "The destination address is missing, or invalid.") return None # LET'S GO if len(self.rewardsArray) > 0: 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.main_tab.caller.parent.cache["lastAddress"] = persistCacheSetting('cache_lastAddress', self.dest_addr) self.main_tab.caller.parent.cache["useSwiftX"] = persistCacheSetting('cache_useSwiftX', self.useSwiftX()) # re-connect signals try: self.main_tab.caller.hwdevice.sigTxdone.disconnect() except: pass try: self.main_tab.caller.hwdevice.sigTxabort.disconnect() except: pass try: self.main_tab.caller.hwdevice.tx_progress.disconnect() except: pass self.main_tab.caller.hwdevice.sigTxdone.connect(self.FinishSend) self.main_tab.caller.hwdevice.sigTxabort.connect(self.AbortSend) self.main_tab.caller.hwdevice.tx_progress.connect(self.updateProgressPercent) self.txFinished = False self.main_tab.caller.hwdevice.prepare_transfer_tx_bulk(self.main_tab.caller, self.rewardsArray, self.dest_addr, self.currFee, self.useSwiftX()) else: myPopUp_sb(self.main_tab.caller, "warn", 'Transaction NOT sent', "No UTXO to send") except DisconnectedException as e: self.main_tab.caller.hwStatus = 0 self.main_tab.caller.updateHWleds() self.onButtonCancel() except Exception as e: err_msg = "Exception in onButtonSend" printException(getCallerName(), getFunctionName(), err_msg, e)
def loadProposals_thread(self, ctrl): if not self.caller.rpcConnected: printException(getCallerName(), getFunctionName(), "RPC server not connected", "") return # clear proposals DB printDbg("Updating proposals...") self.caller.parent.db.clearTable('PROPOSALS') self.proposalsLoaded = False proposals = self.caller.rpcClient.getProposals() for p in proposals: self.caller.parent.db.addProposal(p) num_of_masternodes = self.caller.rpcClient.getMasternodeCount() if num_of_masternodes is None: printDbg("Total number of masternodes not available. Background coloring not accurate") mnCount = 1 else: mnCount = num_of_masternodes.get("total") # persist masternode number self.caller.parent.cache['MN_count'] = persistCacheSetting('cache_MNcount', mnCount) self.updateMyVotes() printDbg("--# PROPOSALS table updated") self.proposalsLoaded = True self.caller.sig_ProposalsLoaded.emit()
def onChangeSelectedHW(self, i): # Clear status self.clearHWstatus() # Persist setting self.parent.cache['selectedHW_index'] = persistCacheSetting( 'cache_HWindex', i)
def updateRPClist(self): # Clear old stuff self.updatingRPCbox = True self.header.rpcClientsBox.clear() public_servers = self.parent.db.getRPCServers(custom=False) custom_servers = self.parent.db.getRPCServers(custom=True) self.rpcServersList = public_servers + custom_servers # Add public servers (italics) italicsFont = QFont("Times", italic=True) for s in public_servers: url = s["protocol"] + "://" + s["host"].split(':')[0] self.header.rpcClientsBox.addItem(url, s) self.header.rpcClientsBox.setItemData(self.getServerListIndex(s), italicsFont, Qt.FontRole) # Add Local Wallet (bold) boldFont = QFont("Times") boldFont.setBold(True) self.header.rpcClientsBox.addItem("Local Wallet", custom_servers[0]) self.header.rpcClientsBox.setItemData( self.getServerListIndex(custom_servers[0]), boldFont, Qt.FontRole) # Add custom servers for s in custom_servers[1:]: url = s["protocol"] + "://" + s["host"].split(':')[0] self.header.rpcClientsBox.addItem(url, s) # reset index if self.parent.cache[ 'selectedRPC_index'] >= self.header.rpcClientsBox.count(): # (if manually removed from the config files) replace default index self.parent.cache['selectedRPC_index'] = persistCacheSetting( 'cache_RPCindex', DefaultCache["selectedRPC_index"]) self.header.rpcClientsBox.setCurrentIndex( self.parent.cache['selectedRPC_index']) self.updatingRPCbox = False # reload servers in configure dialog self.sig_RPClistReloaded.emit()
def onOK(self): self.main_wnd.votingMasternodes = self.getSelection() self.main_wnd.updateSelectedMNlabel() # persist voting masternodes to cache self.main_wnd.caller.parent.cache[ 'votingMasternodes'] = persistCacheSetting( 'cache_votingMNs', self.main_wnd.votingMasternodes) self.accept()
def onChangeSelectedRPC(self, i): # Don't update when we are clearing the box if not self.updatingRPCbox: # persist setting self.parent.cache['selectedRPC_index'] = persistCacheSetting( 'cache_RPCindex', i) self.runInThread( self.updateRPCstatus, (True, ), )
def saveMNListOrder(self): # Update mnList order to cache settings and sort mnOrder = {} mnList = self.tabMain.myList for i in range(mnList.count()): mnName = mnList.itemWidget(mnList.item(i)).alias mnOrder[mnName] = i self.parent.cache['mnList_order'] = persistCacheSetting( 'cache_mnOrder', mnOrder) self.masternode_list.sort(key=self.parent.extract_order) # reload MnSelect in tabRewards self.t_rewards.loadMnSelect()
def updateRPCstatus(self, ctrl, fDebug=False): self.sig_clearRPCstatus.emit() self.rpcClient = None rpc_index, rpc_protocol, rpc_host, rpc_user, rpc_password = self.getRPCserver( ) if fDebug: printDbg("Trying to connect to RPC %s://%s..." % (rpc_protocol, rpc_host)) try: rpcClient = RpcClient(rpc_protocol, rpc_host, rpc_user, rpc_password) except Exception as e: printException(getCallerName(), getFunctionName(), "exception in updateRPCstatus", str(e)) return try: status, statusMess, lastBlock, r_time1, isTestnet = rpcClient.getStatus( ) isBlockchainSynced, r_time2 = rpcClient.isBlockchainSynced() except Exception as e: return rpcResponseTime = None if r_time1 is not None and r_time2 != 0: rpcResponseTime = round((r_time1 + r_time2) / 2, 3) # Update status and client only if selected server is not changed if rpc_index != self.header.rpcClientsBox.currentIndex(): return with self.lock: self.rpcClient = rpcClient self.rpcConnected = status self.rpcLastBlock = lastBlock self.rpcStatusMess = statusMess self.isBlockchainSynced = isBlockchainSynced self.rpcResponseTime = rpcResponseTime # if testnet flag is changed, update api client and persist setting if isTestnet != self.isTestnetRPC: self.isTestnetRPC = isTestnet self.parent.cache['isTestnetRPC'] = persistCacheSetting( 'isTestnetRPC', isTestnet) self.apiClient = ApiClient(isTestnet) self.sig_RPCstatusUpdated.emit(rpc_index, fDebug)
def clear(self): # Clear voting masternodes and update cache self.votingMasternodes = [] self.caller.parent.cache['votingMasternodes'] = persistCacheSetting('cache_votingMNs', self.votingMasternodes)
def vote_thread(self, ctrl, vote_code): # vote_code index for ["yes", "abstain", "no"] if not isinstance(vote_code, int) or vote_code not in range(3): raise Exception("Wrong vote_code %s" % str(vote_code)) self.successVotes = 0 self.failedVotes = 0 self.currHeight = self.caller.rpcClient.getBlockCount() # save delay check data to cache and persist settings self.caller.parent.cache["votingDelayCheck"] = persistCacheSetting('cache_vdCheck', self.ui.randomDelayCheck.isChecked()) self.caller.parent.cache["votingDelayNeg"] = persistCacheSetting('cache_vdNeg', self.ui.randomDelayNeg_edt.value()) self.caller.parent.cache["votingDelayPos"] = persistCacheSetting('cache_vdPos', self.ui.randomDelayPos_edt.value()) for prop in self.selectedProposals: for mn in self.votingMasternodes: vote_sig = '' serialize_for_sig = '' sig_time = int(time.time()) try: # Get mnPrivKey currNode = next(x for x in self.caller.masternode_list if x['name']==mn[1]) if currNode is None: printDbg("currNode not found for current voting masternode %s" % mn[1]) self.clear() raise Exception() mnPrivKey = currNode['mnPrivKey'] self.isTestnet = currNode['isTestnet'] # Add random delay offset if self.ui.randomDelayCheck.isChecked(): minuns_max = int(self.ui.randomDelayNeg_edt.value()) plus_max = int(self.ui.randomDelayPos_edt.value()) delay_secs = random.randint(-minuns_max, plus_max) sig_time += delay_secs # Print Debug line to console mess = "Processing '%s' vote on behalf of masternode [%s]" % (self.vote_codes[vote_code], mn[1]) mess += " for the proposal {%s}" % prop.name if self.ui.randomDelayCheck.isChecked(): mess += " with offset of %d seconds" % delay_secs printDbg(mess) # Serialize and sign vote fNewSigs = NewSigsActive(self.currHeight, self.isTestnet) serialize_for_sig = self.getBudgetVoteMess(fNewSigs, mn[0][:64], currNode['collateral']['txidn'], prop.Hash, vote_code, sig_time) if fNewSigs: vote_sig = ecdsa_sign_bin(serialize_for_sig, mnPrivKey) else: vote_sig = ecdsa_sign(serialize_for_sig, mnPrivKey) # Broadcast the vote v_res = self.caller.rpcClient.mnBudgetRawVote( mn_tx_hash=currNode['collateral'].get('txid'), mn_tx_index=int(currNode['collateral'].get('txidn')), proposal_hash=prop.Hash, vote=self.vote_codes[vote_code], time=sig_time, vote_sig=vote_sig) printOK(v_res) if v_res == 'Voted successfully': self.successVotes += 1 else: self.failedVotes += 1 except Exception as e: err_msg = "Exception in vote_thread - check MN privKey" printException(getCallerName(), getFunctionName(), err_msg, e.args)
def SendRewards(self, useSwiftX, inputs=None, gui=None): # Default slots on tabRewards if gui is None: gui = self # 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(gui.FinishSend) self.caller.hwdevice.api.sigTxabort.connect(gui.AbortSend) self.caller.hwdevice.api.tx_progress.connect(gui.updateProgressPercent) # 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 if inputs is None: # send from single path num_of_inputs = len(self.selectedRewards) else: # bulk send num_of_inputs = sum([len(x['utxos']) for x in inputs]) ans = checkTxInputs(self.caller, num_of_inputs) if ans is None or ans == QMessageBox.No: # emit sigTxAbort and return self.caller.hwdevice.api.sigTxabort.emit() return None # LET'S GO if inputs is None: printDbg("Sending from PIVX address %s to PIVX address %s " % (self.curr_addr, self.dest_addr)) else: printDbg("Sweeping rewards to PIVX address %s " % 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', useSwiftX) try: self.txFinished = False if inputs is None: # send from single path self.caller.hwdevice.prepare_transfer_tx(self.caller, self.curr_hwpath, self.selectedRewards, self.dest_addr, self.currFee, useSwiftX, self.caller.isTestnetRPC) else: # bulk send self.caller.hwdevice.prepare_transfer_tx_bulk(self.caller, inputs, self.dest_addr, self.currFee, 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)
def onSendRewards(self): self.dest_addr = self.ui.destinationLine.text().strip() # Check HW device 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 # Check destination Address if not checkPivxAddr(self.dest_addr, self.caller.isTestnetRPC): myPopUp_sb(self.caller, "crit", 'PET4L - PIVX address check', "The destination address is missing, or invalid.") 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...") try: self.ui.loadingLine.show() self.ui.loadingLinePercent.show() QApplication.processEvents() self.currFee = self.ui.feeLine.value() * 1e8 # 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_path, 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) except Exception as e: print(e) else: myPopUp_sb(self.caller, "warn", 'Transaction NOT sent', "No UTXO to send")
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")