예제 #1
0
    def check_text(self):
        self.errors = []
        if self.is_pr:
            return
        # filter out empty lines
        lines = [i for i in self.lines() if i]
        outputs = []  # type: List[PartialTxOutput]
        total = 0
        self.payto_scriptpubkey = None
        self.lightning_invoice = None
        if len(lines) == 1:
            data = lines[0]
            if data.startswith("{scheme}:".format(
                    scheme=constants.net.PAYMENT_URI_SCHEME)):
                self.win.pay_to_URI(data)
                return
            bolt11_invoice = maybe_extract_bolt11_invoice(data)
            if bolt11_invoice is not None:
                try:
                    self.win.parse_lightning_invoice(bolt11_invoice)
                except LnDecodeException as e:
                    self.errors.append(
                        PayToLineError(idx=0, line_content=data, exc=e))
                else:
                    self.lightning_invoice = bolt11_invoice
                return
            try:
                self.payto_scriptpubkey = self.parse_output(data)
            except:
                pass
            if self.payto_scriptpubkey:
                self.win.set_onchain(True)
                self.win.lock_amount(False)
                return

        is_max = False
        for i, line in enumerate(lines):
            try:
                output = self.parse_address_and_amount(line)
            except Exception as e:
                self.errors.append(
                    PayToLineError(idx=i, line_content=line.strip(), exc=e))
                continue
            outputs.append(output)
            if 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))
예제 #2
0
 def set_URI(self, text: str):
     if not self.app.wallet:
         return
     # interpret as lighting URI
     bolt11_invoice = maybe_extract_bolt11_invoice(text)
     if bolt11_invoice:
         self.set_ln_invoice(bolt11_invoice)
     # interpret as BIP21 URI
     else:
         self.set_bip21(text)
예제 #3
0
    def check_text(self):
        self.errors = []
        if self.is_pr:
            return
        # filter out empty lines
        lines = [i for i in self.lines() if i]

        self._check_minus_sign(lines)
        self.payto_scriptpubkey = None
        self.lightning_invoice = None
        self.outputs = []

        if len(lines) == 1:
            data = lines[0]
            # try bip21 URI
            if data.lower().startswith(BITCOIN_BIP21_URI_SCHEME + ':'):
                self.win.pay_to_URI(data)
                return
            # try LN invoice
            bolt11_invoice = maybe_extract_bolt11_invoice(data)
            if bolt11_invoice is not None:
                try:
                    self.win.parse_lightning_invoice(bolt11_invoice)
                except LnDecodeException as e:
                    self.errors.append(PayToLineError(line_content=data,
                                                      exc=e))
                else:
                    self.lightning_invoice = bolt11_invoice
                return
            # try "address, amount" on-chain format
            try:
                self._parse_as_multiline(lines, raise_errors=True)
            except Exception as e:
                pass
            else:
                return
            # try address/script
            try:
                self.payto_scriptpubkey = self.parse_output(data)
            except Exception as e:
                self.errors.append(PayToLineError(line_content=data, exc=e))
            else:
                self.win.set_onchain(True)
                self.win.lock_amount(False)
                return
        else:
            # there are multiple lines
            self._parse_as_multiline(lines, raise_errors=False)
예제 #4
0
 def do_paste(self):
     data = self.app._clipboard.paste().strip()
     if not data:
         self.app.show_info(_("Clipboard is empty"))
         return
     # try to decode as transaction
     try:
         tx = tx_from_any(data)
         tx.deserialize()
     except:
         tx = None
     if tx:
         self.app.tx_dialog(tx)
         return
     # try to decode as URI/address
     bolt11_invoice = maybe_extract_bolt11_invoice(data)
     if bolt11_invoice is not None:
         self.set_ln_invoice(bolt11_invoice)
     else:
         self.set_URI(data)
예제 #5
0
 def on_qr(self, data):
     from electrum.bitcoin import is_address
     data = data.strip()
     if is_address(data):
         self.set_URI(data)
         return
     if data.startswith('bitcoin:'):
         self.set_URI(data)
         return
     bolt11_invoice = maybe_extract_bolt11_invoice(data)
     if bolt11_invoice is not None:
         self.set_ln_invoice(bolt11_invoice)
         return
     # try to decode transaction
     from electrum.transaction import tx_from_any
     try:
         tx = tx_from_any(data)
     except:
         tx = None
     if tx:
         self.tx_dialog(tx)
         return
     # show error
     self.show_error("Unable to decode QR data")