Exemplo n.º 1
0
 def set_URI(self, text):
     from electrum.bitcoin import is_p2pkh
     if not self.app.wallet:
         self.payment_request_queued = text
         return
     if text.startswith('vipstarcoin:'):
         try:
             bitcoin_uri = parse_URI(text)
         except InvalidBitcoinURI as e:
             self.app.show_error(_("Error parsing URI") + f":\n{e}")
             return
         address = bitcoin_uri.get('address', '')
         text = "vipstoken:{}?to_addr={}".format(self.contract_addr,
                                                 address)
     try:
         uri = parse_token_URI(text)
     except InvalidTokenURI as e:
         self.app.show_error(_("Error parsing URI") + f":\n{e}")
         return
     address = uri.get('contract_addr', '')
     to_addr = uri.get('to_addr', '')
     amount = uri.get('amount', '')
     if not self.match_token(address):
         self.app.show_error(_("Token doesn't mutch"))
         return
     self.amount = self.app.format_token_amount_and_units(
         amount, self.decimals, self.symbol) if amount else ''
     if not is_p2pkh(to_addr):
         self.app.show_error(_("Recipient address is miss"))
     else:
         self.to_addr = to_addr
Exemplo n.º 2
0
 def set_url(self, url):
     payto, amount, label, message, payment_request = parse_URI(url)
     self.notebook.set_current_page(1)
     self.payto_entry.set_text(payto)
     self.message_entry.set_text(message)
     self.amount_entry.set_text(amount)
     self.payto_sig.set_visible(False)
Exemplo n.º 3
0
 def set_bip21(self, text: str, *, can_use_network: bool = True):
     on_bip70_pr = self.on_pr if can_use_network else None
     try:
         out = util.parse_URI(text, on_bip70_pr)
     except InvalidBitcoinURI as e:
         self.show_error(_("Error parsing URI") + f":\n{e}")
         return
     self.payto_URI = out
     r = out.get('r')
     sig = out.get('sig')
     name = out.get('name')
     if (r or (name and sig)) and can_use_network:
         self.prepare_for_send_tab_network_lookup()
         return
     address = out.get('address')
     amount = out.get('amount')
     label = out.get('label')
     message = out.get('message')
     lightning = out.get('lightning')
     if lightning:
         self.handle_payment_identifier(lightning,
                                        can_use_network=can_use_network)
         return
     # use label as description (not BIP21 compliant)
     if label and not message:
         message = label
     if address:
         self.payto_e.setText(address)
     if message:
         self.message_e.setText(message)
     if amount:
         self.amount_e.setAmount(amount)
Exemplo n.º 4
0
 def do_paste(self):
     contents = unicode(self.app._clipboard.get())
     try:
         uri = parse_URI(contents)
     except:
         self.app.show_info("Invalid URI", contents)
         return
     self.set_URI(uri)
Exemplo n.º 5
0
 def pay_from_URI(self, URI):
     try:
         dest_address, amount, label, message, request_url = util.parse_URI(URI)
     except:
         return
     self.address_input.setText(dest_address)
     self.address_field_changed(dest_address)
     self.amount_input.setText(str(amount))
Exemplo n.º 6
0
 def do_paste(self):
     contents = unicode(self.app._clipboard.paste())
     try:
         uri = parse_URI(contents)
     except:
         self.app.show_info("Invalid URI", contents)
         return
     self.set_URI(uri)
Exemplo n.º 7
0
 def pay_from_URI(self, URI):
     try:
         dest_address, amount, label, message, request_url = util.parse_URI(URI)
     except:
         return
     self.address_input.setText(dest_address)
     self.address_field_changed(dest_address)
     self.amount_input.setText(str(amount))
Exemplo n.º 8
0
 def pay_from_URI(self, URI):
     try:
         dest_address, amount, label, message, request_url = util.parse_URI(URI)
     except:
         return
     amount_text = str(D(amount) / (10**self.actuator.g.decimal_point))
     self.address_input.setText(dest_address)
     self.address_field_changed(dest_address)
     self.amount_input.setText(amount_text)
Exemplo n.º 9
0
 def set_url(self, url):
     out = parse_URI(url)
     address = out.get('address')
     message = out.get('message')
     amount = out.get('amount')
     self.notebook.set_current_page(1)
     self.payto_entry.set_text(address)
     self.message_entry.set_text(message)
     self.amount_entry.set_text(amount)
     self.payto_sig.set_visible(False)
Exemplo n.º 10
0
 def show_address():
     addr = str(receive_address_e.text())
     # note: 'addr' could be ln invoice or BIP21 URI
     try:
         uri = parse_URI(addr)
     except InvalidBitcoinURI:
         pass
     else:
         addr = uri.get('address')
     keystore.thread.add(partial(plugin.show_address, wallet, addr, keystore))
Exemplo n.º 11
0
 def set_url(self, url):
     out = parse_URI(url)
     address = out.get('address')
     message = out.get('message')
     amount = out.get('amount')
     self.notebook.set_current_page(1)
     self.payto_entry.set_text(address)
     self.message_entry.set_text(message)
     self.amount_entry.set_text(amount)
     self.payto_sig.set_visible(False)
Exemplo n.º 12
0
 def pay_to_URI(self, URI):
     try:
         out = util.parse_URI(URI)
     except:
         return
     address = out.get('address')
     amount = out.get('amount')
     amount_text = str(D(amount) / (10**self.actuator.g.decimal_point))
     self.address_input.setText(address)
     self.address_field_changed(address)
     self.amount_input.setText(amount_text)
Exemplo n.º 13
0
 def pay_from_URI(self, URI):
     try:
         out = util.parse_URI(URI)
     except:
         return
     address = out.get('address')
     amount = out.get('amount')
     amount_text = str(D(amount) / (10**self.actuator.g.decimal_point))
     self.address_input.setText(address)
     self.address_field_changed(address)
     self.amount_input.setText(amount_text)
Exemplo n.º 14
0
 def set_bip21(self, text: str):
     try:
         uri = parse_URI(text, self.app.on_pr, loop=self.app.asyncio_loop)
     except InvalidBitcoinURI as e:
         self.app.show_info(_("Error parsing URI") + f":\n{e}")
         return
     self.parsed_URI = uri
     amount = uri.get('amount')
     self.address = uri.get('address', '')
     self.message = uri.get('message', '')
     self.amount = self.app.format_amount_and_units(amount) if amount else ''
     self.is_max = False
     self.payment_request = None
     self.is_lightning = False
Exemplo n.º 15
0
 def set_URI(self, text):
     if not self.app.wallet:
         self.payment_request_queued = text
         return
     try:
         uri = parse_URI(text, self.app.on_pr, loop=self.app.asyncio_loop)
     except InvalidBitcoinURI as e:
         self.app.show_info(_("Error parsing URI") + f":\n{e}")
         return
     amount = uri.get('amount')
     self.screen.address = uri.get('address', '')
     self.screen.message = uri.get('message', '')
     self.screen.amount = self.app.format_amount_and_units(amount) if amount else ''
     self.payment_request = None
     self.screen.is_pr = False
Exemplo n.º 16
0
def make_new_contact():
    code = droid.scanBarcode()
    r = code.result
    if r:
        data = r['extras']['SCAN_RESULT']
        if data:
            if re.match('^bitcoin:', data):
                address, _, _, _, _ = util.parse_URI(data)
            elif is_valid(data):
                address = data
            else:
                address = None
            if address:
                if modal_question('Add to contacts?', address):
                    wallet.add_contact(address)
        else:
            modal_dialog('Invalid address', data)
Exemplo n.º 17
0
def make_new_contact():
    code = droid.scanBarcode()
    r = code.result
    if r:
        data = str(r['extras']['SCAN_RESULT']).strip()
        if data:
            if re.match('^bitcoin:', data):
                address, _, _, _, _ = util.parse_URI(data)
            elif is_address(data):
                address = data
            else:
                address = None
            if address:
                if modal_question('Add to contacts?', address):
                    wallet.add_contact(address)
        else:
            modal_dialog('Invalid address', data)
Exemplo n.º 18
0
def make_new_contact():
    code = droid.scanBarcode()
    r = code.result
    if r:
        data = str(r['extras']['SCAN_RESULT']).strip()
        if data:
            if re.match('^bitcoin:', data):
                address, _, _, _, _ = util.parse_URI(data)
            elif is_address(data):
                address = data
            else:
                address = None
            if address:
                if modal_question('Add to contacts?', address):
                    # fixme: ask for key
                    contacts[address] = ('address', address)
        else:
            modal_dialog('Invalid address', data)
Exemplo n.º 19
0
def make_new_contact():
    code = droid.scanBarcode()
    r = code.result
    if r:
        data = str(r['extras']['SCAN_RESULT']).strip()
        if data:
            if re.match('^monetaryunit:', data):
                out = util.parse_URI(data)
                address = out.get('address')
            elif is_address(data):
                address = data
            else:
                address = None
            if address:
                if modal_question('Add to contacts?', address):
                    # fixme: ask for key
                    contacts[address] = ('address', address)
        else:
            modal_dialog('Invalid address', data)
Exemplo n.º 20
0
def make_new_contact():
    code = droid.scanBarcode()
    r = code.result
    if r:
        data = str(r["extras"]["SCAN_RESULT"]).strip()
        if data:
            if re.match("^bitcoin:", data):
                out = util.parse_URI(data)
                address = out.get("address")
            elif is_address(data):
                address = data
            else:
                address = None
            if address:
                if modal_question("Add to contacts?", address):
                    # fixme: ask for key
                    contacts[address] = ("address", address)
        else:
            modal_dialog("Invalid address", data)
Exemplo n.º 21
0
 def _do_test_parse_URI(self, uri, expected):
     result = parse_URI(uri)
     self.assertEqual(expected, result)
Exemplo n.º 22
0
def payto_loop():
    global recipient
    if recipient:
        droid.fullSetProperty("recipient","text",recipient)
        recipient = None

    out = None
    while out is None:
        event = droid.eventWait().result
        if not event: continue
        print "got event in payto loop", event
        if event == 'OK': continue
        if not event.get("name"): continue

        if event["name"] == "click":
            id = event["data"]["id"]

            if id=="buttonPay":

                droid.fullQuery()
                recipient = droid.fullQueryDetail("recipient").result.get('text')
                message = droid.fullQueryDetail("message").result.get('text')
                amount = droid.fullQueryDetail('amount').result.get('text')

                if not is_address(recipient):
                    modal_dialog('Error','Invalid MonetaryUnit address')
                    continue

                try:
                    amount = int(COIN * Decimal(amount))
                except Exception:
                    modal_dialog('Error','Invalid amount')
                    continue

                result = pay_to(recipient, amount, message)
                if result:
                    out = 'main'

            elif id=="buttonContacts":
                addr = select_from_contacts()
                droid.fullSetProperty("recipient", "text", addr)

            elif id=="buttonQR":
                code = droid.scanBarcode()
                r = code.result
                if r:
                    data = str(r['extras']['SCAN_RESULT']).strip()
                    if data:
                        print "data", data
                        if re.match('^monetaryunit:', data):
                            payto, amount, label, message, _ = util.parse_URI(data)
                            if amount:
                                amount = str(amount / COIN)
                            droid.fullSetProperty("recipient", "text", payto)
                            droid.fullSetProperty("amount", "text", amount)
                            droid.fullSetProperty("message", "text", message)
                        elif is_address(data):
                            droid.fullSetProperty("recipient", "text", data)
                        else:
                            modal_dialog('Error','cannot parse QR code\n'+data)


        elif event["name"] in menu_commands:
            out = event["name"]

        elif event["name"]=="key":
            if event["data"]["key"] == '4':
                out = 'main'

        #elif event["name"]=="screen":
        #    if event["data"]=="destroy":
        #        out = 'main'

    return out
Exemplo n.º 23
0
 def _do_test_parse_URI(self, uri, expected):
     result = parse_URI(uri)
     self.assertEqual(expected, result)
Exemplo n.º 24
0
 def parse_uri(self, uri: str) -> dict:
     try:
         return parse_URI(uri)
     except InvalidBitcoinURI as e:
         return {'error': str(e)}
Exemplo n.º 25
0
def payto_loop():
    global recipient
    if recipient:
        droid.fullSetProperty("recipient","text",recipient)
        recipient = None

    out = None
    while out is None:
        event = droid.eventWait().result
        if not event: continue
        print "got event in payto loop", event
        if event == 'OK': continue
        if not event.get("name"): continue

        if event["name"] == "click":
            id = event["data"]["id"]

            if id=="buttonPay":

                droid.fullQuery()
                recipient = droid.fullQueryDetail("recipient").result.get('text')
                label  = droid.fullQueryDetail("label").result.get('text')
                amount = droid.fullQueryDetail('amount').result.get('text')

                if not is_valid(recipient):
                    modal_dialog('Error','Invalid Darkcoin address')
                    continue

                try:
                    amount = int( 100000000 * Decimal(amount) )
                except Exception:
                    modal_dialog('Error','Invalid amount')
                    continue

                result = pay_to(recipient, amount, wallet.fee, label)
                if result:
                    out = 'main'

            elif id=="buttonContacts":
                addr = select_from_contacts()
                droid.fullSetProperty("recipient","text",addr)

            elif id=="buttonQR":
                code = droid.scanBarcode()
                r = code.result
                if r:
                    data = r['extras']['SCAN_RESULT']
                    if data:
                        if re.match('^bitcoin:', data):
                            payto, amount, label, _, _ = util.parse_URI(data)
                            droid.fullSetProperty("recipient", "text",payto)
                            droid.fullSetProperty("amount", "text", amount)
                            droid.fullSetProperty("label", "text", label)
                        else:
                            droid.fullSetProperty("recipient", "text", data)

                    
        elif event["name"] in menu_commands:
            out = event["name"]

        elif event["name"]=="key":
            if event["data"]["key"] == '4':
                out = 'main'

        #elif event["name"]=="screen":
        #    if event["data"]=="destroy":
        #        out = 'main'

    return out
Exemplo n.º 26
0
    def validateRecipient(self, recipient):
        if not recipient:
            self.setInvoiceType(QEInvoice.Type.Invalid)
            return

        maybe_lightning_invoice = recipient

        def _payment_request_resolved(request):
            self._logger.debug('resolved payment request')
            outputs = request.get_outputs()
            invoice = self.create_onchain_invoice(outputs, None, request, None)
            self.setValidOnchainInvoice(invoice)

        try:
            self._bip21 = parse_URI(recipient, _payment_request_resolved)
            if self._bip21:
                if 'r' in self._bip21 or ('name' in self._bip21 and 'sig' in self._bip21): # TODO set flag in util?
                    # let callback handle state
                    return
                if ':' not in recipient:
                    # address only
                    self.setValidAddressOnly()
                    self.validationSuccess.emit()
                    return
                else:
                    # fallback lightning invoice?
                    if 'lightning' in self._bip21:
                        maybe_lightning_invoice = self._bip21['lightning']
        except InvalidBitcoinURI as e:
            self._bip21 = None
            self._logger.debug(repr(e))

        lninvoice = None
        maybe_lightning_invoice = maybe_extract_lightning_payment_identifier(maybe_lightning_invoice)
        if maybe_lightning_invoice is not None:
            try:
                lninvoice = Invoice.from_bech32(maybe_lightning_invoice)
            except InvoiceError as e:
                e2 = e.__cause__
                if isinstance(e2, LnInvoiceException):
                    self.validationError.emit('unknown', _("Error parsing Lightning invoice") + f":\n{e2}")
                    self.clear()
                    return
                if isinstance(e2, lnutil.IncompatibleOrInsaneFeatures):
                    self.validationError.emit('unknown', _("Invoice requires unknown or incompatible Lightning feature") + f":\n{e2!r}")
                    self.clear()
                    return
                self._logger.exception(repr(e))

        if not lninvoice and not self._bip21:
            self.validationError.emit('unknown',_('Unknown invoice'))
            self.clear()
            return

        if lninvoice:
            if not self._wallet.wallet.has_lightning():
                if not self._bip21:
                    # TODO: lightning onchain fallback in ln invoice
                    #self.validationError.emit('no_lightning',_('Detected valid Lightning invoice, but Lightning not enabled for wallet'))
                    self.setValidLightningInvoice(lninvoice)
                    self.clear()
                    return
                else:
                    self._logger.debug('flow with LN but not LN enabled AND having bip21 uri')
                    self.setValidOnchainInvoice(self._bip21['address'])
            else:
                self.setValidLightningInvoice(lninvoice)
                if not self._wallet.wallet.lnworker.channels:
                    self.validationWarning.emit('no_channels',_('Detected valid Lightning invoice, but there are no open channels'))
                else:
                    self.validationSuccess.emit()
        else:
            self._logger.debug('flow without LN but having bip21 uri')
            if 'amount' not in self._bip21: #TODO can we have amount-less invoices?
                self.validationError.emit('no_amount', 'no amount in uri')
                return
            outputs = [PartialTxOutput.from_address_and_value(self._bip21['address'], self._bip21['amount'])]
            self._logger.debug(outputs)
            message = self._bip21['message'] if 'message' in self._bip21 else ''
            invoice = self.create_onchain_invoice(outputs, message, None, self._bip21)
            self._logger.debug(repr(invoice))
            self.setValidOnchainInvoice(invoice)
            self.validationSuccess.emit()
Exemplo n.º 27
0
def payto_loop():
    global recipient
    if recipient:
        droid.fullSetProperty("recipient", "text", recipient)
        recipient = None

    out = None
    while out is None:
        event = droid.eventWait().result
        if not event: continue
        print "got event in payto loop", event
        if event == 'OK': continue
        if not event.get("name"): continue

        if event["name"] == "click":
            id = event["data"]["id"]

            if id == "buttonPay":

                droid.fullQuery()
                recipient = droid.fullQueryDetail("recipient").result.get(
                    'text')
                label = droid.fullQueryDetail("label").result.get('text')
                amount = droid.fullQueryDetail('amount').result.get('text')

                if not is_valid(recipient):
                    modal_dialog('Error', 'Invalid Bitcoin address')
                    continue

                try:
                    amount = int(100000000 * Decimal(amount))
                except Exception:
                    modal_dialog('Error', 'Invalid amount')
                    continue

                result = pay_to(recipient, amount, wallet.fee, label)
                if result:
                    out = 'main'

            elif id == "buttonContacts":
                addr = select_from_contacts()
                droid.fullSetProperty("recipient", "text", addr)

            elif id == "buttonQR":
                code = droid.scanBarcode()
                r = code.result
                if r:
                    data = r['extras']['SCAN_RESULT']
                    if data:
                        if re.match('^bitcoin:', data):
                            payto, amount, label, _, _ = util.parse_URI(data)
                            droid.fullSetProperty("recipient", "text", payto)
                            droid.fullSetProperty("amount", "text", amount)
                            droid.fullSetProperty("label", "text", label)
                        else:
                            droid.fullSetProperty("recipient", "text", data)

        elif event["name"] in menu_commands:
            out = event["name"]

        elif event["name"] == "key":
            if event["data"]["key"] == '4':
                out = 'main'

        #elif event["name"]=="screen":
        #    if event["data"]=="destroy":
        #        out = 'main'

    return out
Exemplo n.º 28
0
def payto_loop():
    global recipient
    if recipient:
        droid.fullSetProperty("recipient", "text", recipient)
        recipient = None

    out = None
    while out is None:
        event = droid.eventWait().result
        if not event: continue
        print "got event in payto loop", event
        if event == 'OK': continue
        if not event.get("name"): continue

        if event["name"] == "click":
            id = event["data"]["id"]

            if id == "buttonPay":

                droid.fullQuery()
                recipient = droid.fullQueryDetail("recipient").result.get(
                    'text')
                message = droid.fullQueryDetail("message").result.get('text')
                amount = droid.fullQueryDetail('amount').result.get('text')

                if not is_address(recipient):
                    modal_dialog('Error', 'Invalid Bitcoin address')
                    continue

                try:
                    amount = int(COIN * Decimal(amount))
                except Exception:
                    modal_dialog('Error', 'Invalid amount')
                    continue

                result = pay_to(recipient, amount, message)
                if result:
                    out = 'main'

            elif id == "buttonContacts":
                addr = select_from_contacts()
                droid.fullSetProperty("recipient", "text", addr)

            elif id == "buttonQR":
                code = droid.scanBarcode()
                r = code.result
                if r:
                    data = str(r['extras']['SCAN_RESULT']).strip()
                    if data:
                        print "data", data
                        if re.match('^bitcoin:', data):
                            rr = util.parse_URI(data)
                            amount = rr.get('amount')
                            address = rr.get('address')
                            message = rr.get('message', '')
                            if amount:
                                amount = str(Decimal(amount) / COIN)
                            droid.fullSetProperty("recipient", "text", address)
                            droid.fullSetProperty("amount", "text", amount)
                            droid.fullSetProperty("message", "text", message)
                        elif is_address(data):
                            droid.fullSetProperty("recipient", "text", data)
                        else:
                            modal_dialog('Error',
                                         'cannot parse QR code\n' + data)

        elif event["name"] in menu_commands:
            out = event["name"]

        elif event["name"] == "key":
            if event["data"]["key"] == '4':
                out = 'main'

        #elif event["name"]=="screen":
        #    if event["data"]=="destroy":
        #        out = 'main'

    return out
Exemplo n.º 29
0
def payto_loop():
    global recipient
    if recipient:
        droid.fullSetProperty("recipient", "text", recipient)
        recipient = None

    out = None
    while out is None:
        event = droid.eventWait().result
        if not event:
            continue
        print "got event in payto loop", event
        if event == "OK":
            continue
        if not event.get("name"):
            continue

        if event["name"] == "click":
            id = event["data"]["id"]

            if id == "buttonPay":

                droid.fullQuery()
                recipient = droid.fullQueryDetail("recipient").result.get("text")
                message = droid.fullQueryDetail("message").result.get("text")
                amount = droid.fullQueryDetail("amount").result.get("text")

                if not is_address(recipient):
                    modal_dialog("Error", "Invalid Bitcoin address")
                    continue

                try:
                    amount = int(COIN * Decimal(amount))
                except Exception:
                    modal_dialog("Error", "Invalid amount")
                    continue

                result = pay_to(recipient, amount, message)
                if result:
                    out = "main"

            elif id == "buttonContacts":
                addr = select_from_contacts()
                droid.fullSetProperty("recipient", "text", addr)

            elif id == "buttonQR":
                code = droid.scanBarcode()
                r = code.result
                if r:
                    data = str(r["extras"]["SCAN_RESULT"]).strip()
                    if data:
                        print "data", data
                        if re.match("^bitcoin:", data):
                            rr = util.parse_URI(data)
                            amount = rr.get("amount")
                            address = rr.get("address")
                            message = rr.get("message", "")
                            if amount:
                                amount = str(Decimal(amount) / COIN)
                            droid.fullSetProperty("recipient", "text", address)
                            droid.fullSetProperty("amount", "text", amount)
                            droid.fullSetProperty("message", "text", message)
                        elif is_address(data):
                            droid.fullSetProperty("recipient", "text", data)
                        else:
                            modal_dialog("Error", "cannot parse QR code\n" + data)

        elif event["name"] in menu_commands:
            out = event["name"]

        elif event["name"] == "key":
            if event["data"]["key"] == "4":
                out = "main"

        # elif event["name"]=="screen":
        #    if event["data"]=="destroy":
        #        out = 'main'

    return out