Exemplo n.º 1
0
Arquivo: gtk.py Projeto: wozz/electrum
 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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
0
def make_new_contact():
    code = droid.scanBarcode()
    r = code.result
    if r:
        data = r['extras']['SCAN_RESULT']
        if data:
            if re.match('^litecoin:', 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.º 9
0
def make_new_contact():
    code = droid.scanBarcode()
    r = code.result
    if r:
        data = r['extras']['SCAN_RESULT']
        if data:
            if re.match('^litecoin:', 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.º 10
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('^litecoin:', 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.º 11
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('^litecoin:', 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.º 12
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 Litecoin 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('^litecoin:', 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.º 13
0
 def _do_test_parse_URI(self, uri, expected):
     result = parse_URI(uri)
     self.assertEqual(expected, result)
Exemplo n.º 14
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 Litecoin 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('^litecoin:', 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.º 15
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 Litecoin 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('^litecoin:', 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