def _parse_as_multiline(self, lines, *, raise_errors: bool):
        outputs = []  # type: List[PartialTxOutput]
        total = 0
        is_max = False
        for i, line in enumerate(lines):
            try:
                output = self.parse_address_and_amount(line)
            except Exception as e:
                if raise_errors:
                    raise
                else:
                    self.errors.append(
                        PayToLineError(idx=i,
                                       line_content=line.strip(),
                                       exc=e,
                                       is_multiline=True))
                    continue
            outputs.append(output)
            if parse_max_spend(output.value):
                is_max = True
            else:
                total += output.value
        if outputs:
            self.win.set_onchain(True)

        self.win.max_button.setChecked(is_max)
        self.outputs = outputs
        self.payto_scriptpubkey = None

        if self.win.max_button.isChecked():
            self.win.spend_max()
        else:
            self.amount_edit.setAmount(total if outputs else None)
        self.win.lock_amount(self.win.max_button.isChecked() or bool(outputs))
Beispiel #2
0
    def pay_onchain_dialog(self,
                           inputs: Sequence[PartialTxInput],
                           outputs: List[PartialTxOutput],
                           *,
                           external_keypairs=None) -> None:
        # trustedcoin requires this
        if run_hook('abort_send', self):
            return
        is_sweep = bool(external_keypairs)
        make_tx = lambda fee_est: self.wallet.make_unsigned_transaction(
            coins=inputs, outputs=outputs, fee=fee_est, is_sweep=is_sweep)
        output_values = [x.value for x in outputs]
        if any(parse_max_spend(outval) for outval in output_values):
            output_value = '!'
        else:
            output_value = sum(output_values)
        conf_dlg = ConfirmTxDialog(window=self.window,
                                   make_tx=make_tx,
                                   output_value=output_value,
                                   is_sweep=is_sweep)
        if conf_dlg.not_enough_funds:
            # Check if we had enough funds excluding fees,
            # if so, still provide opportunity to set lower fees.
            if not conf_dlg.have_enough_funds_assuming_zero_fees():
                text = self.get_text_not_enough_funds_mentioning_frozen()
                self.show_message(text)
                return

        # shortcut to advanced preview (after "enough funds" check!)
        if self.config.get('advanced_preview'):
            preview_dlg = PreviewTxDialog(window=self.window,
                                          make_tx=make_tx,
                                          external_keypairs=external_keypairs,
                                          output_value=output_value)
            preview_dlg.show()
            return

        cancelled, is_send, password, tx = conf_dlg.run()
        if cancelled:
            return
        if is_send:
            self.save_pending_invoice()

            def sign_done(success):
                if success:
                    self.window.broadcast_or_show(tx)

            self.window.sign_tx_with_password(
                tx,
                callback=sign_done,
                password=password,
                external_keypairs=external_keypairs,
            )
        else:
            preview_dlg = PreviewTxDialog(window=self.window,
                                          make_tx=make_tx,
                                          external_keypairs=external_keypairs,
                                          output_value=output_value)
            preview_dlg.show()
Beispiel #3
0
 def _do_pay_onchain(self, invoice: OnchainInvoice) -> None:
     outputs = invoice.outputs
     amount = sum(map(lambda x: x.value, outputs)) if not any(parse_max_spend(x.value) for x in outputs) else '!'
     coins = self.app.wallet.get_spendable_coins(None)
     make_tx = lambda rbf: self.app.wallet.make_unsigned_transaction(coins=coins, outputs=outputs, rbf=rbf)
     on_pay = lambda tx: self.app.protected(_('Send payment?'), self.send_tx, (tx, invoice))
     d = ConfirmTxDialog(self.app, amount=amount, make_tx=make_tx, on_pay=on_pay)
     d.open()
 def parse_amount(self, x):
     x = x.strip()
     if not x:
         raise Exception("Amount is empty")
     if parse_max_spend(x):
         return x
     p = pow(10, self.amount_edit.decimal_point())
     try:
         return int(p * Decimal(x))
     except decimal.InvalidOperation:
         raise Exception("Invalid amount")
Beispiel #5
0
    def send_onchain(self, address, amount, fee=None, rbf=False):
        self._logger.info('send_onchain: %s %d' % (address, amount))
        coins = self.wallet.get_spendable_coins(None)
        if not bitcoin.is_address(address):
            self._logger.warning('Invalid Bitcoin Address: ' + address)
            return False

        outputs = [PartialTxOutput.from_address_and_value(address, amount)]
        self._logger.info(str(outputs))
        output_values = [x.value for x in outputs]
        if any(parse_max_spend(outval) for outval in output_values):
            output_value = '!'
        else:
            output_value = sum(output_values)
        self._logger.info(str(output_value))
        # see qt/confirm_tx_dialog qt/main_window
        tx = self.wallet.make_unsigned_transaction(coins=coins,
                                                   outputs=outputs,
                                                   fee=None)
        self._logger.info(str(tx.to_json()))

        use_rbf = bool(self.wallet.config.get('use_rbf', True))
        tx.set_rbf(use_rbf)
        self.sign_and_broadcast(tx)