Exemple #1
0
 def _parse_tx_output(self, line: str) -> XTxOutput:
     x, y = line.split(',')
     script = self._parse_output(x)
     if not isinstance(script, Script):  # An Address object
         script = script.to_script()
     amount = self._parse_amount(y)
     return XTxOutput(amount, script)
Exemple #2
0
 def get_outputs(self, is_max):
     if self._payto_script is not None:
         if is_max:
             amount = all
         else:
             amount = self._send_view.amount_e.get_amount()
         self._outputs = [XTxOutput(amount, self._payto_script)]
     return self._outputs[:]
Exemple #3
0
    def get_outputs(self, is_max):
        if self.payto_address:
            if is_max:
                amount = all
            else:
                amount = self.amount_edit.get_amount()

            addr = self.payto_address
            self.outputs = [XTxOutput(amount, addr.to_script())]

        return self.outputs[:]
    def _on_direct_split(self) -> None:
        assert self._direct_splitting_enabled, "direct splitting not enabled"
        assert not self._faucet_splitting, "already faucet splitting"

        self._direct_splitting = True
        self._direct_button.setText(_("Splitting") +"...")
        self._direct_button.setEnabled(False)

        unused_key = self._account.get_fresh_keys(CHANGE_SUBPATH, 1)[0]
        script = self._account.get_script_for_id(unused_key.keyinstance_id)
        coins = self._account.get_utxos(exclude_frozen=True, mature=True)
        outputs = [ XTxOutput(all, script) ]
        outputs.extend(self._account.create_extra_outputs(coins, outputs, force=True))
        try:
            tx = self._account.make_unsigned_transaction(coins, outputs, self._main_window.config)
        except NotEnoughFunds:
            self._cleanup_tx_final()
            self._main_window.show_message(_("Insufficient funds"))
            return

        if self._account.type() == AccountType.MULTISIG:
            self._cleanup_tx_final()
            tx.context.description = f"{TX_DESC_PREFIX} (multisig)"
            self._main_window.show_transaction(self._account, tx)
            return

        amount = tx.output_value()
        fee = tx.get_fee()
        fields = [
            (_("Amount to be sent"), QLabel(app_state.format_amount_and_units(amount))),
            (_("Mining fee"), QLabel(app_state.format_amount_and_units(fee))),
        ]
        msg = "\n".join([
            "",
            _("Enter your password to proceed"),
        ])
        password = self._main_window.password_dialog(msg, fields=fields)

        def sign_done(success: bool) -> None:
            if success:
                if not tx.is_complete():
                    dialog = self._main_window.show_transaction(self._account, tx)
                    dialog.exec()
                else:
                    extra_text = _("Your split coins")
                    tx.context.description = f"{TX_DESC_PREFIX}: {extra_text}"
                    self._main_window.broadcast_transaction(self._account, tx,
                        success_text=_("Your coins have now been split."))
            self._cleanup_tx_final()
        self._main_window.sign_tx_with_password(tx, sign_done, password)
Exemple #5
0
    def _parse_tx_output(self, line: str) -> XTxOutput:
        try:
            x, y = line.split(',')
        except ValueError:
            raise InvalidPayToError(
                _("Invalid payment destination: {}").format(line))

        script = self._parse_output(x)
        try:
            amount = self._parse_amount(y)
        except InvalidOperation:
            raise InvalidPayToError(
                _("Invalid payment destination: {}").format(line))

        return XTxOutput(amount, script)
    def _ask_send_split_transaction(self) -> None:
        coins = self._account.get_utxos(exclude_frozen=True, mature=True)
        # Verify that our dust receiving address is in the available UTXOs, if it isn't, the
        # process has failed in some unexpected way.
        for coin in coins:
            if coin.script_pubkey == self.receiving_script_template.to_script():
                break
        else:
            self._main_window.show_error(_("Error accessing dust coins for correct splitting."))
            self._cleanup_tx_final()
            return

        unused_key = self._account.get_fresh_keys(RECEIVING_SUBPATH, 1)[0]
        script = self._account.get_script_for_id(unused_key.keyinstance_id)
        outputs = [ XTxOutput(all, script) ]
        tx = self._account.make_unsigned_transaction(coins, outputs, self._main_window.config)

        amount = tx.output_value()
        fee = tx.get_fee()

        msg = [
            _("Amount to be sent") + ": " + app_state.format_amount_and_units(amount),
            _("Mining fee") + ": " + app_state.format_amount_and_units(fee),
        ]

        msg.append("")
        msg.append(_("Enter your password to proceed"))
        password = self._main_window.password_dialog('\n'.join(msg))

        def sign_done(success) -> None:
            if success:
                if not tx.is_complete():
                    dialog = self._main_window.show_transaction(self._account, tx)
                    dialog.exec()
                else:
                    extra_text = _("Your split coins")
                    tx.context.description = f"{TX_DESC_PREFIX}: {extra_text}"
                    self._main_window.broadcast_transaction(self._account, tx,
                        success_text=_("Your coins have now been split."))
            self._cleanup_tx_final()
        self._main_window.sign_tx_with_password(tx, sign_done, password)
Exemple #7
0
    def do_update_fee(self) -> None:
        '''Recalculate the fee.  If the fee was manually input, retain it, but
        still build the TX to see if there are enough funds.
        '''
        amount = all if self._is_max else self.amount_e.get_amount()
        if amount is None:
            self._not_enough_funds = False
            self._on_entry_changed()
        else:
            fee = None
            outputs = self._payto_e.get_outputs(self._is_max)
            if not outputs:
                output_script = self._payto_e.get_payee_script()
                if output_script is None:
                    output_script = self._account.get_dummy_script_template(
                    ).to_script()
                outputs = [XTxOutput(amount, output_script)]

            coins = self._get_coins()
            outputs.extend(self._account.create_extra_outputs(coins, outputs))
            try:
                tx = self._account.make_unsigned_transaction(
                    self._get_coins(), outputs, self._main_window.config, fee)
                self._not_enough_funds = False
            except NotEnoughFunds:
                self._logger.debug("Not enough funds")
                self._not_enough_funds = True
                self._on_entry_changed()
                return
            except Exception:
                self._logger.exception("transaction failure")
                return

            if self._is_max:
                amount = tx.output_value()
                self.amount_e.setAmount(amount)
Exemple #8
0
 def _parse_tx_output(self, line: str) -> XTxOutput:
     x, y = line.split(',')
     script = self._parse_output(x)
     amount = self._parse_amount(y)
     return XTxOutput(amount, script)