Esempio n. 1
0
    def loadMNConf(self, fileName):
        hot_masternodes = loadMNConfFile(fileName)
        if hot_masternodes is None:
            messText = "Unable to load data from file '%s'" % fileName
            myPopUp_sb(self, "warn", "SPMT - Load MN Conf", messText)
        else:
            new_masternodes = []
            skip_masternodes = []
            for x in hot_masternodes:
                # If masternode name is not in list
                if not self.isMasternodeInList(x['name']):
                    # Add to cache, QListWidget and database
                    appendMasternode(self, x)
                    new_masternodes.append(x)
                # Otherwise skip it
                else:
                    skip_masternodes.append(x)

            # Print number of nodes added
            new_nodes = len(new_masternodes)
            final_message = ""
            if new_nodes == 0:
                final_message = "No External Masternode "
            elif new_nodes == 1:
                final_message = "1 External Masternode "
            else:
                final_message = "%d External Masternodes " % new_nodes
            final_message += "added to the list."
            if new_nodes > 0:
                final_message += "<br>" + str(
                    [x['name'] for x in new_masternodes]) + ".  "
            printOK(final_message)
            if len(skip_masternodes) > 0:
                final_message = "Following entries skipped due to duplicate names:<br>"
                final_message += str([x['name']
                                      for x in skip_masternodes]) + ".  "
                printOK(final_message)
Esempio n. 2
0
    def onSaveMNConf(self):
        try:
            if self.ui.edt_pubKey.text() == "" or self.ui.edt_txid.text() == "" or self.ui.edt_mnPrivKey.text() == "":
                mess_text = 'Attention! Complete the form before saving.<br>'
                mess_text += "<b>pubKey = </b>%s<br>" % self.ui.edt_pubKey.text()
                mess_text += "<b>txId = </b>%s<br>" % self.ui.edt_txid.text()
                mess_text += "<b>mnPrivKey = </b>%s<br>" % self.ui.edt_mnPrivKey.text()
                myPopUp_sb(self.caller, "crit", 'Complete Form', mess_text)
                return

            if not is_hex(self.ui.edt_txid.text()):
                mess_text = 'Attention! txid format is not valid.<br>'
                mess_text += "<b>txId = </b>%s<br>" % self.ui.edt_txid.text()
                mess_text += 'transaction id must be in hex format.<br>'
                myPopUp_sb(self.caller, "crit", 'Complete Form', mess_text)
                return

            # check for duplicate names
            mn_alias = self.ui.edt_name.text().strip()
            # if we are changing a masternode check for duplicate only if name is changed
            old_alias = None
            if not self.caller.mnode_to_change is None:
                old_alias = self.caller.mnode_to_change['name']
            if self.caller.isMasternodeInList(mn_alias) and old_alias != mn_alias:
                mess_text = 'Attention! The name <b>%s</b> is already in use for another masternode.<br>' % mn_alias
                mess_text += 'Choose a different name (alias) for the masternode'
                myPopUp_sb(self.caller, "crit", 'Complete Form', mess_text)
                return

            # create new item
            new_masternode = {}
            new_masternode['name'] = mn_alias
            masternodeIp = self.ui.edt_masternodeIp.text().strip()
            if not masternodeIp.endswith('.onion'):
                masternodeIp = ip_address(masternodeIp).compressed
            new_masternode['ip'] = masternodeIp
            new_masternode['port'] = self.ui.edt_masternodePort.value()
            new_masternode['mnPrivKey'] = self.ui.edt_mnPrivKey.text().strip()
            new_masternode['isTestnet'] = 0 if not self.isTestnet() else 1
            new_masternode['isHardware'] = True
            new_masternode['hwAcc'] = self.ui.edt_hwAccount.value()

            coll = {}
            coll['address'] = self.ui.edt_address.text().strip()
            coll['spath'] = self.ui.edt_spath.value()
            coll['pubKey'] = self.ui.edt_pubKey.text().strip()
            coll['txid'] = self.ui.edt_txid.text().strip()
            coll['txidn'] = self.ui.edt_txidn.value()

            new_masternode['collateral'] = coll

            # Add to cache, QListWidget and database (and remove/edit mnode_to_change)
            appendMasternode(self.caller, new_masternode)

            # go back
            self.onCancelMNConfig()

        except Exception as e:
            error_msg = "ERROR: %s" % e
            printDbg(error_msg)
            myPopUp_sb(self.caller, "crit", 'ERROR', error_msg)