def get_owner_key_to_display(self) -> str:
        ret = ''
        if self.masternode:
            if self.edit_mode:
                if self.masternode.dmn_owner_key_type == InputKeyType.PRIVATE:
                    ret = self.masternode.dmn_owner_private_key
                else:
                    ret = self.masternode.dmn_owner_address
            else:
                try:
                    if self.masternode.dmn_owner_key_type == InputKeyType.PRIVATE:
                        if self.act_view_as_owner_private_key.isChecked():
                            ret = self.masternode.dmn_owner_private_key
                        elif self.act_view_as_owner_public_address.isChecked():
                            if self.masternode.dmn_owner_private_key:
                                ret = dash_utils.wif_privkey_to_address(self.masternode.dmn_owner_private_key,
                                                                        self.app_config.dash_network)
                        elif self.act_view_as_owner_public_key.isChecked():
                            if self.masternode.dmn_owner_private_key:
                                ret = dash_utils.wif_privkey_to_pubkey(self.masternode.dmn_owner_private_key)
                        elif self.act_view_as_owner_public_key_hash.isChecked():
                            if self.masternode.dmn_owner_private_key:
                                pubkey = dash_utils.wif_privkey_to_pubkey(self.masternode.dmn_owner_private_key)
                                pubkey_bin = bytes.fromhex(pubkey)
                                pub_hash = bitcoin.bin_hash160(pubkey_bin)
                                ret = pub_hash.hex()
                        else:
                            ret = '???'
                    else:
                        if self.act_view_as_owner_public_address.isChecked():
                            ret = self.masternode.dmn_owner_address
                        elif self.act_view_as_owner_public_key_hash.isChecked():
                            ret = self.masternode.get_dmn_owner_pubkey_hash()
                        else:
                            ret = '???'
                except Exception as e:
                    msg = str(e)
                    if not msg:
                        msg = 'Key conversion error.'
                    WndUtils.errorMsg(msg)

        return ret
Exemplo n.º 2
0
    def send_upd_tx(self):
        # verify the owner key used in the configuration
        if self.masternode.dmn_owner_key_type == InputKeyType.PRIVATE and self.masternode.dmn_owner_private_key:
            owner_address = wif_privkey_to_address(
                self.masternode.dmn_owner_private_key,
                self.app_config.dash_network)
            if owner_address != self.dmn_owner_address:
                raise Exception(
                    'Inconsistency of the owner key between the app configuration and the data '
                    'on the Firo network.')
        else:
            raise Exception(
                'To use this feature, you need to have the owner private key in your Masternode '
                'configuration.')

        try:
            funding_address = ''
            params = [
                'update_registrar', self.dmn_protx_hash,
                self.dmn_new_operator_pubkey, self.dmn_new_voting_address,
                self.dmn_new_payout_address, funding_address
            ]

            try:
                upd_reg_support = self.dashd_intf.checkfeaturesupport(
                    'protx_update_registrar', self.app_config.app_version)
                if not upd_reg_support.get('enabled'):
                    if upd_reg_support.get('message'):
                        raise Exception(upd_reg_support.get('message'))
                    else:
                        raise Exception(
                            'The \'protx_update_registrar\' function is not supported by the RPC node '
                            'you are connected to.')
                public_proxy_node = True

                active = self.app_config.feature_update_registrar_automatic.get_value(
                )
                if not active:
                    msg = self.app_config.feature_update_registrar_automatic.get_message(
                    )
                    if not msg:
                        msg = 'The functionality of the automatic execution of the update_registrar command on the ' \
                              '"public" RPC nodes is inactive. Use the manual method or contact the program author ' \
                              'for details.'
                    raise Exception(msg)

            except JSONRPCException as e:
                public_proxy_node = False

            if not public_proxy_node:
                try:
                    # find an address to be used as the source of the transaction fees
                    min_fee = round(1024 * FEE_DUFF_PER_BYTE / 1e8, 8)
                    balances = self.dashd_intf.listaddressbalances(min_fee)
                    bal_list = []
                    for addr in balances:
                        bal_list.append({
                            'address': addr,
                            'amount': balances[addr]
                        })
                    bal_list.sort(key=lambda x: x['amount'])
                    if not bal_list:
                        raise Exception(
                            "No address can be found in the node's wallet with sufficient funds to "
                            "cover the transaction fees.")
                    params[5] = bal_list[0]['address']
                except JSONRPCException as e:
                    logging.warning(
                        "Couldn't list the node address balances. We assume you are using a "
                        "public RPC node and the funding address for the transaction fee will "
                        "be estimated during the `update_registrar` call")
            else:
                params.append(self.masternode.dmn_owner_private_key)

            upd_tx_hash = self.dashd_intf.rpc_call(True, False, 'protx',
                                                   *params)

            if upd_tx_hash:
                logging.info(
                    'update_registrar successfully executed, tx hash: ' +
                    upd_tx_hash)
                changed = False
                if self.dmn_new_voting_address != self.dmn_prev_voting_address:
                    changed = self.masternode.dmn_voting_key_type != self.dmn_voting_key_type
                    self.masternode.dmn_voting_key_type = self.dmn_voting_key_type
                    if self.dmn_voting_key_type == InputKeyType.PRIVATE:
                        changed = changed or self.masternode.dmn_voting_private_key != self.dmn_new_voting_privkey
                        self.masternode.dmn_voting_private_key = self.dmn_new_voting_privkey
                    else:
                        changed = changed or self.masternode.dmn_voting_address != self.dmn_new_voting_address
                        self.masternode.dmn_voting_address = self.dmn_new_voting_address

                if self.dmn_new_operator_pubkey != self.dmn_prev_operator_pubkey:
                    changed = changed or self.masternode.dmn_operator_key_type != self.dmn_operator_key_type
                    self.masternode.dmn_operator_key_type = self.dmn_operator_key_type
                    if self.dmn_operator_key_type == InputKeyType.PRIVATE:
                        changed = changed or self.masternode.dmn_operator_private_key != self.dmn_new_operator_privkey
                        self.masternode.dmn_operator_private_key = self.dmn_new_operator_privkey
                    else:
                        changed = changed or self.masternode.dmn_operator_public_key != self.dmn_new_operator_pubkey
                        self.masternode.dmn_operator_public_key = self.dmn_new_operator_pubkey

                if self.on_upd_success_callback:
                    self.on_upd_success_callback(self.masternode)

                self.btnSendUpdateTx.setDisabled(True)
                self.edtPayoutAddress.setReadOnly(True)
                self.edtOperatorKey.setReadOnly(True)
                self.edtVotingKey.setReadOnly(True)
                self.btnGenerateOperatorKey.setDisabled(True)
                self.btnGenerateVotingKey.setDisabled(True)
                self.btnClose.show()

                url = self.app_config.get_block_explorer_tx()
                if url:
                    url = url.replace('%TXID%', upd_tx_hash)
                    upd_tx_hash = f'<a href="{url}">{upd_tx_hash}</a>'

                msg = 'The update_registrar transaction has been successfully sent. ' \
                     f'Tx hash: {upd_tx_hash}. <br><br>' \
                     f'The new values ​​will be visible on the network after the transaction is confirmed, i.e. in ' \
                     f'about 2.5 minutes.'

                if changed:
                    msg += '<br><br>The app configuration has been updated accordingly.'

                WndUtils.infoMsg(msg)
        except Exception as e:
            if str(e).find('protx-dup') >= 0:
                WndUtils.errorMsg(
                    'The previous protx transaction has not been confirmed yet. Wait until it is '
                    'confirmed before sending a new transaction.')
            else:
                logging.error(
                    'Exception occurred while sending protx update_registrar.')
                WndUtils.errorMsg(str(e))
    def verify_data(self):
        self.dmn_collateral_tx = self.edtCollateralTx.text().strip()
        try:
            self.dmn_collateral_tx_index = int(self.edtCollateralIndex.text())
            if self.dmn_collateral_tx_index < 0:
                raise Exception('Invalid transaction index')
        except Exception:
            self.edtCollateralIndex.setFocus()
            raise Exception(
                'Invalid collateral transaction index: should be integer greater or equal 0.'
            )

        try:
            self.dmn_ip = self.edtIP.text().strip()
            if self.dmn_ip:
                ipaddress.ip_address(self.dmn_ip)
        except Exception as e:
            self.edtIP.setFocus()
            raise Exception('Invalid masternode IP address: %s.' % str(e))

        try:
            if self.dmn_ip:
                self.dmn_tcp_port = int(self.edtPort.text())
            else:
                self.dmn_tcp_port = None
        except Exception:
            self.edtPort.setFocus()
            raise Exception('Invalid TCP port: should be integer.')

        self.dmn_owner_payout_addr = self.edtPayoutAddress.text().strip()
        if not validate_address(self.dmn_owner_payout_addr,
                                self.app_config.dash_network):
            self.edtPayoutAddress.setFocus()
            raise Exception('Invalid owner payout address.')

        if self.chbWholeMNReward.isChecked():
            self.dmn_operator_reward = 0
        else:
            self.dmn_operator_reward = self.edtOperatorReward.value()
            if self.dmn_operator_reward > 100 or self.dmn_operator_reward < 0:
                self.edtOperatorReward.setFocus()
                raise Exception(
                    'Invalid operator reward value: should be a value between 0 and 100.'
                )

        self.dmn_owner_privkey = self.edtOwnerKey.text().strip()
        if not validate_wif_privkey(self.dmn_owner_privkey,
                                    self.app_config.dash_network):
            self.edtOwnerKey.setFocus()
            self.upd_owner_key_info(True)
            raise Exception('Invalid owner private key.')
        else:
            self.dmn_owner_address = wif_privkey_to_address(
                self.dmn_owner_privkey, self.app_config.dash_network)

        try:
            self.dmn_operator_privkey = self.edtOperatorKey.text().strip()
            self.dmn_operator_pubkey = bls_privkey_to_pubkey(
                self.dmn_operator_privkey)
        except Exception as e:
            self.upd_operator_key_info(True)
            self.edtOperatorKey.setFocus()
            raise Exception('Invalid operator private key: ' + str(e))

        self.dmn_voting_privkey = self.edtVotingKey.text().strip()
        if not validate_wif_privkey(self.dmn_voting_privkey,
                                    self.app_config.dash_network):
            self.upd_voting_key_info(True)
            self.edtVotingKey.setFocus()
            raise Exception('Invalid voting private key.')
        else:
            self.dmn_voting_address = wif_privkey_to_address(
                self.dmn_voting_privkey, self.app_config.dash_network)

        self.btnContinue.setEnabled(False)
        self.btnContinue.repaint()

        ret = WndUtils.run_thread_dialog(self.get_collateral_tx_address_thread,
                                         (), True)
        self.btnContinue.setEnabled(True)
        self.btnContinue.repaint()
        return ret
Exemplo n.º 4
0
    def validate_data(self):
        payout_address = self.edtPayoutAddress.text()
        if payout_address:
            if not validate_address(payout_address,
                                    self.app_config.dash_network):
                raise Exception('Invalid payout address')
            else:
                self.dmn_new_payout_address = payout_address
        else:
            self.dmn_new_payout_address = self.dmn_prev_payout_address

        key = self.edtOperatorKey.text().strip()
        if key:
            if self.dmn_operator_key_type == InputKeyType.PRIVATE:
                self.dmn_new_operator_privkey = key

                try:
                    b = bytes.fromhex(self.dmn_new_operator_privkey)
                    if len(b) != 32:
                        raise Exception('invalid length (' + str(len(b)) + ')')
                except Exception as e:
                    self.edtOperatorKey.setFocus()
                    raise Exception('Invalid operator private key: ' + str(e))

                try:
                    self.dmn_new_operator_pubkey = bls_privkey_to_pubkey(
                        self.dmn_new_operator_privkey)
                except Exception as e:
                    self.edtOperatorKey.setFocus()
                    raise Exception('Invalid operator private key: ' + str(e))
            else:
                self.dmn_new_operator_pubkey = key
                self.dmn_new_operator_privkey = ''
                try:
                    b = bytes.fromhex(self.dmn_new_operator_pubkey)
                    if len(b) != 48:
                        raise Exception('invalid length (' + str(len(b)) + ')')
                except Exception as e:
                    self.edtOperatorKey.setFocus()
                    raise Exception('Invalid operator public key: ' + str(e))
        else:
            self.dmn_new_operator_pubkey = self.dmn_prev_operator_pubkey
            self.dmn_new_operator_privkey = ''

        key = self.edtVotingKey.text().strip()
        if key:
            if self.dmn_voting_key_type == InputKeyType.PRIVATE:
                self.dmn_new_voting_privkey = key
                if not validate_wif_privkey(self.dmn_new_voting_privkey,
                                            self.app_config.dash_network):
                    self.edtVotingKey.setFocus()
                    raise Exception('Invalid voting private key.')
                else:
                    self.dmn_new_voting_address = wif_privkey_to_address(
                        self.dmn_new_voting_privkey,
                        self.app_config.dash_network)
            else:
                self.dmn_new_voting_address = key
                self.dmn_new_voting_privkey = ''
                if not validate_address(self.dmn_new_voting_address,
                                        self.app_config.dash_network):
                    self.edtVotingKey.setFocus()
                    raise Exception('Invalid voting address.')
        else:
            self.dmn_new_voting_address = self.dmn_prev_voting_address
            self.dmn_new_voting_privkey = ''