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 load_utxos_thread(self, ctrl): with self.Lock: # clear rewards DB printDbg("Updating rewards...") self.caller.parent.db.clearTable('REWARDS') self.caller.parent.db.clearTable('MY_VOTES') self.utxoLoaded = False # If rpc is not connected and hw device is Ledger, warn and return. if not self.caller.rpcConnected and self.caller.hwModel == 0: printError(getCallerName(), getFunctionName(), 'PIVX daemon not connected - Unable to update UTXO list') return total_num_of_utxos = 0 mn_rewards = {} for mn in self.caller.masternode_list: # Load UTXOs from API client rewards = self.caller.apiClient.getAddressUtxos(mn['collateral'].get('address')) if rewards is None: printError(getCallerName(), getFunctionName(), 'API client not responding.') return mn_rewards[mn['name']] = rewards total_num_of_utxos += len(rewards) printDbg("Number of UTXOs to load: %d" % total_num_of_utxos) curr_utxo = 0 percent = 0 for mn in mn_rewards: # for each UTXO for utxo in mn_rewards[mn]: rawtx = None percent = int(100*curr_utxo / total_num_of_utxos) # get raw TX from RPC client (only for ledger / trezor has own api) if self.caller.hwModel == 0: rawtx = self.caller.rpcClient.getRawTransaction(utxo['txid']) else: rawtx = "" # Don't save UTXO if raw TX is unavailable if rawtx is None: printError(getCallerName(), getFunctionName(), "Unable to get raw TX with hash=%s from RPC server" % utxo['txid']) continue # Add mn_name and raw_tx to UTXO and save it to DB else: utxo['mn_name'] = mn utxo['raw_tx'] = rawtx self.caller.parent.db.addReward(utxo) # emit percent self.caller.sig_UTXOsLoading.emit(percent) curr_utxo += 1 self.caller.sig_UTXOsLoading.emit(100) printDbg("--# REWARDS table updated") self.utxoLoaded = True self.caller.sig_UTXOsLoaded.emit()
def sendRawTransaction(self, tx_hex): try: tx_id = self.conn.sendrawtransaction(tx_hex) return tx_id except Exception as e: err_msg = 'error in rpcClient.sendRawTransaction' if str(e.args[0]) != "Request-sent": printException(getCallerName(), getFunctionName(), err_msg, e.args) else: printException(getCallerName(), getFunctionName(), err_msg, e.args)
def getAddressUtxos(self, addresses): try: return self.conn.getaddressutxos({'addresses': addresses}) except Exception as e: err_msg = "error in getAddressUtxos" if str(e.args[0]) != "Request-sent": printException(getCallerName(), getFunctionName(), err_msg, e.args) else: printException(getCallerName(), getFunctionName(), err_msg, e.args) raise e
def getBlockCount(self): try: n = self.conn.getblockcount() return n except Exception as e: err_msg = 'remote or local PIVX-cli running?' if str(e.args[0]) != "Request-sent": printException(getCallerName(), getFunctionName(), err_msg, e.args) else: printException(getCallerName(), getFunctionName(), err_msg, e.args)
def getBlockHash(self, blockNum): try: h = self.conn.getblockhash(blockNum) return h except Exception as e: err_msg = 'remote or local PIVX-cli running?' if str(e.args[0]) != "Request-sent": printException(getCallerName(), getFunctionName(), err_msg, e.args) else: printException(getCallerName(), getFunctionName(), err_msg, e.args)
def FinishSend(self, serialized_tx, amount_to_send): self.AbortSend() if not self.txFinished: try: self.txFinished = True tx_hex = serialized_tx.hex() printDbg("Raw signed transaction: " + tx_hex) printDbg("Amount to send :" + amount_to_send) if len(tx_hex) > 90000: mess = "Transaction's length exceeds 90000 bytes. Select less UTXOs and try again." myPopUp_sb(self.main_tab.caller, "crit", 'transaction Warning', mess) else: decodedTx = None try: decodedTx = ParseTx(tx_hex, self.main_tab.caller.isTestnetRPC) destination = decodedTx.get("vout")[0].get("scriptPubKey").get("addresses")[0] amount = decodedTx.get("vout")[0].get("value") message = '<p>Broadcast signed transaction?</p><p>Destination address:<br><b>%s</b></p>' % destination message += '<p>Amount: <b>%s</b> PIV<br>' % str(round(amount / 1e8, 8)) message += 'Fees: <b>%s</b> PIV <br>Size: <b>%d</b> Bytes</p>' % (str(round(self.currFee / 1e8, 8) ), len(tx_hex)/2) except Exception as e: printException(getCallerName(), getFunctionName(), "decoding exception", str(e)) message = '<p>Unable to decode TX- Broadcast anyway?</p>' mess1 = QMessageBox(QMessageBox.Information, 'Send transaction', message) if decodedTx is not None: mess1.setDetailedText(json.dumps(decodedTx, indent=4, sort_keys=False)) mess1.setStandardButtons(QMessageBox.Yes | QMessageBox.No) reply = mess1.exec_() if reply == QMessageBox.Yes: txid = self.main_tab.caller.rpcClient.sendRawTransaction(tx_hex, self.useSwiftX()) if txid is None: raise Exception("Unable to send TX - connection to RPC server lost.") mess2_text = "<p>Transaction successfully sent.</p>" mess2 = QMessageBox(QMessageBox.Information, 'transaction Sent', mess2_text) mess2.setDetailedText(txid) mess2.exec_() # remove spent rewards (All of them except for collaterals) self.removeSpentRewards() # reload utxos self.main_tab.caller.t_rewards.display_mn_utxos() self.main_tab.caller.t_rewards.onCancel() else: myPopUp_sb(self.main_tab.caller, "warn", 'Transaction NOT sent', "Transaction NOT sent") except Exception as e: err_msg = "Exception in FinishSend" printException(getCallerName(), getFunctionName(), err_msg, e) finally: self.close()
def getFeePerKb(self): try: # get transaction data from last 10 blocks feePerKb = float(self.conn.getfeeinfo(10)['feeperkb']) return (feePerKb if feePerKb > MINIMUM_FEE else MINIMUM_FEE) except Exception as e: err_msg = 'error in getFeePerKb' if str(e.args[0]) != "Request-sent": printException(getCallerName(), getFunctionName(), err_msg, e.args) else: printException(getCallerName(), getFunctionName(), err_msg, e.args)
def load_utxos_thread(self, ctrl): with self.Lock: # clear rewards DB printDbg("Updating rewards...") self.caller.parent.db.clearTable('REWARDS') self.caller.parent.db.clearTable('MY_VOTES') # If rpc is not connected and hw device is Ledger, warn and return. if not self.caller.rpcConnected and self.caller.hwModel == 0: printError(getCallerName(), getFunctionName(), 'PIVX daemon not connected - Unable to update UTXO list') return total_num_of_utxos = 0 mn_rewards = {} for mn in self.caller.masternode_list: # Load UTXOs from API client rewards = self.caller.apiClient.getAddressUtxos(mn['collateral'].get('address')) if rewards is None: printError(getCallerName(), getFunctionName(), 'API client not responding.') return mn_rewards[mn['name']] = rewards total_num_of_utxos += len(rewards) printDbg("Number of UTXOs to load: %d" % total_num_of_utxos) curr_utxo = 0 for mn in mn_rewards: for utxo in mn_rewards[mn]: # Add mn_name to UTXO utxo['mn_name'] = mn # Get raw tx rawtx = TxCache(self.caller)[utxo['txid']] if rawtx is None: printDbg("Unable to get raw TX with hash=%s from RPC server." % utxo['txid']) # Don't save UTXO if raw TX is unavailable mn_rewards[mn].remove(utxo) continue utxo['raw_tx'] = rawtx utxo['staker'] = "" p2cs, utxo['coinstake'] = IsPayToColdStaking(rawtx, utxo['vout']) if p2cs: utxo['staker'] = GetDelegatedStaker(rawtx, utxo['vout'], self.caller.isTestnetRPC) # Add utxo to database self.caller.parent.db.addReward(utxo) # emit percent percent = int(100 * curr_utxo / total_num_of_utxos) self.caller.sig_UTXOsLoading.emit(percent) curr_utxo += 1 printDbg("--# REWARDS table updated") self.caller.sig_UTXOsLoading.emit(100)
def __init__(self): self.rpc_ip, self.rpc_port, self.rpc_user, self.rpc_passwd = readRPCfile() rpc_url = "http://%s:%s@%s:%d" % (self.rpc_user, self.rpc_passwd, self.rpc_ip, self.rpc_port) try: self.conn = AuthServiceProxy(rpc_url, timeout=8) except JSONRPCException as e: err_msg = 'remote or local PIVX-cli running?' printException(getCallerName(), getFunctionName(), err_msg, e) except Exception as e: err_msg = 'remote or local PIVX-cli running?' printException(getCallerName(), getFunctionName(), err_msg, e)
def getMNStatus(self, address): try: mnStatusList = self.conn.listmasternodes(address) if not mnStatusList: return None mnStatus = mnStatusList[0] mnStatus['mnCount'] = self.conn.getmasternodecount()['enabled'] return mnStatus except Exception as e: err_msg = "error in getMNStatus" if str(e.args[0]) != "Request-sent": printException(getCallerName(), getFunctionName(), err_msg, e.args) else: printException(getCallerName(), getFunctionName(), err_msg, e.args)
def process_api_exceptions_int(*args, **kwargs): client = args[0] try: return func(*args, **kwargs) except Exception as e: message = "Primary API source not responding. Trying secondary" printException(getCallerName(True), getFunctionName(True), message, str(e)) try: client.api = CryptoIDClient(client.isTestnet) return func(*args, **kwargs) except Exception as e: printError(getCallerName(True), getFunctionName(True), str(e)) return None
def onSendRewards(self): self.dest_addr = self.ui.destinationLine.text().strip() # 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 # Check destination Address if not checkPivxAddr(self.dest_addr): self.caller.myPopUp2(QMessageBox.Critical, 'PET4L - PIVX address check', "Invalid Destination Address") return None # LET'S GO printDbg("Sending from PIVX address %s to PIVX address %s " % (self.curr_addr, self.dest_addr)) if self.selectedRewards: self.currFee = self.ui.feeLine.value() * 1e8 # connect signal self.caller.hwdevice.sigTxdone.connect(self.FinishSend) try: self.txFinished = False self.caller.hwdevice.prepare_transfer_tx(self.caller, self.curr_path, self.selectedRewards, self.dest_addr, self.currFee, self.rawtransactions) except Exception as e: err_msg = "Error while preparing transaction" printException(getCallerName(), getFunctionName(), err_msg, e.args) else: self.caller.myPopUp2(QMessageBox.Information, 'transaction NOT Sent', "No UTXO to send")
def onStartMN(self, data=None): # Check RPC & dongle if not self.caller.rpcConnected or self.caller.hwStatus != 2: self.caller.myPopUp2(QMessageBox.Critical, '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 = self.caller.myPopUp( 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']) # 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 initTables(self): printDbg("DB: Initializing tables...") try: cursor = self.conn.cursor() # Tables for RPC Servers cursor.execute("CREATE TABLE IF NOT EXISTS PUBLIC_RPC_SERVERS(" " id INTEGER PRIMARY KEY, protocol TEXT, host TEXT," " user TEXT, pass TEXT)") cursor.execute("CREATE TABLE IF NOT EXISTS CUSTOM_RPC_SERVERS(" " id INTEGER PRIMARY KEY, protocol TEXT, host TEXT," " user TEXT, pass TEXT)") self.initTable_RPC(cursor) # Tables for Utxos cursor.execute( "CREATE TABLE IF NOT EXISTS UTXOS(" " tx_hash TEXT, tx_ouput_n INTEGER, satoshis INTEGER, confirmations INTEGER," " script TEXT, raw_tx TEXT, receiver TEXT, staker TEXT, coinstake BOOLEAN," " PRIMARY KEY (tx_hash, tx_ouput_n))") printDbg("DB: Tables initialized") except Exception as e: err_msg = 'error initializing tables' printException(getCallerName(), getFunctionName(), err_msg, e.args)
def onStartAllMN(self): printOK("Start-All pressed") # Check RPC & dongle if not self.caller.rpcConnected: self.caller.myPopUp2(QMessageBox.Critical, 'QMT - hw/rpc device check', "Connect to RPC server and HW device first") printDbg("Hardware device or RPC server not connected") return None try: reply = self.caller.myPopUp( QMessageBox.Question, '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']) # 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 process_cryptoID_exceptions_int(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: message = "CryptoID Client exception" printException(getCallerName(True), getFunctionName(True), message, str(e)) return None
def onToggleCollateral(self): if (self.rewards is not None): if len(self.rewards ) and self.ui.rewardsList.box.collateralRow is not None: if not self.ui.collateralHidden: try: if self.ui.rewardsList.box.item( self.ui.rewardsList.box.collateralRow, 0).isSelected(): self.ui.rewardsList.box.selectRow( self.ui.rewardsList.box.collateralRow) except Exception as e: err_msg = "Error while preparing transaction" printException(getCallerName(), getFunctionName(), err_msg, e.args) self.ui.rewardsList.box.hideRow( self.ui.rewardsList.box.collateralRow) self.ui.btn_toggleCollateral.setText("Show Collateral") self.ui.collateralHidden = True self.updateSelection() else: self.ui.rewardsList.box.showRow( self.ui.rewardsList.box.collateralRow) self.ui.btn_toggleCollateral.setText("Hide Collateral") self.ui.collateralHidden = False self.updateSelection() self.ui.rewardsList.box.resizeColumnsToContents() self.ui.rewardsList.box.horizontalHeader( ).setSectionResizeMode(2, QHeaderView.Stretch) else: self.caller.myPopUp2(QMessageBox.Information, 'No Collateral', "No collateral selected")
def getStatus(self): status = False statusMess = "Unable to connect to a PIVX RPC server.\n" statusMess += "Either the local PIVX wallet is not open, or the remote RPC server is not responding." n = 0 try: self.lock.acquire() n = self.conn.getblockcount() if n > 0: status = True statusMess = "Connected to PIVX RPC client" except Exception as e: # If loading block index set lastBlock=1 if str(e.args[0]) == "Loading block index..." or str( e.args[0]) == "Verifying blocks...": printDbg(str(e.args[0])) statusMess = "PIVX wallet is connected but still synchronizing / verifying blocks" n = 1 elif str(e.args[0]) != "Request-sent" and str( e.args[0]) != "10061": err_msg = "Error while contacting RPC server" printException(getCallerName(), getFunctionName(), err_msg, e.args) finally: self.lock.release() return status, statusMess, n
def FinishSend(self, serialized_tx, amount_to_send): if not self.txFinished: try: self.txFinished = True tx_hex = serialized_tx.hex() printDbg("Raw signed transaction: " + tx_hex) printDbg("Amount to send :" + amount_to_send) if len(tx_hex) > 90000: mess = "Transaction's length exceeds 90000 bytes. Select less UTXOs and try again." self.caller.myPopUp2(QMessageBox.Warning, 'transaction Warning', mess) else: message = 'Broadcast signed transaction?<br><br>Destination address:<br><b>%s</b><br><br>' % (self.dest_addr) message += 'Amount to send: <b>%s PIV</b><br>' % amount_to_send message += 'Fee: <b>%s PIV</b><br>Size: <b>%d bytes</b>' % (str(round(self.currFee / 1e8, 8) ), len(tx_hex)/2) reply = self.caller.myPopUp(QMessageBox.Information, 'Send transaction', message) if reply == QMessageBox.Yes: txid = self.caller.rpcClient.sendRawTransaction(tx_hex) mess = QMessageBox(QMessageBox.Information, 'transaction Sent', 'transaction Sent') mess.setDetailedText(txid) mess.exec_() else: self.caller.myPopUp2(QMessageBox.Information, 'transaction NOT Sent', "transaction NOT sent") self.onCancel() except Exception as e: err_msg = "Exception in sendRewards" printException(getCallerName(), getFunctionName(), err_msg, e.args)
def addMasternode(self, mn, old_mn=None): add_defaultKeys_to_dict(mn, DEFAULT_MN_CONF) if not old_mn is None: printDbg("DB: Editing masternode %s" % old_mn) try: cursor = self.getCursor() cursor.execute( "UPDATE MASTERNODES " "SET name = ?, ip = ?, port = ?, mnPrivKey = ?, hwAcc = ?, isTestnet = ?, isHardware = ?," " address = ?, spath = ?, pubkey = ?, txid = ?, txidn = ?" "WHERE name = ?", (mn['name'], mn['ip'], mn['port'], mn['mnPrivKey'], mn['hwAcc'], mn['isTestnet'], 1 if mn['isHardware'] else 0, mn['collateral'].get('address'), mn['collateral'].get('spath'), mn['collateral'].get('pubKey'), mn['collateral'].get('txid'), mn['collateral'].get('txidn'), old_mn['name'])) except Exception as e: err_msg = 'error writing masternode to DB' printException(getCallerName(), getFunctionName(), err_msg, e.args) finally: self.releaseCursor() else: # Add new record to the table self.addNewMasternode(mn)
def onSave(self): if self.ui.signatureTextEdt.document().isEmpty(): mess = "Nothing to save. Sign message first." myPopUp_sb(self.main_wnd, QMessageBox.Warning, 'PET4L - no signature', mess) return options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog fileName, _ = QFileDialog.getSaveFileName( self.main_wnd, "Save signature to file", "sig.txt", "All Files (*);; Text Files (*.txt)", options=options) try: if fileName: save_file = open(fileName, 'w') save_file.write(self.ui.signatureTextEdt.toPlainText()) save_file.close() myPopUp_sb(self.main_wnd, QMessageBox.Information, 'PET4L - saved', "Signature saved to file") return except Exception as e: err_msg = "error writing signature to file" printException(getCallerName(), getFunctionName(), err_msg, e.args) myPopUp_sb(self.main_wnd, QMessageBox.Warning, 'PET4L - NOT saved', "Signature NOT saved to file")
def getProposals(self): proposals = [] try: self.lock.acquire() data = self.conn.getbudgetinfo() except Exception as e: err_msg = "error getting proposals" printException(getCallerName(), getFunctionName(), err_msg, e.args) data = [] finally: self.lock.release() for p in data: new_proposal = Proposal(p.get('Name'), p.get('URL'), p.get('Hash'), p.get('FeeHash'), p.get('BlockStart'), p.get('BlockEnd'), p.get('TotalPaymentCount'), p.get('RemainingPaymentCount'), p.get('PaymentAddress'), p.get('Yeas'), p.get('Nays'), p.get('Abstains'), float(p.get('TotalPayment')), float(p.get('MonthlyPayment'))) proposals.append(new_proposal) return proposals
def getProposalsProjection(self): proposals = [] try: self.lock.acquire() data = self.conn.getbudgetprojection() except Exception as e: err_msg = "error getting proposals projection" printException(getCallerName(), getFunctionName(), err_msg, e.args) data = [] finally: self.lock.release() for p in data: new_proposal = Proposal(p.get('Name'), p.get('URL'), p.get('Hash'), p.get('FeeHash'), p.get('BlockStart'), p.get('BlockEnd'), p.get('TotalPaymentCount'), p.get('RemainingPaymentCount'), p.get('PaymentAddress'), p.get('Yeas'), p.get('Nays'), p.get('Abstains'), p.get('TotalPayment'), p.get('MonthlyPayment')) new_proposal = {} new_proposal['Name'] = p.get('Name') new_proposal['Allotted'] = float(p.get("Alloted")) new_proposal['Votes'] = p.get('Yeas') - p.get('Nays') new_proposal['Total_Allotted'] = float(p.get('TotalBudgetAlloted')) proposals.append(new_proposal) return proposals
def onToggleCollateral(self): if self.ui.rewardsList.box.collateralRow is not None: if not self.ui.collateralHidden: try: # If collateral row was selected, deselect it before hiding if self.ui.rewardsList.box.item(self.ui.rewardsList.box.collateralRow, 0).isSelected(): self.ui.rewardsList.box.selectRow(self.ui.rewardsList.box.collateralRow) except Exception as e: err_msg = "Error toggling collateral" printException(getCallerName(), getFunctionName(), err_msg, e.args) self.ui.rewardsList.box.hideRow(self.ui.rewardsList.box.collateralRow) self.ui.btn_toggleCollateral.setText("Show Collateral") self.ui.collateralHidden = True self.updateSelection() else: self.ui.rewardsList.box.showRow(self.ui.rewardsList.box.collateralRow) self.ui.btn_toggleCollateral.setText("Hide Collateral") self.ui.collateralHidden = False self.updateSelection() self.ui.rewardsList.box.resizeColumnsToContents() self.ui.rewardsList.box.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch) else: myPopUp_sb(self.caller, "warn", 'No Collateral', "No collateral selected")
def onRemoveMN(self, data=None): if not data: target = self.ui.sender() masternode_alias = target.alias reply = self.caller.myPopUp( QMessageBox.Warning, '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: self.caller.masternode_list.remove(masternode) break try: writeToFile(self.caller.masternode_list, masternodes_File) self.ui.myList.takeItem( self.ui.myList.row(self.ui.current_mn[masternode_alias])) except Exception as e: err_msg = "Error writing masternode file" printException(getCallerName(), getFunctionName(), err_msg, e) # Clear voting masternodes configuration and update cache self.caller.t_governance.clear()
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 onSweepAllRewards(self): try: self.sweepAllDlg.exec_() except Exception as e: err_msg = "exception in SweepAll_dlg" printException(getCallerName(), getFunctionName(), err_msg, e)
def releaseCursor(self, rollingBack=False, vacuum=False): if self.isOpen: try: if self.conn is not None: # commit if rollingBack: self.conn.rollback() else: self.conn.commit() if vacuum: self.conn.execute('vacuum') # close connection self.conn.close() self.conn = None except Exception as e: err_msg = 'SQLite error releasing cursor' printException(getCallerName(), getFunctionName(), err_msg, e.args) finally: self.lock.release() else: raise Exception("Database closed")
def getBlockCount(self): try: self.parameters['q'] = 'getblockcount' return self.checkResponse(self.parameters) except Exception as e: err_msg = "error in getBlockCount" printException(getCallerName(), getFunctionName(), err_msg, e.args)